numericFilters
'numericFilters' => [ 'numeric_attribute [= | != | > | >= | < | <=](#numeric-comparisons) numeric_value', 'attribute:lower_value TO higher_value', ... ]
Can be used in these methods:
search,
browseObjects,
deleteBy,
searchForFacetValues,
generateSecuredApiKey,
addApiKey,
updateApiKey
search,
browse_objects,
delete_by,
search_for_facet_values,
generate_secured_api_key,
add_api_key,
update_api_key
search,
browseObjects,
deleteBy,
searchForFacetValues,
generateSecuredApiKey,
addApiKey,
updateApiKey
search,
browse_objects,
delete_by,
search_for_facet_values,
generate_secured_api_key,
add_api_key,
update_api_key
search,
browse,
deleteBy,
searchForFacetValues,
generateSecuredApiKey,
addAPIKey,
updateAPIKey
search,
browseObjects,
deleteObjectBy,
searchForFacetValues,
generateSecuredApiKey,
addApiKey,
updateApiKey
Search,
Browse,
DeleteBy,
SearchForFacetValues,
GenerateSecuredApiKey,
AddApiKey,
UpdateApiKey
Search,
browse,
deleteBy,
searchForFacetValues,
generateSecuredApiKey,
addApiKey,
updateApiKey
Search,
BrowseObjects,
DeleteBy,
SearchForFacetValues,
GenerateSecuredAPIKey,
AddAPIKey,
UpdateAPIKey
search,
browse index,
delete by,
search into facet values,
generateSecuredApiKey,
add key,
update key
About this parameter
Filter on numeric attributes.
In most cases, use the filters
parameter instead of numericFilters
since filters
has a more straightforward, SQL-like syntax and supports both filters and facets. However, sometimes you may want to combine filters
and numericFilters
in the same search.
Numeric comparisons
- Format:
${attributeName} ${operator} ${operand}
- Example:
inStock = 1
.
These operatores are supported: <
, <=
, =
, !=
, >=
, and >
.
Numeric range
- Format:
${attributeName}:${lowerBound} TO ${upperBound}
- Example:
price:5.99 TO 100
${lowerBound}
and ${upperBound}
must be numeric.
Both bounds are included in the range.
Combining filters
and numericFilters
As for facetFilters
, you can also combine filters
and numericFilters
.
For example:
1
2
3
4
index.search('',{
filters:'("county:Maricopa" OR "county:Pima")',
numericFilters:["employees > 500"]
});
Which is the equivalent of saying “List all organizations with more than 500 employees in Maricopa OR Pima county”
Usage notes
- No boolean operators: you can’t use boolean operators like AND and OR.
- Multiple filters: if you specify multiple filters, they’re interpreted as a conjunction (AND). If you want to use a disjunction (OR), use a nested array.
- Supported values: you can use positive or negative numbers with an absolute value of up to
4611686018427387
. - Precision limit: numeric filters support up to the third decimal point. Digits after the fourth decimal point are lost when filtering.
Examples
Apply numeric filters on a search query
1
2
3
4
5
6
7
8
9
$results = $index->search('query', [
'numericFilters' => [
[
"inStock = 1",
"deliveryDate < 1441755506"
],
"price < 1000"
]
]);
[["inStock = 1", "deliveryDate < 1441755506"], "price < 1000"]
translates as(inStock = 1 OR deliveryDate < 1441755506) AND price < 1000