• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Query类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.google.appengine.api.search.Query的典型用法代码示例。如果您正苦于以下问题:Java Query类的具体用法?Java Query怎么用?Java Query使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Query类属于com.google.appengine.api.search包,在下文中一共展示了Query类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: testSearchAsyncQuery

import com.google.appengine.api.search.Query; //导入依赖的package包/类
@Test
public void testSearchAsyncQuery() throws ExecutionException, InterruptedException {
    String indexName = "put-index";
    String docId = "testPutDocs";
    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) {
        QueryOptions.Builder optionBuilder = QueryOptions.newBuilder();
        optionBuilder.setLimit(10);
        Query.Builder queryBuilder = Query.newBuilder().setOptions(optionBuilder.build());
        Future<Results<ScoredDocument>> Fres = oneIndex.searchAsync(queryBuilder.build(""));

        Iterator<ScoredDocument> it = Fres.get().iterator();
        assertEquals(docId + "1", it.next().getId());
        assertEquals(docId + "2", it.next().getId());
        sync();
    }
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:25,代码来源:SearchServiceTest.java


示例2: doSearch

import com.google.appengine.api.search.Query; //导入依赖的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.Query; //导入依赖的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: testSortOptions

import com.google.appengine.api.search.Query; //导入依赖的package包/类
@Test
public void testSortOptions() {
    for (SortExpression.SortDirection direction : SortExpression.SortDirection.values()) {
        SortExpression sortExpression = SortExpression.newBuilder()
            .setExpression("numfield")
            .setDirection(direction)
            .setDefaultValueNumeric(9999)
            .build();
        SortOptions sortOptions = SortOptions.newBuilder()
            .addSortExpression(sortExpression)
            .build();
        QueryOptions options = QueryOptions.newBuilder()
            .setFieldsToReturn("numfield", "datefield")
            .setSortOptions(sortOptions)
            .build();
        Query.Builder queryBuilder = Query.newBuilder().setOptions(options);
        Results<ScoredDocument> results = index.search(queryBuilder.build(""));

        double pre = -9999;
        if (direction.equals(SortExpression.SortDirection.DESCENDING)) {
            pre = 9999;
        }
        for (ScoredDocument doc : results) {
            assertEquals(2, doc.getFieldNames().size());
            for (Field numField : doc.getFields("numfield")) {
                if (direction.equals(SortExpression.SortDirection.DESCENDING)) {
                    assertTrue(pre > numField.getNumber());
                } else {
                    assertTrue(pre < numField.getNumber());
                }
                pre = numField.getNumber();
            }
        }
    }
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:36,代码来源:SearchServiceTest.java


示例5: getPlaces

import com.google.appengine.api.search.Query; //导入依赖的package包/类
static List<PlaceInfo> getPlaces(GeoPt location, long distanceInMeters, int resultCount) {

    // TODO(user): Use memcache

    String geoPoint = "geopoint(" + location.getLatitude() + ", " + location.getLongitude() + ")";

    String query = "distance(place_location, " + geoPoint + ") < " + distanceInMeters;
    String locExpr = "distance(place_location, " + geoPoint + ")";

    SortExpression sortExpr = SortExpression.newBuilder()
        .setExpression(locExpr)
        .setDirection(SortExpression.SortDirection.ASCENDING)
        .setDefaultValueNumeric(distanceInMeters + 1)
        .build();
    Query searchQuery = Query.newBuilder().setOptions(QueryOptions.newBuilder()
        .setSortOptions(SortOptions.newBuilder().addSortExpression(sortExpr))).build(query);
    Results<ScoredDocument> results = getIndex().search(searchQuery);

    if (results.getNumberFound() == 0) {
      // geo-location doesn't work under dev_server
      if (environment.value() == Development) {
        // return all documents
        results = getIndex().search("value > 0");
      }
    }

    List<PlaceInfo> places = new ArrayList<PlaceInfo>();

    for (ScoredDocument document : results) {
      if (places.size() >= resultCount) {
        break;
      }

      GeoPoint p = document.getOnlyField("place_location").getGeoPoint();

      PlaceInfo place = new PlaceInfo();
      place.setplaceID(document.getOnlyField("id").getText());
      place.setName(document.getOnlyField("name").getText());
      place.setAddress(document.getOnlyField("address").getText());

      place.setLocation(new GeoPt((float) p.getLatitude(), (float) p.getLongitude()));

      // GeoPoints are not implemented on dev server and latitude and longitude are set to zero
      // But since those are doubles let's play safe
      // and use double comparison with epsilon set to 0.0001
      if (Math.abs(p.getLatitude()) <= 0.0001 && Math.abs(p.getLongitude()) <= 0.0001) {
        // set a fake distance of 5+ km
        place.setDistanceInKilometers(5 + places.size());
      } else {
        double distance = distanceInMeters / 1000;
        try {
          distance = getDistanceInKm(
              p.getLatitude(), p.getLongitude(), location.getLatitude(), location.getLongitude());
        } catch (Exception e) {
          log.warning("Exception when calculating a distance: " + e.getMessage());
        }

        place.setDistanceInKilometers(distance);
      }

      places.add(place);
    }

    return places;
  }
 
开发者ID:googlearchive,项目名称:solutions-mobile-shopping-assistant-backend-java,代码行数:66,代码来源:PlacesHelper.java


示例6: doSearch

import com.google.appengine.api.search.Query; //导入依赖的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


示例7: searchDocuments

import com.google.appengine.api.search.Query; //导入依赖的package包/类
/**
 * Searches document by the given query.
 */
public static Results<ScoredDocument> searchDocuments(String indexName, Query query) {
    return getIndex(indexName).search(query);
}
 
开发者ID:TEAMMATES,项目名称:teammates,代码行数:7,代码来源:SearchManager.java


示例8: toQuery

import com.google.appengine.api.search.Query; //导入依赖的package包/类
/**
 * Builds the {@link Query} object.
 */
public Query toQuery() {
    return Query.newBuilder().setOptions(options).build(toString());
}
 
开发者ID:TEAMMATES,项目名称:teammates,代码行数:7,代码来源:SearchQuery.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java OutputSlot类代码示例发布时间:2022-05-22
下一篇:
Java TypeReference类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap