Set an Index's Query Language
On this page
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 queryLanguages
parameter.
If you don’t set queryLanguages
, be careful when using ignorePlurals
and 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 setSettings
method.
In the below example, we set queryLanguages
for the english
index and set ignorePlurals
to true
. This means “mice” and “mouse” will be treated as equivalent.
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:
- Select the Search product icon on your dashboard and then select your index.
- 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.
Likewise, you can also set
ignorePlurals
andremoveStopWords
in the Algolia dashboard. - Don’t forget to save your changes.