Package com.google.appengine.api.search
Interface Index
-
public interface IndexAn Index allows synchronous and asynchronous adding and deleting ofDocumentsas well as synchronous and asynchronous searching for Documents for a givenQuery. 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 } }
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voiddelete(Iterable<String> documentIds)voiddelete(String... documentIds)Delete documents for the given document ids from the index if they are in the index.Future<Void>deleteAsync(Iterable<String> documentIds)Future<Void>deleteAsync(String... documentId)voiddeleteSchema()Delete the schema from the index.Future<Void>deleteSchemaAsync()Documentget(String documentId)Gets aDocumentfor the given document Id.StringgetName()StringgetNamespace()GetResponse<Document>getRange(GetRequest request)Get an index's documents, in document Id order.GetResponse<Document>getRange(GetRequest.Builder builder)Future<GetResponse<Document>>getRangeAsync(GetRequest request)Future<GetResponse<Document>>getRangeAsync(GetRequest.Builder builder)SchemagetSchema()longgetStorageLimit()longgetStorageUsage()PutResponseput(Document.Builder... builders)PutResponseput(Document... documents)Put the documents into the index, updating any document that is already present.PutResponseput(Iterable<Document> documents)Future<PutResponse>putAsync(Document.Builder... document)Future<PutResponse>putAsync(Document... document)Future<PutResponse>putAsync(Iterable<Document> documents)Results<ScoredDocument>search(Query query)Search the index for documents matching the query.Results<ScoredDocument>search(String query)Search the index for documents matching the query string.Future<Results<ScoredDocument>>searchAsync(Query query)Future<Results<ScoredDocument>>searchAsync(String query)
-
-
-
Method Detail
-
getName
String getName()
- Returns:
- the name of the index
-
getNamespace
String getNamespace()
- Returns:
- the namespace of the index name
-
deleteAsync
Future<Void> deleteAsync(String... documentId)
- See Also:
delete(String...)
-
deleteAsync
Future<Void> deleteAsync(Iterable<String> documentIds)
- See Also:
delete(String...)
-
deleteSchemaAsync
Future<Void> deleteSchemaAsync()
- See Also:
deleteSchema()
-
putAsync
Future<PutResponse> putAsync(Document... document)
- See Also:
put(Document...)
-
putAsync
Future<PutResponse> putAsync(Document.Builder... document)
- See Also:
put(Document...)
-
putAsync
Future<PutResponse> putAsync(Iterable<Document> documents)
- See Also:
put(Document...)
-
searchAsync
Future<Results<ScoredDocument>> searchAsync(String query)
- See Also:
search(String)
-
searchAsync
Future<Results<ScoredDocument>> searchAsync(Query query)
- See Also:
search(Query)
-
getRangeAsync
Future<GetResponse<Document>> getRangeAsync(GetRequest request)
- See Also:
getRange(GetRequest)
-
getRangeAsync
Future<GetResponse<Document>> getRangeAsync(GetRequest.Builder builder)
- See Also:
getRange(GetRequest)
-
delete
void delete(String... documentIds)
Delete documents for the given document ids from the index if they are in the index.- Parameters:
documentIds- the ids of documents to delete- Throws:
DeleteException- if there is a failure in the search service deleting documentsIllegalArgumentException- if some document id is invalid
-
delete
void delete(Iterable<String> documentIds)
- See Also:
delete(String...)
-
deleteSchema
void deleteSchema()
Delete the schema from the index. To fully delete an index, you must delete both the index's documents and schema. This method deletes the index's schema, which contains field names and field types of previously indexed documents.- Throws:
DeleteException- if there is a failure in the search service deleting the schema
-
put
PutResponse put(Document... documents)
Put the documents into the index, updating any document that is already present.- Parameters:
documents- the documents to put into the index- Returns:
- an
PutResponsecontaining 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 - Throws:
PutException- if there is a failure in the search service putting documentsIllegalArgumentException- if some document is invalid or more thanSearchApiLimits.PUT_MAXIMUM_DOCS_PER_REQUESTdocuments requested to be put into the index
-
put
PutResponse put(Document.Builder... builders)
- See Also:
put(Document...)
-
put
PutResponse put(Iterable<Document> documents)
- See Also:
put(Document...)
-
get
Document get(String documentId)
Gets aDocumentfor the given document Id.- Parameters:
documentId- the identifier for the document to retrieve- Returns:
- the associated
Document. can be null
-
search
Results<ScoredDocument> search(String query)
Search the index for documents matching the query string.- Parameters:
query- the query string- Returns:
- a
ResultscontainingScoredDocuments - Throws:
SearchQueryException- if the query string is invalidSearchException- if there is a failure in the search service performing the search- See Also:
search(Query)
-
search
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.- Parameters:
query- the fully specifiedQueryobject- Returns:
- a
ResultscontainingScoredDocuments - Throws:
IllegalArgumentException- if the query is invalidSearchQueryException- if the query string is invalidSearchException- if there is a failure in the search service performing the search
-
getRange
GetResponse<Document> getRange(GetRequest request)
Get an index's documents, in document Id order.- Parameters:
request- contains various options restricting which documents are returned.- Returns:
- a
GetResponsecontaining a list of documents from the index - Throws:
IllegalArgumentException- if the get request is invalid
-
getRange
GetResponse<Document> getRange(GetRequest.Builder builder)
- See Also:
getRange(GetRequest)
-
getSchema
Schema getSchema()
- Returns:
- the
Schemadescribing supported document field names andField.FieldTypes supported for those field names. This schema will only be populated if theGetIndexesRequest.isSchemaFetched()is set totrueon aSearchService.getIndexes(com.google.appengine.api.search.GetIndexesRequest)request
-
getStorageUsage
long getStorageUsage()
- Returns:
- a rough approximation of the amount of storage space currently used by this index, expressed in bytes
- Throws:
UnsupportedOperationException- if called on an Index object that is not the result of aSearchService.getIndexes(com.google.appengine.api.search.GetIndexesRequest)request
-
getStorageLimit
long getStorageLimit()
- Returns:
- the maximum amount of storage space that the application may use in this index, expressed in bytes
- Throws:
UnsupportedOperationException- if called on an Index object that is not the result of aSearchService.getIndexes(com.google.appengine.api.search.GetIndexesRequest)
-
-