Index (Google App Engine API for Java)

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(
      // Create a document.
      Document document = Document.newBuilder()
          .addField(Field.newBuilder().setName("subject").setText("my first email"))
               .setHTML("<html>some content here</html>")
      // Put the document.
      try {
      } catch (PutException e) {
        if (StatusCode.TRANSIENT_ERROR.equals(e.getOperationResult().getCode())) {
          // retry putting document
      // Query the index.
      try {
        Results<ScoredDocument> results =
  "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