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:

  1. ignorePlurals, which treats both the singular and plural of a word as a zero typo match.
  2. 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 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:

  1. Go to your dashboard and select your index from the Indices tab.
  2. Click on the Configuration tab, then the Language subsection.
  3. 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.
  4. Don’t forget to save your changes.

Did you find this page helpful?