本文整理汇总了Java中com.google.appengine.api.search.QueryOptions类的典型用法代码示例。如果您正苦于以下问题:Java QueryOptions类的具体用法?Java QueryOptions怎么用?Java QueryOptions使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
QueryOptions类属于com.google.appengine.api.search包,在下文中一共展示了QueryOptions类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSearchAsyncQuery
import com.google.appengine.api.search.QueryOptions; //导入依赖的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();
}
}
示例2: apply
import com.google.appengine.api.search.QueryOptions; //导入依赖的package包/类
@Override
public com.google.appengine.api.search.Query apply(Query<?> query) {
String queryString = queryStringCompiler.apply(query);
LOGGER.trace("QUERY [{}]", queryString);
QueryOptions queryOptions = queryOptionsCompiler.apply(query);
LOGGER.trace(queryOptions.toString());
return com.google.appengine.api.search.Query.newBuilder()
.setOptions(queryOptions)
.build(queryString);
}
示例3: apply
import com.google.appengine.api.search.QueryOptions; //导入依赖的package包/类
@Override
public QueryOptions apply(Query<?> query) {
final QueryOptions.Builder options = QueryOptions.newBuilder();
int offset = query.getSkip().orElse(0);
options.setOffset(offset);
query.getLimit().ifPresent(limit -> options.setLimit(limit + offset));
query.getAccuracy().ifPresent(options::setNumberFoundAccuracy);
options.setSortOptions(sortOptionsCompiler.apply(query));
options.setReturningIdsOnly(query.isIdsOnly());
return options.build();
}
示例4: doSearch
import com.google.appengine.api.search.QueryOptions; //导入依赖的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;
}
示例5: SearchQuery
import com.google.appengine.api.search.QueryOptions; //导入依赖的package包/类
protected SearchQuery(List<InstructorAttributes> instructors, String queryString) {
options = QueryOptions.newBuilder()
.setLimit(20)
.build();
visibilityQueryString = instructors == null ? "" : prepareVisibilityQueryString(instructors);
setTextFilter(Const.SearchDocumentField.SEARCHABLE_TEXT, queryString);
}
示例6: searchDocs
import com.google.appengine.api.search.QueryOptions; //导入依赖的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);
}
}
示例7: testSortOptions
import com.google.appengine.api.search.QueryOptions; //导入依赖的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();
}
}
}
}
示例8: getPlaces
import com.google.appengine.api.search.QueryOptions; //导入依赖的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
示例9: doSearch
import com.google.appengine.api.search.QueryOptions; //导入依赖的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;
}
示例10: search
import com.google.appengine.api.search.QueryOptions; //导入依赖的package包/类
/**
* @param query
* @param start
* @param count
* @param sortBy
* @param direction
* @return
*/
public static List<Long> search (String query, String indexName,
Integer start, Integer count, String sortBy,
SortDirectionType direction) {
QueryOptions.Builder queryOptionsBuilder = QueryOptions.newBuilder()
.setOffset(start == null ? PagerHelper.DEFAULT_START.intValue()
: start.intValue())
.setLimit(count == null ? PagerHelper.DEFAULT_COUNT.intValue()
: count.intValue())
.setReturningIdsOnly(true);
if (sortBy != null) {
queryOptionsBuilder
.setSortOptions(SortOptions.newBuilder()
.addSortExpression(SortExpression.newBuilder()
.setExpression(sortBy)
.setDirection(direction == null
|| direction == SortDirectionType.SortDirectionTypeDescending
? SortExpression.SortDirection.DESCENDING
: SortExpression.SortDirection.ASCENDING))
.setLimit(SearchHelper.SORT_LIMIT).build());
}
QueryOptions options = queryOptionsBuilder.build();
com.google.appengine.api.search.Query apiQuery = com.google.appengine.api.search.Query
.newBuilder().setOptions(options).build(query);
Results<ScoredDocument> matches = SearchHelper.getIndex(indexName)
.search(apiQuery);
String id;
List<Long> ids = new ArrayList<Long>();
for (ScoredDocument scoredDocument : matches) {
if ((id = scoredDocument.getId()) != null) {
ids.add(Long.valueOf(id));
}
}
return ids;
}