Stay organized with collections Save and categorize content based on your preferences.
public interface Index
An Index allows synchronous and asynchronous adding and deleting of
Documents
as well as synchronous and asynchronous searching for Documents for a given
Query
. The following code fragment shows how to add documents, then search the index for documents matching a query.
// Get the SearchService for the default namespace SearchService searchService = SearchServiceFactory.getSearchService(); // Get the index. If not yet created, create it. Index index = searchService.getIndex( IndexSpec.newBuilder().setIndexName("indexName")); // Create a document. Document document = Document.newBuilder() .setId("documentId") .addField(Field.newBuilder().setName("subject").setText("my first email")) .addField(Field.newBuilder().setName("body") .setHTML("<html>some content here</html>") .build(); // Put the document. try { index.put(document); } catch (PutException e) { if (StatusCode.TRANSIENT_ERROR.equals(e.getOperationResult().getCode())) { // retry putting document } } // Query the index. try { Results<ScoredDocument> results = index.search(Query.newBuilder().build("subject:first body:here")); // Iterate through the search results. for (ScoredDocument document : results) { // display results } } catch (SearchException e) { if (StatusCode.TRANSIENT_ERROR.equals(e.getOperationResult().getCode())) { // retry } }
java.lang.String getName()
java.lang.String getNamespace()
java.util.concurrent.Future<java.lang.Void> deleteAsync(java.lang.String... documentId)
delete(String...)
java.util.concurrent.Future<java.lang.Void> deleteAsync(java.lang.Iterable<java.lang.String> documentIds)
delete(String...)
@Deprecated java.util.concurrent.Future<java.lang.Void> deleteSchemaAsync()
Deprecated.
deleteSchema()
java.util.concurrent.Future<PutResponse> putAsync(Document... document)
put(Document...)
java.util.concurrent.Future<PutResponse> putAsync(Document.Builder... document)
put(Document...)
java.util.concurrent.Future<PutResponse> putAsync(java.lang.Iterable<Document> documents)
put(Document...)
java.util.concurrent.Future<Results<ScoredDocument>> searchAsync(java.lang.String query)
search(String)
java.util.concurrent.Future<Results<ScoredDocument>> searchAsync(Query query)
search(Query)
java.util.concurrent.Future<GetResponse<Document>> getRangeAsync(GetRequest request)
getRange(GetRequest)
java.util.concurrent.Future<GetResponse<Document>> getRangeAsync(GetRequest.Builder builder)
getRange(GetRequest)
void delete(java.lang.String... documentIds)
Delete documents for the given document ids from the index if they are in the index.
documentIds
- the ids of documents to delete
DeleteException
- if there is a failure in the search service deleting documents
java.lang.IllegalArgumentException
- if some document id is invalid
void delete(java.lang.Iterable<java.lang.String> documentIds)
delete(String...)
@Deprecated void deleteSchema()
Deprecated.
Delete the schema from the index. A possible use may be that there are typed fields which are no longer required. Make sure that you re-index some or all of your documents to enable search again. A sample of documents is required that uses named fields to rebuild the schema.
DeleteException
- if there is a failure in the search service deleting the schema
PutResponse put(Document... documents)
Put the documents into the index, updating any document that is already present.
documents
- the documents to put into the index
PutResponse
containing the result of the put operations indicating success or failure as well as the document ids. The search service will allocate document ids for documents which have none provided
PutException
- if there is a failure in the search service putting documents
java.lang.IllegalArgumentException
- if some document is invalid or more than IndexChecker#MAXIMUM_DOCS_PER_REQUEST
documents requested to be put into the index
PutResponse put(Document.Builder... builders)
put(Document...)
PutResponse put(java.lang.Iterable<Document> documents)
put(Document...)
Document get(java.lang.String documentId)
Gets a
Document
for the given document Id.
documentId
- the identifier for the document to retrieve
Document
. can be null
Results<ScoredDocument> search(java.lang.String query)
Search the index for documents matching the query string.
query
- the query string
Results
containing ScoredDocuments
SearchQueryException
- if the query string is invalid
SearchException
- if there is a failure in the search service performing the search
search(Query)
Results<ScoredDocument> search(Query query)
Search the index for documents matching the query. The query must specify a query string, and optionally, how many documents are requested, how the results are to be sorted, scored and which fields are to be returned.
query
- the fully specified Query
object
Results
containing ScoredDocuments
java.lang.IllegalArgumentException
- if the query is invalid
SearchQueryException
- if the query string is invalid
SearchException
- if there is a failure in the search service performing the search
GetResponse<Document> getRange(GetRequest request)
Get an index's documents, in document Id order.
request
- contains various options restricting which documents are returned.
GetResponse
containing a list of documents from the index
java.lang.IllegalArgumentException
- if the get request is invalid
GetResponse<Document> getRange(GetRequest.Builder builder)
getRange(GetRequest)
Schema getSchema()
Schema
describing supported document field names and Field.FieldType
s supported for those field names. This schema will only be populated if the GetIndexesRequest.isSchemaFetched()
is set to true
on a SearchService.getIndexes(com.google.appengine.api.search.GetIndexesRequest)
request
long getStorageUsage()
java.lang.UnsupportedOperationException
- if called on an Index object that is not the result of a SearchService.getIndexes(com.google.appengine.api.search.GetIndexesRequest)
request
long getStorageLimit()
java.lang.UnsupportedOperationException
- if called on an Index object that is not the result of a SearchService.getIndexes(com.google.appengine.api.search.GetIndexesRequest)
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-06-16 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","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"],["Other","otherDown","thumb-down"]],["Last updated 2025-06-16 UTC."],[[["The `Index` interface facilitates both synchronous and asynchronous operations for adding, deleting, and searching `Documents`."],["Documents can be added to an index with the `put` method, and retrieved by their `documentId` using the `get` method."],["The `search` method allows querying the index for matching `Documents`, either using a query string or a `Query` object, returning a `Results` object containing `ScoredDocuments`."],["The `delete` method allows removing documents from the index by their document IDs, with asyncronous versions of the method also available."],["The `getRange` methods allow for fetching a range of documents from the index, and the `getStorageLimit` and `getStorageUsage` methods provide information on storage space usage."]]],[]]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4