Class Query (2.0.0)

public class Query

A query to search an index for documents which match, restricting the document fields returned to those given, and scoring and sorting the results, whilst supporting pagination.

For example, the following query will search for documents where the tokens 'good' and 'story' occur in some fields, returns up to 20 results including the fields 'author' and 'date-sent' as well as snippeted fields 'subject' and 'body'. The results are sorted by 'author' in descending order, getting the next 20 results from the responseCursor in the previously returned results, giving back a single cursor in the Results to get the next batch of results after this.


 QueryOptions options = QueryOptions.newBuilder()
     .setLimit(20)
     .setFieldsToSnippet("subject", "body")
     .setScorer(CustomScorer.newBuilder()
         .addSortExpression(SortExpression.newBuilder()
             .setExpression("author")
             .setDirection(SortDirection.DESCENDING)
             .setDefaultValue("")))
     .setCursor(responseCursor)
     .build();
 Query query = Query.newBuilder()
     .setOptions(options)
     .build("good story");
 
 

The following query will return facet information with the query result:

Query query = Query.newBuilder() .setOptions(options) .setEnableFacetDiscovery(true) .build("tablet");

To customize returned facet or refine the result using a previously returned FacetResultValue#getRefinementToken:

Query query = Query.newBuilder() .setOptions(options) .setEnableFacetDiscovery(true) .setFacetOptions(FacetOptions.newBuilder().setDiscoveryLimit(5).build()) .addReturnFacet("shipping") .addReturnFacet(FacetRequest.newBuilder().setName("department") .addValueConstraint("Computers") .addValueConstraint("Electronics") .build()) .addRefinementToken(refinementToken1) .addRefinementToken(refinementToken2) .build("tablet");

Inheritance

java.lang.Object > Query

Static Methods

newBuilder()

public static Query.Builder newBuilder()

Creates and returns a Query builder. Set the query parameters and use the Builder#build() method to create a concrete instance of Query.

Returns
Type Description
Query.Builder

a Builder which can construct a query

newBuilder(Query query)

public static Query.Builder newBuilder(Query query)

Creates a builder from the given query.

Parameter
Name Description
query Query

the query for the builder to use to build another query

Returns
Type Description
Query.Builder

a new builder with values based on the given request

Constructors

Query(Query.Builder builder)

protected Query(Query.Builder builder)

Creates a query from the builder.

Parameter
Name Description
builder Query.Builder

the query builder to populate with

Methods

getEnableFacetDiscovery()

public boolean getEnableFacetDiscovery()

Returns true if facet discovery is enabled.

Returns
Type Description
boolean

getFacetOptions()

public FacetOptions getFacetOptions()

Returns the FacetOptions for controlling faceted search or null if unset.

Returns
Type Description
FacetOptions

getOptions()

public QueryOptions getOptions()

Returns the QueryOptions for controlling the what is returned in the result set matching the query

Returns
Type Description
QueryOptions

getQueryString()

public String getQueryString()

The query can be as simple as a single term ("foo"), or as complex as a boolean expression, including field names ("title:hello OR body:important -october").

Returns
Type Description
String

the query

getRefinements()

public ImmutableList<FacetRefinement> getRefinements()

Returns an unmodifiable list of facet refinements for the search.

Returns
Type Description
com.google.common.collect.ImmutableList<FacetRefinement>

getReturnFacets()

public ImmutableList<FacetRequest> getReturnFacets()

Returns an unmodifiable list of requests for facets to be returned with the search results.

Returns
Type Description
com.google.common.collect.ImmutableList<FacetRequest>

toString()

public String toString()
Returns
Type Description
String
Overrides