import("context"
"fmt"
"io"
talent"cloud.google.com/go/talent/apiv4beta1"
"cloud.google.com/go/talent/apiv4beta1/talentpb"
)// jobTitleAutoComplete suggests the job titles of the given// company identifier on query.funcjobTitleAutocomplete(wio.Writer,projectID,querystring)(*talentpb.CompleteQueryResponse,error){ctx:=context.Background()// Initialize a completionService client.c,err:=talent.NewCompletionClient(ctx)iferr!=nil{returnnil,fmt.Errorf("talent.NewCompletionClient:%w",err)}deferc.Close()// Construct a completeQuery request.req:=&talentpb.CompleteQueryRequest{Parent:fmt.Sprintf("projects/%s",projectID),Query:query,LanguageCodes:[]string{"en-US"},PageSize:5,// Number of completion results returned.Scope:talentpb.CompleteQueryRequest_PUBLIC,Type:talentpb.CompleteQueryRequest_JOB_TITLE,}resp,err:=c.CompleteQuery(ctx,req)iferr!=nil{returnnil,fmt.Errorf("CompleteQuery(%s):%w",query,err)}fmt.Fprintf(w,"Autocompleteresults:")for_,c:=rangeresp.GetCompletionResults(){fmt.Fprintf(w,"\t%v\n",c.Suggestion)}returnresp,nil}
importcom.google.cloud.talent.v4beta1.CompleteQueryRequest;importcom.google.cloud.talent.v4beta1.CompleteQueryResponse;importcom.google.cloud.talent.v4beta1.CompletionClient;importcom.google.cloud.talent.v4beta1.TenantName;importjava.io.IOException;publicclassJobSearchAutoCompleteJobTitle{publicstaticvoidcompleteQuery()throwsIOException{// TODO(developer): Replace these variables before running the sample.StringprojectId="your-project-id";StringtenantId="your-tenant-id";Stringquery="your-query-for-job-title";completeQuery(projectId,tenantId,query);}// Complete job title given partial text (autocomplete).publicstaticvoidcompleteQuery(StringprojectId,StringtenantId,Stringquery)throwsIOException{// Initialize client that will be used to send requests. This client only needs to be created// once, and can be reused for multiple requests. After completing all of your requests, call// the "close" method on the client to safely clean up any remaining background resources.try(CompletionClientcompletionClient=CompletionClient.create()){TenantNameparent=TenantName.of(projectId,tenantId);CompleteQueryRequestrequest=CompleteQueryRequest.newBuilder().setParent(parent.toString()).setQuery(query).setPageSize(5)// limit for number of results.addLanguageCodes("en-US")// language code.build();CompleteQueryResponseresponse=completionClient.completeQuery(request);for(CompleteQueryResponse.CompletionResultresult:response.getCompletionResultsList()){System.out.format("Suggestedtitle:%s%n",result.getSuggestion());// Suggestion type is JOB_TITLE or COMPANY_TITLESystem.out.format("Suggestiontype:%s%n",result.getType());}}}}
fromgoogle.cloudimporttalent_v4beta1defcomplete_query(project_id,tenant_id,query):
"""Completejobtitlegivenpartialtext(autocomplete)"""
client=talent_v4beta1.CompletionClient()# project_id = 'Your Google Cloud Project ID'
# tenant_id = 'Your Tenant ID (using tenancy is optional)'
# query = '[partially typed job title]'
ifisinstance(project_id,bytes):project_id=project_id.decode("utf-8")ifisinstance(tenant_id,bytes):tenant_id=tenant_id.decode("utf-8")ifisinstance(query,bytes):query=query.decode("utf-8")parent=f"projects/{project_id}/tenants/{tenant_id}"
request=talent_v4beta1.CompleteQueryRequest(parent=parent,query=query,page_size=5,# limit for number of resultslanguage_codes=["en-US"],# language code)response=client.complete_query(request=request)forresultinresponse.completion_results:print(f"Suggestedtitle:{result.suggestion}")# Suggestion type is JOB_TITLE or COMPANY_TITLEprint(f"Suggestiontype:{talent_v4beta1.CompleteQueryRequest.CompletionType(result.type_).name}"
)
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2024-10-10。"],[],[]]