OR
: must match any of the combined conditionsAND
: must match all the combined conditionsNOT
: negates a filter
Use of parentheses
Use parentheses(
and )
to combine several OR conditions.
These rules apply:
- Donโt group ANDs within ORs.
For example,
A OR (B AND C) OR (D AND E)
isnโt supported. - Donโt use parentheses with top-level AND combinations.
For example,
(A AND (B OR C))
isnโt supported. (ButA AND (B OR C)
is supported) - Donโt use parentheses to negate a group of expressions.
For example,
NOT (filter1 OR filter2)
isnโt supported.
Examples of valid combinations
The following examples are valid combinations of filter expressions:A AND (B OR C)
(A OR B) AND C
A AND (B OR C) AND (D OR E)
A AND B AND (C OR D) AND (E OR F)
(A OR B) AND (C OR D) AND E
Example scenarios for filter combinations
Thefilters
parameter gives precise control over search results with a SQL-like syntax.
Use the following examples to learn how to apply different filters and combine them with boolean logic.
Basic filters
Filter type | Example | Filter |
---|---|---|
Numeric comparison | Show products that cost $13 or more | price > 12.99 |
Numeric range | Show products with a price between 100 | price:5.99 TO 100 |
Facets | Show records categorized as โBookโ | category:Book |
Tag filters | Show records marked with the โpublishedโ tag | _tags:published |
Boolean filters | Show records where the isEnabled attribute is true | isEnabled:true |
Filter by date | Show records published between two dates Unix timestamps | date: 1441745506 TO 1441755506 |
Negation | Exclude discontinued products | NOT is_discontinued:true |
Combine filters
- Find books not written by a specific author:
(category:Book OR category:Ebook) AND NOT author:"JK Rowling"
- Filter products by price range and category:
price:10 TO 50 AND (category:Electronics OR category:Accessories)
- Complex filter with several conditions:
inStock:true AND (category:Phones OR category:Tablets) AND (brand:Apple OR brand:Samsung) AND price>500
Donโt mix filter types in OR conditions
You canโt compare different filter types (string, numeric, tags) with anOR
.
For example, num=3 OR tag1 OR facet:value
isnโt allowed.
Apps and user actions change filter expressions
If a user or app selects a filter, Algolia omits the filters that donโt apply from the expression. For example, if the original filter expression is((category:Electronics OR category:Home) AND NOT brand:LG) AND NOT price:100 TO 500
and the user selects the Electronics category, the expression simplifies to (category:Electronics AND NOT brand:LG) AND NOT price:100 TO 500
.