Class DeveloperKnowledgeClient
- All Implemented Interfaces:
BackgroundResource,AutoCloseable
The API is designed to be the canonical source for machine-readable access to Google's developer documentation.
A typical use case is to first use [DeveloperKnowledge.SearchDocumentChunks][google.developers.knowledge.v1.DeveloperKnowledge.SearchDocumentChunks] to find relevant page URIs based on a query, and then use [DeveloperKnowledge.GetDocument][google.developers.knowledge.v1.DeveloperKnowledge.GetDocument] or [DeveloperKnowledge.BatchGetDocuments][google.developers.knowledge.v1.DeveloperKnowledge.BatchGetDocuments] to fetch the full content of the top results.
All document content is provided in Markdown format.
This class provides the ability to make remote calls to the backing service through method calls that map to API methods. Sample code to get started:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (DeveloperKnowledgeClient developerKnowledgeClient = DeveloperKnowledgeClient.create()) {
DocumentName name = DocumentName.of("[DOCUMENT]");
Document response = developerKnowledgeClient.getDocument(name);
}
Note: close() needs to be called on the DeveloperKnowledgeClient object to clean up resources such as threads. In the example above, try-with-resources is used, which automatically calls close().
| Method | Description | Method Variants |
|---|---|---|
SearchDocumentChunks |
Searches for developer knowledge across Google's developer documentation. Returns [DocumentChunk][google.developers.knowledge.v1.DocumentChunk]s based on the user's query. There may be many chunks from the same [Document][google.developers.knowledge.v1.Document]. To retrieve full documents, use [DeveloperKnowledge.GetDocument][google.developers.knowledge.v1.DeveloperKnowledge.GetDocument] or [DeveloperKnowledge.BatchGetDocuments][google.developers.knowledge.v1.DeveloperKnowledge.BatchGetDocuments] with the [DocumentChunk.parent][google.developers.knowledge.v1.DocumentChunk.parent] returned in the [SearchDocumentChunksResponse.results][google.developers.knowledge.v1.SearchDocumentChunksResponse.results]. |
Request object method variants only take one parameter, a request object, which must be constructed before the call.
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
|
GetDocument |
Retrieves a single document with its full Markdown content. |
Request object method variants only take one parameter, a request object, which must be constructed before the call.
"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
|
BatchGetDocuments |
Retrieves multiple documents, each with its full Markdown content. |
Request object method variants only take one parameter, a request object, which must be constructed before the call.
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
|
See the individual methods for example code.
Many parameters require resource names to be formatted in a particular way. To assist with these names, this class includes a format method for each type of name, and additionally a parse method to extract the individual identifiers contained within names that are returned.
This class can be customized by passing in a custom instance of DeveloperKnowledgeSettings to create(). For example:
To customize credentials:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
DeveloperKnowledgeSettings developerKnowledgeSettings =
DeveloperKnowledgeSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
.build();
DeveloperKnowledgeClient developerKnowledgeClient =
DeveloperKnowledgeClient.create(developerKnowledgeSettings);
To customize the endpoint:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
DeveloperKnowledgeSettings developerKnowledgeSettings =
DeveloperKnowledgeSettings.newBuilder().setEndpoint(myEndpoint).build();
DeveloperKnowledgeClient developerKnowledgeClient =
DeveloperKnowledgeClient.create(developerKnowledgeSettings);
To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over the wire:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
DeveloperKnowledgeSettings developerKnowledgeSettings =
DeveloperKnowledgeSettings.newHttpJsonBuilder().build();
DeveloperKnowledgeClient developerKnowledgeClient =
DeveloperKnowledgeClient.create(developerKnowledgeSettings);
Please refer to the GitHub repository's samples for more quickstart code snippets.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic classstatic class -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedConstructs an instance of DeveloperKnowledgeClient, using the given settings.protected -
Method Summary
Modifier and TypeMethodDescriptionbooleanawaitTermination(long duration, TimeUnit unit) Retrieves multiple documents, each with its full Markdown content.Retrieves multiple documents, each with its full Markdown content.final voidclose()static final DeveloperKnowledgeClientcreate()Constructs an instance of DeveloperKnowledgeClient with default settings.static final DeveloperKnowledgeClientcreate(DeveloperKnowledgeSettings settings) Constructs an instance of DeveloperKnowledgeClient, using the given settings.static final DeveloperKnowledgeClientcreate(DeveloperKnowledgeStub stub) Constructs an instance of DeveloperKnowledgeClient, using the given stub for making calls.final DocumentgetDocument(DocumentName name) Retrieves a single document with its full Markdown content.final DocumentgetDocument(GetDocumentRequest request) Retrieves a single document with its full Markdown content.final DocumentgetDocument(String name) Retrieves a single document with its full Markdown content.Retrieves a single document with its full Markdown content.getStub()booleanbooleanSearches for developer knowledge across Google's developer documentation.Searches for developer knowledge across Google's developer documentation.final UnaryCallable<SearchDocumentChunksRequest,DeveloperKnowledgeClient.SearchDocumentChunksPagedResponse> Searches for developer knowledge across Google's developer documentation.voidshutdown()void
-
Constructor Details
-
DeveloperKnowledgeClient
Constructs an instance of DeveloperKnowledgeClient, using the given settings. This is protected so that it is easy to make a subclass, but otherwise, the static factory methods should be preferred.- Throws:
IOException
-
DeveloperKnowledgeClient
-
-
Method Details
-
create
Constructs an instance of DeveloperKnowledgeClient with default settings.- Throws:
IOException
-
create
public static final DeveloperKnowledgeClient create(DeveloperKnowledgeSettings settings) throws IOException Constructs an instance of DeveloperKnowledgeClient, using the given settings. The channels are created based on the settings passed in, or defaults for any settings that are not set.- Throws:
IOException
-
create
Constructs an instance of DeveloperKnowledgeClient, using the given stub for making calls. This is for advanced usage - prefer using create(DeveloperKnowledgeSettings). -
getSettings
-
getStub
-
searchDocumentChunks
public final DeveloperKnowledgeClient.SearchDocumentChunksPagedResponse searchDocumentChunks(SearchDocumentChunksRequest request) Searches for developer knowledge across Google's developer documentation. Returns [DocumentChunk][google.developers.knowledge.v1.DocumentChunk]s based on the user's query. There may be many chunks from the same [Document][google.developers.knowledge.v1.Document]. To retrieve full documents, use [DeveloperKnowledge.GetDocument][google.developers.knowledge.v1.DeveloperKnowledge.GetDocument] or [DeveloperKnowledge.BatchGetDocuments][google.developers.knowledge.v1.DeveloperKnowledge.BatchGetDocuments] with the [DocumentChunk.parent][google.developers.knowledge.v1.DocumentChunk.parent] returned in the [SearchDocumentChunksResponse.results][google.developers.knowledge.v1.SearchDocumentChunksResponse.results].Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (DeveloperKnowledgeClient developerKnowledgeClient = DeveloperKnowledgeClient.create()) { SearchDocumentChunksRequest request = SearchDocumentChunksRequest.newBuilder() .setQuery("query107944136") .setPageSize(883849137) .setPageToken("pageToken873572522") .setFilter("filter-1274492040") .build(); for (DocumentChunk element : developerKnowledgeClient.searchDocumentChunks(request).iterateAll()) { // doThingsWith(element); } }- Parameters:
request- The request object containing all of the parameters for the API call.- Throws:
ApiException- if the remote call fails
-
searchDocumentChunksPagedCallable
public final UnaryCallable<SearchDocumentChunksRequest,DeveloperKnowledgeClient.SearchDocumentChunksPagedResponse> searchDocumentChunksPagedCallable()Searches for developer knowledge across Google's developer documentation. Returns [DocumentChunk][google.developers.knowledge.v1.DocumentChunk]s based on the user's query. There may be many chunks from the same [Document][google.developers.knowledge.v1.Document]. To retrieve full documents, use [DeveloperKnowledge.GetDocument][google.developers.knowledge.v1.DeveloperKnowledge.GetDocument] or [DeveloperKnowledge.BatchGetDocuments][google.developers.knowledge.v1.DeveloperKnowledge.BatchGetDocuments] with the [DocumentChunk.parent][google.developers.knowledge.v1.DocumentChunk.parent] returned in the [SearchDocumentChunksResponse.results][google.developers.knowledge.v1.SearchDocumentChunksResponse.results].Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (DeveloperKnowledgeClient developerKnowledgeClient = DeveloperKnowledgeClient.create()) { SearchDocumentChunksRequest request = SearchDocumentChunksRequest.newBuilder() .setQuery("query107944136") .setPageSize(883849137) .setPageToken("pageToken873572522") .setFilter("filter-1274492040") .build(); ApiFuture<DocumentChunk> future = developerKnowledgeClient.searchDocumentChunksPagedCallable().futureCall(request); // Do something. for (DocumentChunk element : future.get().iterateAll()) { // doThingsWith(element); } } -
searchDocumentChunksCallable
public final UnaryCallable<SearchDocumentChunksRequest,SearchDocumentChunksResponse> searchDocumentChunksCallable()Searches for developer knowledge across Google's developer documentation. Returns [DocumentChunk][google.developers.knowledge.v1.DocumentChunk]s based on the user's query. There may be many chunks from the same [Document][google.developers.knowledge.v1.Document]. To retrieve full documents, use [DeveloperKnowledge.GetDocument][google.developers.knowledge.v1.DeveloperKnowledge.GetDocument] or [DeveloperKnowledge.BatchGetDocuments][google.developers.knowledge.v1.DeveloperKnowledge.BatchGetDocuments] with the [DocumentChunk.parent][google.developers.knowledge.v1.DocumentChunk.parent] returned in the [SearchDocumentChunksResponse.results][google.developers.knowledge.v1.SearchDocumentChunksResponse.results].Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (DeveloperKnowledgeClient developerKnowledgeClient = DeveloperKnowledgeClient.create()) { SearchDocumentChunksRequest request = SearchDocumentChunksRequest.newBuilder() .setQuery("query107944136") .setPageSize(883849137) .setPageToken("pageToken873572522") .setFilter("filter-1274492040") .build(); while (true) { SearchDocumentChunksResponse response = developerKnowledgeClient.searchDocumentChunksCallable().call(request); for (DocumentChunk element : response.getResultsList()) { // doThingsWith(element); } String nextPageToken = response.getNextPageToken(); if (!Strings.isNullOrEmpty(nextPageToken)) { request = request.toBuilder().setPageToken(nextPageToken).build(); } else { break; } } } -
getDocument
Retrieves a single document with its full Markdown content.Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (DeveloperKnowledgeClient developerKnowledgeClient = DeveloperKnowledgeClient.create()) { DocumentName name = DocumentName.of("[DOCUMENT]"); Document response = developerKnowledgeClient.getDocument(name); }- Parameters:
name- Required. Specifies the name of the document to retrieve. Format: `documents/{uri_without_scheme}` Example: `documents/docs.cloud.google.com/storage/docs/creating-buckets`- Throws:
ApiException- if the remote call fails
-
getDocument
Retrieves a single document with its full Markdown content.Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (DeveloperKnowledgeClient developerKnowledgeClient = DeveloperKnowledgeClient.create()) { String name = DocumentName.of("[DOCUMENT]").toString(); Document response = developerKnowledgeClient.getDocument(name); }- Parameters:
name- Required. Specifies the name of the document to retrieve. Format: `documents/{uri_without_scheme}` Example: `documents/docs.cloud.google.com/storage/docs/creating-buckets`- Throws:
ApiException- if the remote call fails
-
getDocument
Retrieves a single document with its full Markdown content.Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (DeveloperKnowledgeClient developerKnowledgeClient = DeveloperKnowledgeClient.create()) { GetDocumentRequest request = GetDocumentRequest.newBuilder() .setName(DocumentName.of("[DOCUMENT]").toString()) .setView(DocumentView.forNumber(0)) .build(); Document response = developerKnowledgeClient.getDocument(request); }- Parameters:
request- The request object containing all of the parameters for the API call.- Throws:
ApiException- if the remote call fails
-
getDocumentCallable
Retrieves a single document with its full Markdown content.Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (DeveloperKnowledgeClient developerKnowledgeClient = DeveloperKnowledgeClient.create()) { GetDocumentRequest request = GetDocumentRequest.newBuilder() .setName(DocumentName.of("[DOCUMENT]").toString()) .setView(DocumentView.forNumber(0)) .build(); ApiFuture<Document> future = developerKnowledgeClient.getDocumentCallable().futureCall(request); // Do something. Document response = future.get(); } -
batchGetDocuments
Retrieves multiple documents, each with its full Markdown content.Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (DeveloperKnowledgeClient developerKnowledgeClient = DeveloperKnowledgeClient.create()) { BatchGetDocumentsRequest request = BatchGetDocumentsRequest.newBuilder() .addAllNames(new ArrayList<String>()) .setView(DocumentView.forNumber(0)) .build(); BatchGetDocumentsResponse response = developerKnowledgeClient.batchGetDocuments(request); }- Parameters:
request- The request object containing all of the parameters for the API call.- Throws:
ApiException- if the remote call fails
-
batchGetDocumentsCallable
public final UnaryCallable<BatchGetDocumentsRequest,BatchGetDocumentsResponse> batchGetDocumentsCallable()Retrieves multiple documents, each with its full Markdown content.Sample code:
// This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (DeveloperKnowledgeClient developerKnowledgeClient = DeveloperKnowledgeClient.create()) { BatchGetDocumentsRequest request = BatchGetDocumentsRequest.newBuilder() .addAllNames(new ArrayList<String>()) .setView(DocumentView.forNumber(0)) .build(); ApiFuture<BatchGetDocumentsResponse> future = developerKnowledgeClient.batchGetDocumentsCallable().futureCall(request); // Do something. BatchGetDocumentsResponse response = future.get(); } -
close
public final void close()- Specified by:
closein interfaceAutoCloseable
-
shutdown
public void shutdown()- Specified by:
shutdownin interfaceBackgroundResource
-
isShutdown
public boolean isShutdown()- Specified by:
isShutdownin interfaceBackgroundResource
-
isTerminated
public boolean isTerminated()- Specified by:
isTerminatedin interfaceBackgroundResource
-
shutdownNow
public void shutdownNow()- Specified by:
shutdownNowin interfaceBackgroundResource
-
awaitTermination
- Specified by:
awaitTerminationin interfaceBackgroundResource- Throws:
InterruptedException
-