public class Query extends AbstractQuery
There are two ways to access parameters:
1. Using the high-level, typed properties for individual parameters (recommended). 2. Using the low-level, untyped getter (`get()`) and setter (`set()`) or the subscript operator. Use this approach if the parameter you wish to set is not supported by this class.
Modifier and Type | Class and Description |
---|---|
static class |
Query.AlternativesAsExact |
static class |
Query.ExactOnSingleWordQuery |
static class |
Query.GeoRect
A rectangle in geo coordinates.
|
static class |
Query.IgnorePlurals
A value of the
ignorePlurals setting. |
static class |
Query.Polygon
A polygon in geo coordinates.
|
static class |
Query.QueryType |
static class |
Query.RemoveWordsIfNoResults |
static class |
Query.SortFacetValuesBy |
static class |
Query.TypoTolerance |
AbstractQuery.LatLng
Modifier and Type | Field and Description |
---|---|
static String |
KEY_SORT_FACET_VALUES_BY |
static int |
RADIUS_ALL |
Constructor and Description |
---|
Query()
Construct an empty query.
|
Query(CharSequence query)
Construct a query with the specified query text.
|
Query(Query other)
Clone an existing query.
|
Modifier and Type | Method and Description |
---|---|
Boolean |
getAdvancedSyntax() |
Boolean |
getAllowTyposOnNumericTokens() |
Query.AlternativesAsExact[] |
getAlternativesAsExact() |
Boolean |
getAnalytics() |
String[] |
getAnalyticsTags() |
AbstractQuery.LatLng |
getAroundLatLng() |
Boolean |
getAroundLatLngViaIP() |
Integer |
getAroundPrecision() |
Integer |
getAroundRadius()
Get the current radius for around latitude/longitude queries.
|
String[] |
getAttributesToHighlight() |
String[] |
getAttributesToRetrieve() |
String[] |
getAttributesToSnippet() |
Boolean |
getClickAnalytics() |
String[] |
getDisableExactOnAttributes() |
String[] |
getDisableTypoToleranceOnAttributes() |
Integer |
getDistinct() |
Boolean |
getEnableRules() |
Query.ExactOnSingleWordQuery |
getExactOnSingleWordQuery() |
JSONArray |
getFacetFilters()
Deprecated.
Use
getFilters() instead. |
Boolean |
getFacetingAfterDistinct() |
String[] |
getFacets() |
String |
getFilters()
Get the numeric, facet or/and tag filters for this Query.
|
Boolean |
getGetRankingInfo() |
String |
getHighlightPostTag() |
String |
getHighlightPreTag() |
Integer |
getHitsPerPage() |
Query.IgnorePlurals |
getIgnorePlurals() |
Query.GeoRect[] |
getInsideBoundingBox() |
Query.Polygon[] |
getInsidePolygon() |
Integer |
getLength() |
Integer |
getMaxFacetHits() |
Integer |
getMaxValuesPerFacet() |
Integer |
getMinimumAroundRadius() |
Integer |
getMinProximity() |
Integer |
getMinWordSizefor1Typo() |
Integer |
getMinWordSizefor2Typos() |
JSONArray |
getNumericFilters()
Deprecated.
Use
getFilters() instead. |
Integer |
getOffset() |
String[] |
getOptionalFilters() |
String[] |
getOptionalWords() |
Integer |
getPage() |
Boolean |
getPercentileComputation() |
String |
getQuery() |
Query.QueryType |
getQueryType() |
Object |
getRemoveStopWords() |
Query.RemoveWordsIfNoResults |
getRemoveWordsIfNoResults() |
Boolean |
getReplaceSynonymsInHighlight() |
String[] |
getResponseFields()
Get the fields the response will contain.
|
Boolean |
getRestrictHighlightAndSnippetArrays() |
String[] |
getRestrictSearchableAttributes() |
String[] |
getRuleContexts() |
String |
getSnippetEllipsisText() |
Query.SortFacetValuesBy |
getSortFacetValuesBy() |
Boolean |
getSumOrFiltersScores() |
Boolean |
getSynonyms() |
JSONArray |
getTagFilters() |
Query.TypoTolerance |
getTypoTolerance() |
Query |
set(String name,
Object value)
Set a parameter in an untyped fashion.
|
Query |
setAdvancedSyntax(Boolean enabled)
Enable the advanced query syntax.
|
Query |
setAllowTyposOnNumericTokens(Boolean enabled) |
Query |
setAlternativesAsExact(Query.AlternativesAsExact[] types) |
Query |
setAnalytics(Boolean enabled) |
Query |
setAnalyticsTags(String... tags) |
Query |
setAroundLatLng(AbstractQuery.LatLng location)
Search for entries around a given latitude/longitude.
|
Query |
setAroundLatLngViaIP(Boolean enabled)
Search for entries around the latitude/longitude of user (using IP
geolocation)
|
Query |
setAroundPrecision(Integer precision)
Change the radius or around latitude/longitude query
|
Query |
setAroundRadius(Integer radius)
Change the radius for around latitude/longitude queries.
|
Query |
setAttributesToHighlight(List<String> attributes)
Deprecated.
|
Query |
setAttributesToHighlight(String... attributes)
Specify the list of attribute names to highlight.
|
Query |
setAttributesToRetrieve(List<String> attributes)
Deprecated.
|
Query |
setAttributesToRetrieve(String... attributes)
Specify the list of attribute names to retrieve.
|
Query |
setAttributesToSnippet(String... attributes)
Specify the list of attribute names to Snippet alongside the number of
words to return (syntax is 'attributeName:nbWords').
|
Query |
setClickAnalytics(Boolean enabled) |
Query |
setDisableExactOnAttributes(String... attributes)
List of attributes on which you want to disable computation of the
exact ranking criterion (must be a subset of the `searchableAttributes` index setting). |
Query |
setDisableTypoToleranceOnAttributes(String... attributes)
List of attributes on which you want to disable typo tolerance (must be a subset of the `searchableAttributes` index setting).
|
Query |
setDistinct(Integer nbHitsToKeep)
This feature is similar to the distinct just before but instead of
keeping the best value per value of attributeForDistinct, it allows to
keep N values.
|
Query |
setEnableRules(Boolean enabled) |
Query |
setExactOnSingleWordQuery(Query.ExactOnSingleWordQuery type) |
Query |
setFacetFilters(JSONArray filters)
Deprecated.
Use
setFilters(String) instead. |
Query |
setFacetingAfterDistinct(Boolean enabled)
Force faceting to be applied after de-duplication.
|
Query |
setFacets(String... facets)
List of object attributes that you want to use for faceting.
|
Query |
setFilters(String filters)
Filter the query with numeric, facet or/and tag filters.
|
Query |
setGetRankingInfo(Boolean enabled)
if set, the result hits will contain ranking information in _rankingInfo
attribute.
|
Query |
setHighlightPostTag(String tag) |
Query |
setHighlightPreTag(String tag) |
Query |
setHitsPerPage(Integer nbHitsPerPage)
Set the number of hits per page.
|
Query |
setIgnorePlurals(boolean enabled)
If set to true, plural won't be considered as a typo (for example
car/cars will be considered as equals).
|
Query |
setIgnorePlurals(Collection<String> languageISOCodes)
A list of language codes for which plural won't be considered as a typo (for example
car/cars will be considered as equals).
|
Query |
setIgnorePlurals(String... languageISOCodes)
One or several language codes for which plural won't be considered as a typo (for example
car/cars will be considered as equals).
|
Query |
setInsideBoundingBox(Query.GeoRect... boxes)
Search for entries inside one area or the union of several areas
defined by the two extreme points of a rectangle.
|
Query |
setInsidePolygon(AbstractQuery.LatLng... points)
Search for entries inside a given area defined by the points of a polygon.
|
Query |
setInsidePolygon(Query.Polygon... polygons)
Search for entries inside a given area defined by several polygons.
|
Query |
setLength(Integer n)
Maximum number of hits to return.
|
Query |
setMaxFacetHits(Integer n)
Limit the number of facet values returned for each facet.
|
Query |
setMaxValuesPerFacet(Integer n)
Limit the number of facet values returned for each facet.
|
Query |
setMinimumAroundRadius(Integer minimumAroundRadius)
Specify the minimum number of characters in a query word to accept one
typo in this word.
|
Query |
setMinProximity(Integer nbChars)
Specify the minimum number of characters in a query word to accept one
typo in this word.
|
Query |
setMinWordSizefor1Typo(Integer nbChars)
Specify the minimum number of characters in a query word to accept one
typo in this word.
|
Query |
setMinWordSizefor2Typos(Integer nbChars)
Specify the minimum number of characters in a query word to accept one
typo in this word.
|
Query |
setNumericFilters(JSONArray filters)
Deprecated.
Use
setFilters(String) instead. |
Query |
setOffset(int offset)
Set the offset of the first hit to return (zero-based).
|
Query |
setOptionalFilters(String... filters)
Set a list of filters for ranking purposes, to rank higher records that contain the filter(s).
|
Query |
setOptionalWords(String... words)
Set a list of words that should be considered as optional when found in
the query.
|
Query |
setPage(Integer page)
Set the page to retrieve (zero base).
|
Query |
setPercentileComputation(boolean enabled)
Whether to include the query in processing time percentile computation.
|
Query |
setQuery(CharSequence query)
Set the full text query
|
Query |
setQueryType(Query.QueryType type)
Select how the query words are interpreted:
|
Query |
setRemoveStopWords(Object removeStopWords)
Enable the removal of stop words, disabled by default.
|
Query |
setRemoveWordsIfNoResults(Query.RemoveWordsIfNoResults type)
Select the strategy to adopt when a query does not return any result.
|
Query |
setReplaceSynonymsInHighlight(Boolean enabled) |
Query |
setResponseFields(String... attributes)
Choose which fields the response will contain.
|
Query |
setRestrictHighlightAndSnippetArrays(boolean restrict)
Restricts arrays in highlight and snippet results to items that matched the query.
|
Query |
setRestrictSearchableAttributes(String... attributes)
List of object attributes you want to use for textual search (must be a
subset of the `searchableAttributes` index setting).
|
Query |
setRuleContexts(String... ruleContexts)
Set a list of contexts for which rules are enabled.
|
Query |
setSnippetEllipsisText(String snippetEllipsisText)
Specify the string that is used as an ellipsis indicator when a snippet
is truncated (defaults to the empty string).
|
Query |
setSortFacetValuesBy(Query.SortFacetValuesBy order)
When using
setFacets(java.lang.String...) , Algolia retrieves a list of matching facet values for each faceted attribute. |
Query |
setSumOrFiltersScores(Boolean enabled) |
Query |
setSynonyms(Boolean enabled) |
Query |
setTagFilters(JSONArray tagFilters) |
Query |
setTypoTolerance(Query.TypoTolerance type) |
build, equals, get, hashCode, parseFrom, parseLatLng, toString
public static final int RADIUS_ALL
public static final String KEY_SORT_FACET_VALUES_BY
public Query()
public Query(CharSequence query)
query
- Query text.public Query(@NonNull Query other)
other
- The query to be cloned.@NonNull public Query setAdvancedSyntax(Boolean enabled)
public Boolean getAdvancedSyntax()
@NonNull public Query setAllowTyposOnNumericTokens(Boolean enabled)
enabled
- If set to false, disable typo-tolerance on numeric tokens.
Defaults to true.public Boolean getAllowTyposOnNumericTokens()
@NonNull public Query setClickAnalytics(Boolean enabled)
enabled
- If set to true, the results will return queryID which is needed for sending click | conversion events. Defaults to false.public Boolean getClickAnalytics()
@NonNull public Query setAnalytics(Boolean enabled)
enabled
- If set to false, this query will not be taken into account in
analytics feature. Defaults to true.public Boolean getAnalytics()
@NonNull public Query setAnalyticsTags(String... tags)
tags
- Set the analytics tags identifying the querypublic String[] getAnalyticsTags()
@NonNull public Query setAroundLatLng(@Nullable AbstractQuery.LatLng location)
@Nullable public AbstractQuery.LatLng getAroundLatLng()
@NonNull public Query setAroundLatLngViaIP(Boolean enabled)
public Boolean getAroundLatLngViaIP()
@NonNull public Query setAroundPrecision(Integer precision)
public Integer getAroundPrecision()
@NonNull public Query setAroundRadius(Integer radius)
radius
- the radius to set, or Query.RADIUS_ALL to disable stopping at a specific radius.public Integer getAroundRadius()
@Deprecated @NonNull public Query setAttributesToHighlight(List<String> attributes)
setAttributesToHighlight(String...)
@NonNull public Query setAttributesToHighlight(String... attributes)
public String[] getAttributesToHighlight()
@Deprecated @NonNull public Query setAttributesToRetrieve(List<String> attributes)
setAttributesToRetrieve(String...)
@NonNull public Query setAttributesToRetrieve(String... attributes)
public String[] getAttributesToRetrieve()
@NonNull public Query setAttributesToSnippet(String... attributes)
public String[] getAttributesToSnippet()
@NonNull public Query setDisableExactOnAttributes(String... attributes)
exact
ranking criterion (must be a subset of the `searchableAttributes` index setting).public String[] getDisableExactOnAttributes()
@NonNull public Query setDisableTypoToleranceOnAttributes(String... attributes)
public String[] getDisableTypoToleranceOnAttributes()
@NonNull public Query setDistinct(Integer nbHitsToKeep)
nbHitsToKeep
- Specify the maximum number of hits to keep for each distinct
valuepublic Integer getDistinct()
@NonNull public Query setFacets(String... facets)
public String[] getFacets()
@NonNull public Query setFacetFilters(JSONArray filters)
setFilters(String)
instead.facetFilters
parameter.@Nullable public JSONArray getFacetFilters()
getFilters()
instead.facetFilters
parameter.@Nullable public Boolean getFacetingAfterDistinct()
@NonNull public Query setFacetingAfterDistinct(Boolean enabled)
enabled
- if true
, facets will be computed after de-duplication is applied.@NonNull public Query setFilters(String filters)
The syntax is a SQL like syntax, you can use the OR and AND keywords. The syntax for the underlying numeric, facet and tag filters is the same than in the other filters:
available=1 AND (category:Book OR NOT category:Ebook) AND _tags:public date: 1441745506 TO 1441755506 AND inStock > 0 AND author:"John Doe"
filters
- a string following the given syntax.Query
for chaining.@Nullable public String getFilters()
@NonNull public Query setGetRankingInfo(Boolean enabled)
public Boolean getGetRankingInfo()
@NonNull public Query setHighlightPostTag(String tag)
@Nullable public String getHighlightPostTag()
@NonNull public Query setHighlightPreTag(String tag)
@Nullable public String getHighlightPreTag()
@NonNull public Query setHitsPerPage(Integer nbHitsPerPage)
public Integer getHitsPerPage()
@NonNull public Query setIgnorePlurals(boolean enabled)
@NonNull public Query setIgnorePlurals(@Nullable Collection<String> languageISOCodes)
@NonNull public Query setIgnorePlurals(@Nullable String... languageISOCodes)
@NonNull public Query.IgnorePlurals getIgnorePlurals()
@NonNull public Query setInsideBoundingBox(@Nullable Query.GeoRect... boxes)
@Nullable public Query.GeoRect[] getInsideBoundingBox()
@NonNull public Query setInsidePolygon(@Nullable AbstractQuery.LatLng... points)
@NonNull public Query setInsidePolygon(@Nullable Query.Polygon... polygons)
@Nullable public Query.Polygon[] getInsidePolygon()
@NonNull public Query setLength(Integer n)
In most cases, page
/hitsPerPage
is the recommended method for pagination.
n
- the number of hits to return. (Maximum 1000)public Integer getLength()
@NonNull public Query setMaxFacetHits(Integer n)
public Integer getMaxFacetHits()
@NonNull public Query setMaxValuesPerFacet(Integer n)
public Integer getMaxValuesPerFacet()
@NonNull public Query setMinimumAroundRadius(Integer minimumAroundRadius)
public Integer getMinimumAroundRadius()
@NonNull public Query setMinProximity(Integer nbChars)
public Integer getMinProximity()
@NonNull public Query setMinWordSizefor1Typo(Integer nbChars)
public Integer getMinWordSizefor1Typo()
@NonNull public Query setMinWordSizefor2Typos(Integer nbChars)
public Integer getMinWordSizefor2Typos()
@NonNull public Query setNumericFilters(JSONArray filters)
setFilters(String)
instead.numericFilters
parameter.@Nullable public JSONArray getNumericFilters()
getFilters()
instead.facetFilters
parameter.@NonNull public Query setOffset(int offset)
page
/hitsPerPage
is the recommended method for pagination.offset
- a zero-based offset.public Integer getOffset()
@NonNull public Query setOptionalWords(String... words)
words
- The list of optional words.public String[] getOptionalWords()
@NonNull public Query setOptionalFilters(String... filters)
filters
- The list of optional filters.public String[] getOptionalFilters()
@NonNull public Query setPage(Integer page)
public Integer getPage()
@NonNull public Query setPercentileComputation(boolean enabled)
enabled
- if true
, the API records the processing time of the search query
and includes it when computing the 90% and 99% percentiles, available in your
Algolia dashboard. When `false`, the search query is excluded from percentile computation.public Boolean getPercentileComputation()
@NonNull public Query setQuery(CharSequence query)
@Nullable public String getQuery()
@NonNull public Query setQueryType(@Nullable Query.QueryType type)
@Nullable public Query.QueryType getQueryType()
@NonNull public Query setRemoveStopWords(Object removeStopWords) throws AlgoliaException
removeStopWords
- Boolean: enable or disable all 41 supported languages,
String: comma separated list of languages you have in your record (using language iso code).AlgoliaException
@Nullable public Object getRemoveStopWords()
@NonNull public Query setRemoveWordsIfNoResults(@Nullable Query.RemoveWordsIfNoResults type)
@Nullable public Query.RemoveWordsIfNoResults getRemoveWordsIfNoResults()
@NonNull public Query setReplaceSynonymsInHighlight(Boolean enabled)
enabled
- If set to false, words matched via synonyms expansion will not be
replaced by the matched synonym in highlight result. Default
to true.public Boolean getReplaceSynonymsInHighlight()
@NonNull public Query setRestrictHighlightAndSnippetArrays(boolean restrict)
restrict
- if false
, all array items are highlighted/snippeted. When true,
only array items that matched at least partially are highlighted/snippeted.public Boolean getRestrictHighlightAndSnippetArrays()
@NonNull public Query setRestrictSearchableAttributes(String... attributes)
public String[] getRestrictSearchableAttributes()
@NonNull public Query setRuleContexts(String... ruleContexts)
Contextual rules matching any of these contexts are eligible, as well as generic rules. When empty, only generic rules are eligible.
ruleContexts
- one or several contexts.@Nullable public String[] getRuleContexts()
@NonNull public Query setSnippetEllipsisText(String snippetEllipsisText)
@Nullable public String getSnippetEllipsisText()
@NonNull public Query setSortFacetValuesBy(Query.SortFacetValuesBy order)
setFacets(java.lang.String...)
, Algolia retrieves a list of matching facet values for each faceted attribute.
This parameter controls how the facet values are sorted within each faceted attribute.order
- supported options are `count` (sort by decreasing count) and `alpha` (sort by increasing alphabetical order)public Query.SortFacetValuesBy getSortFacetValuesBy()
@NonNull public Query setSumOrFiltersScores(Boolean enabled)
enabled
- False means that the total score of a record is the maximum score of an individual filter. Setting it to true changes the total score by adding together the scores of each filter found. Defaults to false.public Boolean getSumOrFiltersScores()
@NonNull public Query setSynonyms(Boolean enabled)
enabled
- If set to false, this query will not use synonyms defined in
configuration. Defaults to true.public Boolean getSynonyms()
@NonNull public Query setTagFilters(JSONArray tagFilters)
@Nullable public JSONArray getTagFilters()
@NonNull public Query setTypoTolerance(@Nullable Query.TypoTolerance type)
@Nullable public Query.TypoTolerance getTypoTolerance()
@NonNull public Query setExactOnSingleWordQuery(@Nullable Query.ExactOnSingleWordQuery type)
@Nullable public Query.ExactOnSingleWordQuery getExactOnSingleWordQuery()
@NonNull public Query setEnableRules(Boolean enabled)
enabled
- If set to false, rules processing is disabled: no rule will match the query.
Defaults to true.public Boolean getEnableRules()
@NonNull public Query setAlternativesAsExact(@Nullable Query.AlternativesAsExact[] types)
@Nullable public Query.AlternativesAsExact[] getAlternativesAsExact()
@NonNull public Query setResponseFields(String... attributes)
By default, all fields are returned. If this parameter is specified, only the fields explicitly listed will be returned, unless * is used, in which case all fields are returned. Specifying an empty list or unknown field names is an error.
public String[] getResponseFields()
@NonNull public Query set(@NonNull String name, @Nullable Object value)
set
in class AbstractQuery
name
- The parameter's name.value
- The parameter's value, or null to remove it.
It will first be converted to a String by the `toString()` method.