public class Query extends AbstractQuery
Describes all parameters of a search query.
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.TypoTolerance |
AbstractQuery.LatLng| Modifier and Type | Field and Description |
|---|---|
static int |
RADIUS_ALL |
| Constructor and Description |
|---|
Query()
Construct an empty query.
|
Query(Query other)
Clone an existing query.
|
Query(String query)
Construct a query with the specified query text.
|
| 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() |
String[] |
getDisableExactOnAttributes() |
String[] |
getDisableTypoToleranceOnAttributes() |
Integer |
getDistinct() |
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[] |
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 |
getSnippetEllipsisText() |
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(String... attributes)
Specify the list of attribute names to highlight.
|
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 |
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 |
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 |
setOptionalWords(String... words)
Set the 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(String 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 |
setSnippetEllipsisText(String snippetEllipsisText)
Specify the string that is used as an ellipsis indicator when a snippet is truncated (defaults to the empty string).
|
Query |
setSynonyms(Boolean enabled) |
Query |
setTagFilters(JSONArray tagFilters) |
Query |
setTypoTolerance(Query.TypoTolerance type) |
build, equals, get, hashCode, parseLatLng, toStringpublic static final int RADIUS_ALL
public Query()
Construct an empty query.
public Query(String query)
Construct a query with the specified query text.
query - Query text.public Query(@NonNull
Query other)
Clone an existing query.
other - The query to be cloned.@NonNull public Query setAdvancedSyntax(Boolean enabled)
Enable the advanced query syntax. Defaults to false. - Phrase query: a phrase query defines a particular sequence of terms. A phrase query is build by Algolia’s query parser for words surrounded by “. For example, ”search engine" will retrieve records having search next to engine only. Typo-tolerance is disabled on phrase queries. - Prohibit operator: The prohibit operator excludes records that contain the term after the - symbol. For example search -engine will retrieve records containing search but not engine.
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 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)
Search for entries around a given latitude/longitude.
@Nullable public AbstractQuery.LatLng getAroundLatLng()
@NonNull public Query setAroundLatLngViaIP(Boolean enabled)
Search for entries around the latitude/longitude of user (using IP geolocation)
public Boolean getAroundLatLngViaIP()
@NonNull public Query setAroundPrecision(Integer precision)
Change the radius or around latitude/longitude query
public Integer getAroundPrecision()
@NonNull public Query setAroundRadius(Integer radius)
Change the radius for around latitude/longitude queries.
radius - the radius to set, or Query.RADIUS_ALL to disable stopping at a specific radius.public Integer getAroundRadius()
Get the current radius for around latitude/longitude queries.
@NonNull public Query setAttributesToHighlight(String... attributes)
Specify the list of attribute names to highlight. By default indexed attributes are highlighted.
public String[] getAttributesToHighlight()
@NonNull public Query setAttributesToRetrieve(String... attributes)
Specify the list of attribute names to retrieve. By default all attributes are retrieved.
public String[] getAttributesToRetrieve()
@NonNull public Query setAttributesToSnippet(String... attributes)
Specify the list of attribute names to Snippet alongside the number of words to return (syntax is ‘attributeName:nbWords’). By default no snippet is computed.
public String[] getAttributesToSnippet()
@NonNull public 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).
public String[] getDisableExactOnAttributes()
@NonNull public Query setDisableTypoToleranceOnAttributes(String... attributes)
List of attributes on which you want to disable typo tolerance (must be a subset of the searchableAttributes index setting).
public String[] getDisableTypoToleranceOnAttributes()
@NonNull public 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.
nbHitsToKeep - Specify the maximum number of hits to keep for each distinct valuepublic Integer getDistinct()
@NonNull public Query setFacets(String... facets)
List of object attributes that you want to use for faceting. Only attributes that have been added in attributesForFaceting index setting can be used in this parameter. You can also use * to perform faceting on all attributes specified in attributesForFaceting.
public String[] getFacets()
@NonNull public Query setFacetFilters(JSONArray filters)
setFilters(String) instead.Set the deprecated facetFilters parameter.
@Nullable public JSONArray getFacetFilters()
getFilters() instead.Get the value of deprecated facetFilters parameter.
@Nullable public Boolean getFacetingAfterDistinct()
@NonNull public Query setFacetingAfterDistinct(Boolean enabled)
Force faceting to be applied after de-duplication. Please check documentation for consequences and limitations
enabled - if true, facets will be computed after de-duplication is applied.@NonNull public Query setFilters(String filters)
Filter the query with numeric, facet or/and tag 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()
Get the numeric, facet or/and tag filters for this Query.
@NonNull public Query setGetRankingInfo(Boolean enabled)
if set, the result hits will contain ranking information in _rankingInfo attribute.
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)
Set the number of hits per page. Defaults to 10.
public Integer getHitsPerPage()
@NonNull public 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). Defaults to false.
@NonNull public Query setIgnorePlurals(@Nullable 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). If empty or null, this disables the feature.
@NonNull public Query setIgnorePlurals(@Nullable 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). If empty or null, this disables the feature.
@NonNull public Query.IgnorePlurals getIgnorePlurals()
@NonNull public Query setInsideBoundingBox(@Nullable Query.GeoRect... boxes)
Search for entries inside one area or the union of several areas defined by the two extreme points of a rectangle.
@Nullable public Query.GeoRect[] getInsideBoundingBox()
@NonNull public Query setInsidePolygon(@Nullable AbstractQuery.LatLng... points)
Search for entries inside a given area defined by the points of a polygon.
@NonNull public Query setInsidePolygon(@Nullable Query.Polygon... polygons)
Search for entries inside a given area defined by several polygons.
@Nullable public Query.Polygon[] getInsidePolygon()
@NonNull public Query setLength(Integer n)
Maximum number of hits to return.
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)
Limit the number of facet values returned for each facet.
public Integer getMaxFacetHits()
@NonNull public Query setMaxValuesPerFacet(Integer n)
Limit the number of facet values returned for each facet.
public Integer getMaxValuesPerFacet()
@NonNull public Query setMinimumAroundRadius(Integer minimumAroundRadius)
Specify the minimum number of characters in a query word to accept one typo in this word. Defaults to 3.
public Integer getMinimumAroundRadius()
@NonNull public Query setMinProximity(Integer nbChars)
Specify the minimum number of characters in a query word to accept one typo in this word. Defaults to 3.
public Integer getMinProximity()
@NonNull public Query setMinWordSizefor1Typo(Integer nbChars)
Specify the minimum number of characters in a query word to accept one typo in this word. Defaults to 3.
public Integer getMinWordSizefor1Typo()
@NonNull public Query setMinWordSizefor2Typos(Integer nbChars)
Specify the minimum number of characters in a query word to accept one typo in this word. Defaults to 3.
public Integer getMinWordSizefor2Typos()
@NonNull public Query setNumericFilters(JSONArray filters)
setFilters(String) instead.Set the deprecated numericFilters parameter.
@Nullable public JSONArray getNumericFilters()
getFilters() instead.Get the value of deprecated facetFilters parameter.
@NonNull public Query setOffset(int offset)
Set the offset of the first hit to return (zero-based). In most cases, page/hitsPerPage is the recommended method for pagination.
offset - a zero-based offset.public Integer getOffset()
@NonNull public Query setOptionalWords(String... words)
Set the list of words that should be considered as optional when found in the query.
words - The list of optional words, comma separated.public String[] getOptionalWords()
@NonNull public Query setPage(Integer page)
Set the page to retrieve (zero base). Defaults to 0.
public Integer getPage()
@NonNull public Query setPercentileComputation(boolean enabled)
Whether to include the query in processing time percentile computation.
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(String query)
Set the full text query
@Nullable public String getQuery()
@NonNull public Query setQueryType(@Nullable Query.QueryType type)
Select how the query words are interpreted:
@Nullable public Query.QueryType getQueryType()
@NonNull public Query setRemoveStopWords(Object removeStopWords) throws AlgoliaException
Enable the removal of stop words, disabled by default. In most use-cases, we don’t recommend enabling this option.
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)
Select the strategy to adopt when a query does not return any result.
@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)
Restricts arrays in highlight and snippet results to items that matched the query.
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)
List of object attributes you want to use for textual search (must be a subset of the searchableAttributes index setting). Attributes are separated with a comma (for example @“name,address”). You can also use a JSON string array encoding (for example encodeURIComponent(“["name","address"]”)). By default, all attributes specified in searchableAttributes settings are used to search.
public String[] getRestrictSearchableAttributes()
@NonNull public Query setSnippetEllipsisText(String snippetEllipsisText)
Specify the string that is used as an ellipsis indicator when a snippet is truncated (defaults to the empty string).
@Nullable public String getSnippetEllipsisText()
@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 setAlternativesAsExact(@Nullable Query.AlternativesAsExact[] types)
@Nullable public Query.AlternativesAsExact[] getAlternativesAsExact()
@NonNull public Query setResponseFields(String... attributes)
Choose which fields the response will contain. Applies to search and browse queries.
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()
Get the fields the response will contain. If unspecified, all fields are returned.
@NonNull public Query set(@NonNull String name, @Nullable Object value)
Set a parameter in an untyped fashion. This low-level accessor is intended to access parameters that this client does not yet support.
set in class AbstractQueryname - 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.