public class Query
extends java.lang.Object
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");
Modifier and Type | Class and Description |
---|---|
static class |
Query.Builder
A builder which constructs Query objects.
|
Modifier and Type | Method and Description |
---|---|
boolean |
getEnableFacetDiscovery()
Returns true if facet discovery is enabled.
|
FacetOptions |
getFacetOptions()
Returns the
FacetOptions for controlling faceted search or null if unset. |
QueryOptions |
getOptions()
Returns the
QueryOptions for controlling the what is returned
in the result set matching the query |
java.lang.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").
|
<any> |
getRefinements()
Returns an unmodifiable list of facet refinements for the search.
|
<any> |
getReturnFacets()
Returns an unmodifiable list of requests for facets to be returned with the search results.
|
static Query.Builder |
newBuilder()
Creates and returns a
Query builder. |
static Query.Builder |
newBuilder(Query query)
Creates a builder from the given query.
|
java.lang.String |
toString() |
public java.lang.String getQueryString()
public QueryOptions getOptions()
QueryOptions
for controlling the what is returned
in the result set matching the querypublic FacetOptions getFacetOptions()
FacetOptions
for controlling faceted search or null if unset.public boolean getEnableFacetDiscovery()
public <any> getReturnFacets()
public <any> getRefinements()
public static Query.Builder newBuilder()
Query
builder. Set the query
parameters and use the Query.Builder.build()
method to create a concrete
instance of Query.Query.Builder
which can construct a querypublic static Query.Builder newBuilder(Query query)
query
- the query for the builder to use to build another querypublic java.lang.String toString()
toString
in class java.lang.Object