Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.google.appengine.api.search
Interface Index

    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

### getName

    java.lang.String getName()

  Returns:
    the name of the index

### getNamespace

    java.lang.String getNamespace()

  Returns:
    the namespace of the index name

### getConsistency

    Consistency getConsistency()

  Returns:
    the consistency mode of this index

### deleteDocumentAsync

    java.util.concurrent.Future<DeleteDocumentsResponse> deleteDocumentAsync(java.lang.String documentId)

  See Also:
    `deleteDocument(String)`

### deleteDocumentsAsync

    java.util.concurrent.Future<DeleteDocumentsResponse> deleteDocumentsAsync(java.lang.Iterable<java.lang.String> documentIds)

  See Also:
    `deleteDocuments(Iterable)`

### indexDocumentAsync

    java.util.concurrent.Future<IndexDocumentsResponse> indexDocumentAsync(Document document)

  See Also:
    `indexDocument(Document)`

### indexDocumentsAsync

    java.util.concurrent.Future<IndexDocumentsResponse> indexDocumentsAsync(java.lang.Iterable<Document> documents)

  See Also:
    `indexDocuments(Iterable)`

### searchAsync

    java.util.concurrent.Future<SearchResponse> searchAsync(java.lang.String query)

  See Also:
    `search(String)`

### searchAsync

    java.util.concurrent.Future<SearchResponse> searchAsync(SearchRequest request)

  See Also:
    `search(SearchRequest)`

### listDocumentsAsync

    java.util.concurrent.Future<ListDocumentsResponse> listDocumentsAsync(ListDocumentsRequest request)

  See Also:
    `listDocuments(ListDocumentsRequest)`

### deleteDocument

    DeleteDocumentsResponse deleteDocument(java.lang.String documentId)

  Delete the document with the corresponding document id from the index if it is in the index. If no document exists for the document id, then the request is ignored.

  Parameters:
    `documentId` - the id of the document to delete
  Returns:
    a `DeleteDocumentsResponse` containing the result of the delete document operation indicating success or failure
  Throws:
    `DeleteDocumentsException` - if there is a failure in the search service deleting documents
    `java.lang.IllegalArgumentException` - if the document id is invalid

### deleteDocuments

    DeleteDocumentsResponse deleteDocuments(java.lang.Iterable<java.lang.String> documentIds)

  Delete documents from the index which have ids in the documentIds collection. If the index does not have a document for a given document id, that is ignored. If any document delete fails, then no documents will be deleted.

  Parameters:
    `documentIds` - the ids of documents which are to be deleted from the index
  Returns:
    a `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
  Throws:
    `DeleteDocumentsException` - if there is a failure in the search service deleting documents
    `java.lang.IllegalArgumentException` - if the document id collection is invalid

### indexDocument

    IndexDocumentsResponse indexDocument(Document document)

  Index the document, re-indexing the document if it is already present.

  Parameters:
    `document` - the document to index
  Returns:
    an `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
  Throws:
    `IndexDocumentsException` - if there is a failure in the search service indexing documents
    `java.lang.IllegalArgumentException` - if the document is invalid

### indexDocuments

    IndexDocumentsResponse indexDocuments(java.lang.Iterable<Document> documents)

  Index the collection of documents. If any of the documents are already in the index, then re-index them with their corresponding fresh document. If any of the documents fail to be indexed, then none of the documents will be indexed.

  Parameters:
    `documents` - the documents to index
  Returns:
    an `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
  Throws:
    `IndexDocumentsException` - if there is a failure in the search service indexing documents
    `java.lang.IllegalArgumentException` - if the document collection is invalid

### search

    SearchResponse search(java.lang.String query)

  Search the index for documents matching the query.

  Parameters:
    `query` - the query to match against documents in the index
  Returns:
    a `SearchResponse` containing the search results
  Throws:
    `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 search

### search

    SearchResponse search(SearchRequest request)

  Search the index for documents matching the query in the request. The search request must specify a query, how many documents are requested, how the results are to be sorted, scored and which fields are to be returned.

  Parameters:
    `request` - the fully specified search request
  Returns:
    a `SearchResponse` containing the search results
  Throws:
    `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 search

### listDocuments

    ListDocumentsResponse listDocuments(ListDocumentsRequest request)

  Lists the index's documents, in document Id order.

  Parameters:
    `request` - contains various options restricting which documents are returned.
  Returns:
    a `ListDocumentsResponse` containing a list of documents from the index
  Throws:
    `java.lang.IllegalArgumentException` - if the list documents request is invalid

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD