use of com.google.appengine.api.search.QueryOptions in project blogwt by billy1380.
the class SearchHelper method search.
public static String search(Collection<Long> resultsIds, String query, String indexName, String next, Integer count, String sortBy, SortDirectionType direction) {
Cursor cursor = null;
if (!SearchHelper.EMPTY_CURSOR.equals(next)) {
// build options and query
QueryOptions.Builder queryOptionsBuilder = QueryOptions.newBuilder().setCursor(next == null ? Cursor.newBuilder().build() : Cursor.newBuilder().build(next)).setLimit(count == null ? PagerHelper.DEFAULT_COUNT.intValue() : count.intValue()).setReturningIdsOnly(true);
if (sortBy != null) {
queryOptionsBuilder = 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;
if (resultsIds == null) {
resultsIds = new ArrayList<>();
} else {
resultsIds.clear();
}
for (ScoredDocument scoredDocument : matches) {
if ((id = scoredDocument.getId()) != null) {
resultsIds.add(Long.valueOf(id));
}
}
cursor = matches.getCursor();
}
return cursor == null ? SearchHelper.EMPTY_CURSOR : cursor.toWebSafeString();
}
use of com.google.appengine.api.search.QueryOptions in project blogwt by billy1380.
the class SearchHelper method search.
/**
* @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;
}
Aggregations