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 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")
              .setConsistency(Consistency.PER_DOCUMENT));

      // 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();

      // Add the document.
      try {
        index.add(document);
      } catch (AddException e) {
        if (StatusCode.TRANSIENT_ERROR.equals(e.getOperationResult().getCode())) {
          // retry adding 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
`AddResponse` | `add(Document... documents)` Add the documents to the index, updating any document that is already present.
`AddResponse` | `add(java.lang.Iterable<Document> documents)`
`java.util.concurrent.Future<AddResponse>` | `addAsync(Document... document)`
`java.util.concurrent.Future<AddResponse>` | `addAsync(java.lang.Iterable<Document> documents)`
`Document` | `get(java.lang.String documentId)` Gets a `Document` for the given document Id.
`Consistency` | `getConsistency()`
`java.lang.String` | `getName()`
`java.lang.String` | `getNamespace()`
`Schema` | `getSchema()`
`ListResponse<Document>` | `listDocuments(ListRequest request)` Lists the index's documents, in document Id order.
`java.util.concurrent.Future<ListResponse<Document>>` | `listDocumentsAsync(ListRequest request)`
`void` | `remove(java.lang.Iterable<java.lang.String> documentIds)`
`void` | `remove(java.lang.String... documentIds)` Delete documents for the given document ids from the index if they are 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)`
`Results<ScoredDocument>` | `search(Query query)` Search the index for documents matching the query.
`Results<ScoredDocument>` | `search(java.lang.String query)`
`java.util.concurrent.Future<Results<ScoredDocument>>` | `searchAsync(Query query)`
`java.util.concurrent.Future<Results<ScoredDocument>>` | `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

### removeAsync

    java.util.concurrent.Future<java.lang.Void> removeAsync(java.lang.String... documentId)

  See Also:
    `#remove(String...)}`

### removeAsync

    java.util.concurrent.Future<java.lang.Void> removeAsync(java.lang.Iterable<java.lang.String> documentIds)

  See Also:
    `#remove(String...)}`

### addAsync

    java.util.concurrent.Future<AddResponse> addAsync(Document... document)

  See Also:
    `#add(Document...)}`

### addAsync

    java.util.concurrent.Future<AddResponse> addAsync(java.lang.Iterable<Document> documents)

  See Also:
    `#add(Document...)}`

### searchAsync

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

  See Also:
    `{@link #search(String)}`

### searchAsync

    java.util.concurrent.Future<Results<ScoredDocument>> searchAsync(Query query)

  See Also:
    `#search(Query)}`

### listDocumentsAsync

    java.util.concurrent.Future<ListResponse<Document>> listDocumentsAsync(ListRequest request)

  See Also:
    `#listDocuments(ListRequest)}`

### remove

    void remove(java.lang.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 remove
  Throws:
    `RemoveException` - if there is a failure in the search service deleting documents
    `java.lang.IllegalArgumentException` - if some document id is invalid

### remove

    void remove(java.lang.Iterable<java.lang.String> documentIds)

  See Also:
    `#remove(String...)}`

### add

    AddResponse add(Document... documents)

  Add the documents to the index, updating any document that is already present.

  Parameters:
    `documents` - the documents to add to the index
  Returns:
    an `AddResponse` containing the result 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
  Throws:
    `AddException` - if there is a failure in the search service adding documents
    `java.lang.IllegalArgumentException` - if some document is invalid or more than `IndexChecker.MAXIMUM_DOCS_PER_REQUEST` documents requested to be added

### add

    AddResponse add(java.lang.Iterable<Document> documents)

  See Also:
    `#add(Document...)}`

### get

    Document get(java.lang.String documentId)

  Gets a `Document` for the given document Id.

  Parameters:
    `documentId` - the identifier for the document to retrieve
  Returns:
    the associated `Document`. can be null

### search

    Results<ScoredDocument> search(java.lang.String query)

  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 specified `Query` object
  Returns:
    a `Results` containing `ScoredDocuments`
  Throws:
    `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

### listDocuments

    ListResponse<Document> listDocuments(ListRequest request)

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

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

### getSchema

    Schema getSchema()

  Returns:
    the `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 `SearchService.listIndexes(com.google.appengine.api.search.ListIndexesRequest)` request

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