Set an Index's Query Language
Most of Algolia’s textual matching is language agnostic: this means the matching and ranking processes are the same for every language. If a search textually matches a record, that record is returned. This approach ensures that Algolia works for any language without any extra customization.
However, there are circumstances where knowledge of the query language is important for accurate search. For example, by identifying your query language, you can treat plurals and singulars as equivalent. If your users search for “mice”, you most likely don’t want to treat the singular “mouse” as a typo.
Algolia has two main parameters that rely on query language:
ignorePlurals, which treats both the singular and plural of a word as a zero typo match.
removeStopWords, which prevents stop words from being processed as a part of the query. English stop words include “the”, “a”, “an”, “and”.
The language(s) that these parameters use (to determine stop words or plurals) can be set independently, or through the
If you don’t set
queryLanguages, be careful when using
removeStopWords. In this circumstance, setting either of these to
true without passing a language causes Algolia to ignores plurals or removes stop words for every language. This can lead to strange or inaccurate search results.
Using the API
To set an index’s language through the API, you need to use the
1 2 3 4 $index->setSettings([ 'queryLanguages' => ['en'], 'ignorePlurals' => true ]);
Using the Dashboard
You can also set an index’s query language in your Algolia dashboard:
- Go to your dashboard and select your index from the Indices tab.
- Click on the Configuration tab, then the Language subsection.
- Click Select one or more languages under the Query Languages section, and enter your desired language. You can enter as many languages as you want.
- Don’t forget to save your changes.