Search in sources :

Example 1 with Query

use of com.google.appengine.api.search.Query in project pratilipi by Pratilipi.

the class SearchAccessorGaeImpl method search.

// Helper Methods
public Results<ScoredDocument> search(String searchQuery, SortOptions sortOptions, String cursorStr, Integer offset, Integer resultCount, String... fieldsToReturn) {
    if (sortOptions == null) {
        SortOptions.Builder sortOptionsBuilder = SortOptions.newBuilder();
        sortOptionsBuilder.setMatchScorer(MatchScorer.newBuilder());
        sortOptionsBuilder.addSortExpression(SortExpression.newBuilder().setExpression(SortExpression.SCORE_FIELD_NAME).setDirection(SortExpression.SortDirection.DESCENDING).setDefaultValueNumeric(0.0));
        // Max allowed: 10000
        sortOptions = sortOptionsBuilder.setLimit(1000).build();
    }
    QueryOptions.Builder queryOptionsBuilder = QueryOptions.newBuilder().setSortOptions(sortOptions).setLimit(resultCount == null ? 1000 : resultCount).setNumberFoundAccuracy(// Max allowed: 10000
    1000).setFieldsToReturn(fieldsToReturn);
    if (cursorStr != null && !cursorStr.trim().isEmpty())
        queryOptionsBuilder.setCursor(Cursor.newBuilder().build(cursorStr));
    else if (offset != null && offset > 0)
        queryOptionsBuilder.setOffset(offset);
    else
        // Without this, query will not return a cursor.
        queryOptionsBuilder.setCursor(Cursor.newBuilder());
    Query query = Query.newBuilder().setOptions(queryOptionsBuilder).build(searchQuery);
    logger.log(Level.INFO, "Search Query: " + query.toString());
    return searchIndex.search(query);
}
Also used : Query(com.google.appengine.api.search.Query) QueryOptions(com.google.appengine.api.search.QueryOptions) SortOptions(com.google.appengine.api.search.SortOptions)

Aggregations

Query (com.google.appengine.api.search.Query)1 QueryOptions (com.google.appengine.api.search.QueryOptions)1 SortOptions (com.google.appengine.api.search.SortOptions)1