当前位置: 首页>>代码示例>>Java>>正文


Java Index.search方法代码示例

本文整理汇总了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();
    }
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:24,代码来源:SearchServiceTest.java

示例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;
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:40,代码来源:SearchOptionServlet.java

示例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);
    }
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:11,代码来源:SearchTestBase.java

示例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;
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:44,代码来源:SearchOptionServlet.java


注:本文中的com.google.appengine.api.search.Index.search方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。