本文整理汇总了Java中com.google.appengine.api.search.Index.search方法的典型用法代码示例。如果您正苦于以下问题:Java Index.search方法的具体用法?Java Index.search怎么用?Java Index.search使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.appengine.api.search.Index
的用法示例。
在下文中一共展示了Index.search方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSearchServiceConfig
import com.google.appengine.api.search.Index; //导入方法依赖的package包/类
@Test
public void testSearchServiceConfig() throws ExecutionException, InterruptedException {
String indexName = "put-index";
String docId = "testPutDocs";
searchService = SearchServiceFactory.getSearchService(SearchServiceConfig.newBuilder().setDeadline(10.).build());
Index index = createIndex(indexName, docId);
GetIndexesRequest request = GetIndexesRequest.newBuilder()
.setIndexNamePrefix(indexName)
.build();
GetResponse<Index> response = searchService.getIndexes(request);
List<Index> listIndexes = response.getResults();
for (Index oneIndex : listIndexes) {
Results<ScoredDocument> res = oneIndex.search("");
Iterator<ScoredDocument> it = res.iterator();
assertEquals(docId + "1", it.next().getId());
assertEquals(docId + "2", it.next().getId());
sync();
}
}
示例2: doSearch
import com.google.appengine.api.search.Index; //导入方法依赖的package包/类
private Results<ScoredDocument> doSearch() {
String indexName = SEARCH_INDEX;
// [START search_with_options]
try {
// Build the SortOptions with 2 sort keys
SortOptions sortOptions = SortOptions.newBuilder()
.addSortExpression(SortExpression.newBuilder()
.setExpression("price")
.setDirection(SortExpression.SortDirection.DESCENDING)
.setDefaultValueNumeric(0))
.addSortExpression(SortExpression.newBuilder()
.setExpression("brand")
.setDirection(SortExpression.SortDirection.DESCENDING)
.setDefaultValue(""))
.setLimit(1000)
.build();
// Build the QueryOptions
QueryOptions options = QueryOptions.newBuilder()
.setLimit(25)
.setFieldsToReturn("model", "price", "description")
.setSortOptions(sortOptions)
.build();
// A query string
String queryString = "product: coffee roaster AND price < 500";
// Build the Query and run the search
Query query = Query.newBuilder().setOptions(options).build(queryString);
IndexSpec indexSpec = IndexSpec.newBuilder().setName(indexName).build();
Index index = SearchServiceFactory.getSearchService().getIndex(indexSpec);
Results<ScoredDocument> result = index.search(query);
return result;
} catch (SearchException e) {
// handle exception...
}
// [END search_with_options]
return null;
}
示例3: searchDocs
import com.google.appengine.api.search.Index; //导入方法依赖的package包/类
protected Results<ScoredDocument> searchDocs(Index index, String query, int limit) {
if (limit > 0) {
QueryOptions.Builder optionBuilder = QueryOptions.newBuilder();
optionBuilder.setLimit(limit);
Query.Builder queryBuilder = Query.newBuilder().setOptions(optionBuilder.build());
return index.search(queryBuilder.build(query));
} else {
return index.search(query);
}
}
示例4: doSearch
import com.google.appengine.api.search.Index; //导入方法依赖的package包/类
private Results<ScoredDocument> doSearch() {
String indexName = SEARCH_INDEX;
// [START search_with_options]
try {
// Build the SortOptions with 2 sort keys
SortOptions sortOptions =
SortOptions.newBuilder()
.addSortExpression(
SortExpression.newBuilder()
.setExpression("price")
.setDirection(SortExpression.SortDirection.DESCENDING)
.setDefaultValueNumeric(0))
.addSortExpression(
SortExpression.newBuilder()
.setExpression("brand")
.setDirection(SortExpression.SortDirection.DESCENDING)
.setDefaultValue(""))
.setLimit(1000)
.build();
// Build the QueryOptions
QueryOptions options =
QueryOptions.newBuilder()
.setLimit(25)
.setFieldsToReturn("model", "price", "description")
.setSortOptions(sortOptions)
.build();
// A query string
String queryString = "product: coffee roaster AND price < 500";
// Build the Query and run the search
Query query = Query.newBuilder().setOptions(options).build(queryString);
IndexSpec indexSpec = IndexSpec.newBuilder().setName(indexName).build();
Index index = SearchServiceFactory.getSearchService().getIndex(indexSpec);
Results<ScoredDocument> result = index.search(query);
return result;
} catch (SearchException e) {
// handle exception...
}
// [END search_with_options]
return null;
}