1 // Copyright 2010 Google Inc. All Rights Reserved.
3 package com
.google
.appengine
.api
.search
;
5 import java
.util
.concurrent
.Future
;
8 * The SearchService is used to get available indexes, which can be
9 * queried about their metadata or have index/delete/search operations
10 * performed on them. For example:
13 * SearchService searchService = SearchServiceFactory.getSearchService();
14 * GetResponse<Index> response = searchService.getIndexes(
15 * GetIndexesRequest.newBuilder());
16 * for (Index index : response) {
18 * index.getNamespace();
19 * index.search("query");
23 * SearchService is also responsible for creating new indexes. For
27 * SearchService searchService = SearchServiceFactory.getSearchService();
28 * Index index = searchService.getIndex(IndexSpec.newBuilder().setName("myindex"));
32 public interface SearchService
{
35 * Returns an instance of {@link Index} corresponding to the provided
38 * @return an instance of {@link Index} corresponding to the given
41 public Index
getIndex(IndexSpec spec
);
44 * Returns an instance of {@link Index} corresponding to the
45 * specification built from the given {@code builder}.
47 * @return an instance of {@link Index} corresponding to the given
50 public Index
getIndex(IndexSpec
.Builder builder
);
53 * Returns the namespace associated with this search service. Each
54 * service instance is assigned one namespace and all operations,
55 * such as listing documents, indexes inherit it. Also, when you
56 * get an index, the namespace of this service is passed to the
59 * @return the namespace associated with this search service.
61 public String
getNamespace();
64 * Gets the indexes specified. The following code fragment shows how
65 * to get the schemas of each available {@link Index}.
68 * // Get the SearchService for the default namespace
69 * SearchService searchService = SearchServiceFactory.newSearchService();
71 * // Get the first page of indexes available and retrieve schemas
72 * GetResponse<Index> response = searchService.getIndexes(
73 * GetIndexesRequest.newBuilder().setSchemaFetched(true).build());
75 * // List out elements of Schema
76 * for (Index index : response) {
77 * String name = index.getName();
78 * Schema schema = index.getSchema();
79 * for (String fieldName : schema.getFieldNames()) {
80 * List<FieldType> typesForField = schema.getFieldTypes(fieldName);
85 * @param request a request specifying which indexes to get
86 * @return a {@link GetResponse}{@code <Index>} containing a list of existing indexes
87 * @throws GetException if there is a failure in the search service
90 public GetResponse
<Index
> getIndexes(GetIndexesRequest request
);
93 * Gets the indexes specified in the request built from the {@code builder}.
95 * @param builder a builder to be used to construct a {@link GetIndexesRequest}
96 * specifying which indexes to get
97 * @return a {@link GetResponse}{@code <Index>} containing a list of existing indexes
99 public GetResponse
<Index
> getIndexes(GetIndexesRequest
.Builder builder
);
102 * Gets the indexes requested asynchronously.
104 * @param request a request specifying which indexes to get
105 * @return a {@link Future} that will allow getting a
106 * {@link GetResponse}{@code <Index>} containing a list of existing indexes
108 public Future
<GetResponse
<Index
>> getIndexesAsync(GetIndexesRequest request
);
111 * Gets the indexes asynchronously for those specified in the request built from
112 * the {@code builder}.
114 * @param builder a builder to be used to construct a {@link GetIndexesRequest}
115 * specifying which indexes to get
116 * @return a {@link Future} that will allow getting a
117 * {@link GetResponse}{@code <Index>} containing a list of existing indexes
119 public Future
<GetResponse
<Index
>> getIndexesAsync(GetIndexesRequest
.Builder builder
);