use of com.google.cloud.talent.v4.CompleteQueryRequest in project java-docs-samples by GoogleCloudPlatform.
the class JobSearchAutoCompleteJobTitle method completeQuery.
// Complete job title given partial text (autocomplete).
public static void completeQuery(String projectId, String tenantId, String query) throws IOException {
// 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(// limit for number of results
5).addLanguageCodes(// language code
"en-US").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());
}
}
}
use of com.google.cloud.talent.v4.CompleteQueryRequest in project java-talent by googleapis.
the class JobSearchAutocompleteJobTitle method sampleCompleteQuery.
/**
* Complete job title given partial text (autocomplete)
*
* @param projectId Your Google Cloud Project ID
* @param tenantId Identifier of the Tenantd
*/
public static void sampleCompleteQuery(String projectId, String tenantId, String query, int numResults, String languageCode) {
try (CompletionClient completionClient = CompletionClient.create()) {
TenantOrProjectName parent = TenantName.of(projectId, tenantId);
List<String> languageCodes = Arrays.asList(languageCode);
CompleteQueryRequest request = CompleteQueryRequest.newBuilder().setParent(parent.toString()).setQuery(query).setPageSize(numResults).addAllLanguageCodes(languageCodes).build();
CompleteQueryResponse response = completionClient.completeQuery(request);
for (CompleteQueryResponse.CompletionResult result : response.getCompletionResultsList()) {
System.out.printf("Suggested title: %s\n", result.getSuggestion());
// Suggestion type is JOB_TITLE or COMPANY_TITLE
System.out.printf("Suggestion type: %s\n", result.getType());
}
} catch (Exception exception) {
System.err.println("Failed to create the client due to: " + exception);
}
}
use of com.google.cloud.talent.v4.CompleteQueryRequest in project java-talent by googleapis.
the class ITSystemTest method completeQueryTest.
@Test
public void completeQueryTest() {
CompleteQueryRequest request = CompleteQueryRequest.newBuilder().setParent(tenantName.toString()).setQuery("Soft").setPageSize(5).addAllLanguageCodes(Arrays.asList(LANGUAGE_CODE)).build();
CompleteQueryResponse queryResponse = completionClient.completeQuery(request);
for (CompleteQueryResponse.CompletionResult result : queryResponse.getCompletionResultsList()) {
if (TITLE.equals(result.getSuggestion())) {
assertEquals(CompleteQueryRequest.CompletionType.JOB_TITLE, result.getType());
}
}
}
use of com.google.cloud.talent.v4.CompleteQueryRequest in project java-talent by googleapis.
the class JobSearchAutoCompleteJobTitle method completeQuery.
// Complete job title given partial text (autocomplete).
public static void completeQuery(String projectId, String tenantId, String query) throws IOException {
// 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(// limit for number of results
5).addLanguageCodes(// language code
"en-US").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());
}
}
}
Aggregations