import com.google.cloud.talent.v4.CompleteQueryRequest;
import com.google.cloud.talent.v4.CompleteQueryResponse;
import com.google.cloud.talent.v4.CompletionClient;
import com.google.cloud.talent.v4.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()
.setTenant(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());
}
}
}
}
from google.cloud import talent_v4beta1
import six
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, six.binary_type):
project_id = project_id.decode("utf-8")
if isinstance(tenant_id, six.binary_type):
tenant_id = tenant_id.decode("utf-8")
if isinstance(query, six.binary_type):
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}"
)