|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface Index
An Index allows synchronous adding and deleting of Documents
as well as synchronous searching for Documents. The following
code fragment shows how to add documents, then search the index for
documents matching a query.
// Get the index manager for the default namespace IndexManager indexManager = IndexManagerFactory.newIndexManager(); // Get the index. If not yet created, create it. Index index = indexManager.getIndex( IndexSpec.newBuilder() .setIndexName("indexName") .setConsistency(Consistency.PER_DOCUMENT)); // Create a document. Document d = 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(); // Add the document. try { index.add(d); } catch (AddDocumentsException e) { if (StatusCode.TRANSIENT_ERROR.equals(e.getOperationResult().getCode())) { // retry adding document } } // Query the index. try { SearchResponse response = index.search("subject:first body:here"); // Iterate through the search results. for (SearchResult result : response) { Document doc = result.getDocument(); } } catch (SearchException e) { if (StatusCode.TRANSIENT_ERROR.equals(e.getOperationResult().getCode())) { // retry } }
Method Summary | |
---|---|
AddDocumentsResponse |
add(Document document)
Add the document, update the document if it is already present. |
AddDocumentsResponse |
add(java.lang.Iterable<Document> documents)
Adds the collection of documents. |
java.util.concurrent.Future<AddDocumentsResponse> |
addAsync(Document document)
|
java.util.concurrent.Future<AddDocumentsResponse> |
addAsync(java.lang.Iterable<Document> documents)
|
Consistency |
getConsistency()
|
java.lang.String |
getName()
|
java.lang.String |
getNamespace()
|
Schema |
getSchema()
|
ListDocumentsResponse |
listDocuments(ListDocumentsRequest request)
Lists the index's documents, in document Id order. |
java.util.concurrent.Future<ListDocumentsResponse> |
listDocumentsAsync(ListDocumentsRequest request)
|
void |
remove(java.lang.Iterable<java.lang.String> documentIds)
Delete documents from the index which have IDs in the documentIds
collection. |
void |
remove(java.lang.String documentId)
Delete the document with the corresponding document id from the index if it is in the index. |
java.util.concurrent.Future<java.lang.Void> |
removeAsync(java.lang.Iterable<java.lang.String> documentIds)
|
java.util.concurrent.Future<java.lang.Void> |
removeAsync(java.lang.String documentId)
|
SearchResponse |
search(SearchRequest request)
Search the index for documents matching the query in the request. |
SearchResponse |
search(java.lang.String query)
Search the index for documents matching the query. |
java.util.concurrent.Future<SearchResponse> |
searchAsync(SearchRequest request)
|
java.util.concurrent.Future<SearchResponse> |
searchAsync(java.lang.String query)
|
Method Detail |
---|
java.lang.String getName()
java.lang.String getNamespace()
Consistency getConsistency()
java.util.concurrent.Future<java.lang.Void> removeAsync(java.lang.String documentId)
remove(String)
java.util.concurrent.Future<java.lang.Void> removeAsync(java.lang.Iterable<java.lang.String> documentIds)
remove(Iterable)
java.util.concurrent.Future<AddDocumentsResponse> addAsync(Document document)
add(Document)
java.util.concurrent.Future<AddDocumentsResponse> addAsync(java.lang.Iterable<Document> documents)
add(Iterable)
java.util.concurrent.Future<SearchResponse> searchAsync(java.lang.String query)
search(String)
java.util.concurrent.Future<SearchResponse> searchAsync(SearchRequest request)
search(SearchRequest)
java.util.concurrent.Future<ListDocumentsResponse> listDocumentsAsync(ListDocumentsRequest request)
listDocuments(ListDocumentsRequest)
void remove(java.lang.String documentId)
documentId
- the id of the document to remove
RemoveDocumentsException
- if there is a failure in the search
service deleting documents
java.lang.IllegalArgumentException
- if the document id is invalidvoid remove(java.lang.Iterable<java.lang.String> documentIds)
documentIds
collection. If the index does not have a document for a given document id,
that is ignored. For globally consistent indexes either all or none of
documents are removed. For per-document consistent indexes, if some documents
are not successfully removed, their IDs are reported in the
RemoveDocumentsException
documentIds
- the IDs of documents which are to be removed from the
index
RemoveDocumentsException
- if there is a failure in the search
service deleting documents
java.lang.IllegalArgumentException
- if the document id collection is invalid
or larger than IndexChecker#MAXIMUM_DOCS_PER_REQUEST
.AddDocumentsResponse add(Document document)
document
- the document to add to the index
AddDocumentsResponse
containing the result of
the add operation indicating success or failure as well as the document
id. The search service will allocate document ids for documents which
have none provided
AddDocumentsException
- if there is a failure in the search
service adding documents
java.lang.IllegalArgumentException
- if the document is invalidAddDocumentsResponse add(java.lang.Iterable<Document> documents)
documents
- the documents to add to the index
AddDocumentsResponse
containing the results of
the add operations indicating success or failure as well as the document
Ids. The search service will allocate document ids for documents which
have none provided
AddDocumentsException
- if there is a failure in the search service
adding documents
java.lang.IllegalArgumentException
- if the document collection is invalid or
larger than IndexChecker#MAXIMUM_DOCS_PER_REQUEST
.SearchResponse search(java.lang.String query)
query
- the query to match against documents in the index
SearchResponse
containing the search results
java.lang.IllegalArgumentException
- if the query is null
SearchQueryException
- if the query is invalid
SearchException
- if there is a failure in the search service
performing the searchSearchResponse search(SearchRequest request)
request
- the fully specified search request
SearchResponse
containing the search results
java.lang.IllegalArgumentException
- if the search request is invalid
SearchQueryException
- if the query is invalid
SearchException
- if there is a failure in the search service
performing the searchListDocumentsResponse listDocuments(ListDocumentsRequest request)
request
- contains various options restricting which documents are returned.
ListDocumentsResponse
containing a list of documents from the
index
java.lang.IllegalArgumentException
- if the list documents request is invalidSchema getSchema()
Schema
describing supported document field names and
Field.FieldType
s supported for those field names. This schema
will only be populated if the ListIndexesRequest.isSchemaFetched()
is set to true on an IndexManager.listIndexes(com.google.appengine.api.search.ListIndexesRequest)
request
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |