Cloud Talent Solution 为招聘信息和公司名称提供自动填充建议。只有有效的招聘信息和至少有一则公开招聘信息的公司才有资格获得建议结果。添加新招聘信息或公司之后,最多需要等待 48 小时才能将信息添加到自动填充结果集中。
要使用自动填充功能,请在更新搜索栏时调用 complete
方法。
Go
如需进行 CTS 身份验证,请设置应用默认凭据。如需了解详情,请参阅为本地开发环境设置身份验证。
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.
func jobTitleAutocomplete(w io.Writer, projectID, query string) (*talentpb.CompleteQueryResponse, error) {
ctx := context.Background()
// Initialize a completionService client.
c, err := talent.NewCompletionClient(ctx)
if err != nil {
return nil, fmt.Errorf("talent.NewCompletionClient: %w", err)
}
defer c.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)
if err != nil {
return nil, fmt.Errorf("CompleteQuery(%s): %w", query, err)
}
fmt.Fprintf(w, "Auto complete results:")
for _, c := range resp.GetCompletionResults() {
fmt.Fprintf(w, "\t%v\n", c.Suggestion)
}
return resp, nil
}
Java
如需详细了解如何安装和创建 Cloud Talent Solution 客户端,请参阅 Cloud Talent Solution 客户端库。
import com.google.cloud.talent.v4beta1.CompleteQueryRequest;
import com.google.cloud.talent.v4beta1.CompleteQueryResponse;
import com.google.cloud.talent.v4beta1.CompletionClient;
import com.google.cloud.talent.v4beta1.TenantName;
import java.io.IOException;
public class JobSearchAutoCompleteJobTitle {
public static void completeQuery() throws IOException {
// TODO(developer): Replace these variables before running the sample.
String projectId = "your-project-id";
String tenantId = "your-tenant-id";
String query = "your-query-for-job-title";
completeQuery(projectId, tenantId, query);
}
// Complete job title given partial text (autocomplete).
public static void completeQuery(String projectId, String tenantId, String query)
throws IOException {
// 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 (CompletionClient completionClient = CompletionClient.create()) {
TenantName parent = TenantName.of(projectId, tenantId);
CompleteQueryRequest request =
CompleteQueryRequest.newBuilder()
.setParent(parent.toString())
.setQuery(query)
.setPageSize(5) // limit for number of results
.addLanguageCodes("en-US") // language code
.build();
CompleteQueryResponse response = completionClient.completeQuery(request);
for (CompleteQueryResponse.CompletionResult result : response.getCompletionResultsList()) {
System.out.format("Suggested title: %s%n", result.getSuggestion());
// Suggestion type is JOB_TITLE or COMPANY_TITLE
System.out.format("Suggestion type: %s%n", result.getType());
}
}
}
}
Python
如需详细了解如何安装和创建 Cloud Talent Solution 客户端,请参阅 Cloud Talent Solution 客户端库。
from google.cloud import talent_v4beta1
def complete_query(project_id, tenant_id, query):
"""Complete job title given partial text (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]'
if isinstance(project_id, bytes):
project_id = project_id.decode("utf-8")
if isinstance(tenant_id, bytes):
tenant_id = tenant_id.decode("utf-8")
if isinstance(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 results
language_codes=["en-US"], # language code
)
response = client.complete_query(request=request)
for result in response.completion_results:
print(f"Suggested title: {result.suggestion}")
# Suggestion type is JOB_TITLE or COMPANY_TITLE
print(
f"Suggestion type: {talent_v4beta1.CompleteQueryRequest.CompletionType(result.type_).name}"
)