- Type:
string | list<string>
- Default:
[]
- Scope:
settings,search
optionalWords
parameter defines which words in the query are considered optional.
By default, all query terms must match for a record to be included in the search results.
For example, a search for phone case
only returns records where the words phone
and case
occur in the searchable attributes.
Optional words allow for query relaxation.
For example, with phone
and case
as optional words,
the same search returns records with the words phone
or case
.
Matches with all words rank higher than matches with only non-optional words.
When using optional words, Algolia performs “double querying”:
one query with all terms, and another where optional words are removed.
Results are merged and re-ranked.
Usage
- You can include multiple optional phrases or word sets.
- Each string is interpreted as a set of optional words. Don’t separate words with commas.
- This feature increases the response size.
- There isn’t a hard limit on the number of words,
but using too many can slow down
getSettings
and the Algolia dashboard.
Long queries
If the query contains four or more optional words, the required number of matched words in a record increases for every 1,000 records:-
If
optionalWords
has up to 10 words, the required number of matched words increases by 1. -
If
optionalWords
has 10 or more words, the required number of matching words is based on the number of optional words divided by 5 (rounded down). For example:- For the first 1,000 results, 1 matched word is required.
- For the next 1,000 results, 4 matched words are needed (the initial 1, plus the calculated increase of 3).
Comparison with removeWordsIfNoResults
Use removeWordsIfNoResults
when you want optional behavior only if no results are found.
This is more adaptive for unpredictable, user-generated queries.
Comparison with stop words
Stop word removal always ignores common words (words that add no value to a search query, such as “the”, “on”, and “it”)Examples
Current API clients
Current API clients