Index (Google App Engine API for Java)

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"));
    
      // 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 Detail

      • getName

        java.lang.String getName()
        Returns:
        the name of the index
      • getNamespace

        java.lang.String getNamespace()
        Returns:
        the namespace of the index name
      • deleteAsync

        java.util.concurrent.Future<java.lang.Void> deleteAsync(java.lang.String... documentId)
        See Also:
        delete(String...)
      • deleteAsync

        java.util.concurrent.Future<java.lang.Void> deleteAsync(java.lang.Iterable<java.lang.String> documentIds)
        See Also:
        delete(String...)
      • deleteSchemaAsync

        @Deprecated
        java.util.concurrent.Future<java.lang.Void> deleteSchemaAsync()
        Deprecated. as of 1.7.4
        See Also:
        deleteSchema()
      • putAsync

        java.util.concurrent.Future<