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
TypeDescription
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
NameDescription
queryQuery

the query for the builder to use to build another query

Returns
TypeDescription
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
NameDescription
builderQuery.Builder

the query builder to populate with

Methods

getEnableFacetDiscovery()

public boolean getEnableFacetDiscovery()

Returns true if facet discovery is enabled.

Returns
TypeDescription
boolean

getFacetOptions()

public FacetOptions getFacetOptions()

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

Returns
TypeDescription
FacetOptions

getOptions()

public QueryOptions getOptions()

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

Returns
TypeDescription
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
TypeDescription
String

the query

getRefinements()

public ImmutableList<FacetRefinement> getRefinements()

Returns an unmodifiable list of facet refinements for the search.

Returns
TypeDescription
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
TypeDescription
com.google.common.collect.ImmutableList<FacetRequest>

toString()

public String toString()
Returns
TypeDescription
String
Overrides