Please note that the contents of this offline web site may be out of date. To access the most recent documentation visit the online version .
Note that links that point to online resources are green in color and will open in a new window.
We would love it if you could give us feedback about this material by filling this form (You have to be online to fill it)



Package com.google.appengine.api.search

Provides a service for indexing documents and retrieving them using search queries.

See: Description

Package com.google.appengine.api.search Description

Provides a service for indexing documents and retrieving them using search queries. This is a low-level API that allows users to directly create Document s which can be indexed and retrieved with the help of Index .

A Document is a collection of Field s. Each field is a named and typed value. A document is uniquely identified by its ID and may contain zero or more fields. A field with a given name can have multiple occurrences. Once documents are put into the Index , they can be retrieved via search queries. Typically, a program creates an index. This operation does nothing if the index was already created. Next, a number of documents are inserted into the index. Finally, index is searched and matching documents, or their snippets are returned to the user.

 public List<ScoredDocument> indexAndSearch(
     String query, Document... documents) {
     SearchService searchService = SearchServiceFactory.getSearchService();
     Index index = searchService.getIndex(
         IndexSpec.newBuilder().setIndexName("indexName"));
     for (Document document : documents) {
       PutResponse response = index.put(document);
       assert response.getResults().get(0).getCode().equals(StatusCode.OK);
     }
     Results<ScoredDocument> results =
         index.search(Query.newBuilder().build(query));
     List<ScoredDocument> matched = new ArrayList<ScoredDocument>(
         results.getNumberReturned());
     for (ScoredDocument result : results) {
       matched.add(result);
     }
     return matched;
 }

See Also:
SearchServiceFactory