Class Query
- java.lang.Object
-
- com.google.appengine.api.search.Query
-
public class Query extends java.lang.ObjectA 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
Resultsto get the next batch of results after this. The following query will return facet information with the query result: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"); To customize returned facet or refine the result using a previously returnedQuery query = Query.newBuilder() .setOptions(options) .setEnableFacetDiscovery(true) .build("tablet");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");
-
-
Nested Class Summary
Nested Classes Modifier and Type Class and Description static classQuery.BuilderA builder which constructs Query objects.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description booleangetEnableFacetDiscovery()Returns true if facet discovery is enabled.FacetOptionsgetFacetOptions()Returns theFacetOptionsfor controlling faceted search or null if unset.QueryOptionsgetOptions()Returns theQueryOptionsfor controlling the what is returned in the result set matching the queryjava.lang.StringgetQueryString()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.BuildernewBuilder()Creates and returns aQuerybuilder.static Query.BuildernewBuilder(Query query)Creates a builder from the given query.java.lang.StringtoString()
-
-
-
Method Detail
-
getQueryString
public 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").- Returns:
- the query
-
getOptions
public QueryOptions getOptions()
Returns theQueryOptionsfor controlling the what is returned in the result set matching the query
-
getFacetOptions
public FacetOptions getFacetOptions()
Returns theFacetOptionsfor controlling faceted search or null if unset.
-
getEnableFacetDiscovery
public boolean getEnableFacetDiscovery()
Returns true if facet discovery is enabled.
-
getReturnFacets
public <any> getReturnFacets()
Returns an unmodifiable list of requests for facets to be returned with the search results.
-
getRefinements
public <any> getRefinements()
Returns an unmodifiable list of facet refinements for the search.
-
newBuilder
public static Query.Builder newBuilder()
Creates and returns aQuerybuilder. Set the query parameters and use theQuery.Builder.build()method to create a concrete instance of Query.- Returns:
- a
Query.Builderwhich can construct a query
-
newBuilder
public static Query.Builder newBuilder(Query query)
Creates a builder from the given query.- Parameters:
query- the query for the builder to use to build another query- Returns:
- a new builder with values based on the given request
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-