|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
public interface Index
An Index allows synchronous indexing and deleting of Documents as well as synchronous searching for Documents. The following
code fragment shows how to index 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.get(
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();
// Index the document.
try {
index.indexDocument(d);
} catch (IndexDocumentsFailure e) {
if (StatusCode.TRANSIENT_ERROR.equals(e.getOperationResult().getCode())) {
// retry index 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 | |
|---|---|
DeleteDocumentsResponse |
deleteDocument(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<DeleteDocumentsResponse> |
deleteDocumentAsync(java.lang.String documentId)
|
DeleteDocumentsResponse |
deleteDocuments(java.lang.Iterable<java.lang.String> documentIds)
Delete documents from the index which have ids in the documentIds collection. |
java.util.concurrent.Future<DeleteDocumentsResponse> |
deleteDocumentsAsync(java.lang.Iterable<java.lang.String> documentIds)
|
Consistency |
getConsistency()
|
java.lang.String |
getName()
|
java.lang.String |
getNamespace()
|
IndexDocumentsResponse |
indexDocument(Document document)
Index the document, re-indexing the document if it is already present. |
java.util.concurrent.Future<IndexDocumentsResponse> |
indexDocumentAsync(Document document)
|
IndexDocumentsResponse |
indexDocuments(java.lang.Iterable<Document> documents)
Index the collection of documents. |
java.util.concurrent.Future<IndexDocumentsResponse> |
indexDocumentsAsync(java.lang.Iterable<Document> documents)
|
ListDocumentsResponse |
listDocuments(ListDocumentsRequest request)
Lists the index's documents, in document Id order. |
java.util.concurrent.Future<ListDocumentsResponse> |
listDocumentsAsync(ListDocumentsRequest request)
|
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<DeleteDocumentsResponse> deleteDocumentAsync(java.lang.String documentId)
deleteDocument(String)java.util.concurrent.Future<DeleteDocumentsResponse> deleteDocumentsAsync(java.lang.Iterable<java.lang.String> documentIds)
deleteDocuments(Iterable)java.util.concurrent.Future<IndexDocumentsResponse> indexDocumentAsync(Document document)
indexDocument(Document)java.util.concurrent.Future<IndexDocumentsResponse> indexDocumentsAsync(java.lang.Iterable<Document> documents)
indexDocuments(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)DeleteDocumentsResponse deleteDocument(java.lang.String documentId)
documentId - the id of the document to delete
DeleteDocumentsResponse containing the result of the
delete document operation indicating success or failure
DeleteDocumentsException - if there is a failure in the search
service deleting documents
java.lang.IllegalArgumentException - if the document id is invalidDeleteDocumentsResponse deleteDocuments(java.lang.Iterable<java.lang.String> documentIds)
documentIds - the ids of documents which are to be deleted from the
index
DeleteDocumentsResponse containing the result of the
delete document operations indicating success or failure. The order
of the results matches the order of the supplied documents
DeleteDocumentsException - if there is a failure in the search
service deleting documents
java.lang.IllegalArgumentException - if the document id collection is invalidIndexDocumentsResponse indexDocument(Document document)
document - the document to index
IndexDocumentsResponse containing the result of
the index operation indicating success or failure as well as the document
id. The search service will allocate document ids for documents which
have none provided
IndexDocumentsException - if there is a failure in the search
service indexing documents
java.lang.IllegalArgumentException - if the document is invalidIndexDocumentsResponse indexDocuments(java.lang.Iterable<Document> documents)
documents - the documents to index
IndexDocumentsResponse containing the results of
the index operations indicating success or failure as well as the document
Ids. The search service will allocate document ids for documents which
have none provided
IndexDocumentsException - if there is a failure in the search service
indexing documents
java.lang.IllegalArgumentException - if the document collection is invalidSearchResponse 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 invalid
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||