Guides / Managing results / Optimize search results / Handling natural languages

Set an index's query language

Most of Algolia’s textual matching is language agnostic, meaning 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 vital 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.

Two parameters rely on query language:

  • ignorePlurals, which treats the singular and plural forms of a word as equivalent (they match even if they’re spelled differently).
  • removeStopWords, which prevents stop words from being processed as a part of the query. English stop words include “the”, “a”, “an”, “and”. Use queryLanguages to set the languages that these parameters use to determine stop words or plurals.

You should always set queryLanguages and indexLanguages for your indices. If you don’t, the engine uses either the default (all supported languages) or the list of languages specified in ignorePlurals and removeStopWords. This can lead to unexpected search results.

Using the API

To set an index’s language through the API, use the setSettings method.

In the following example, queryLanguages is set to English and ignorePlurals is set to true. This means “mice” and “mouse” are treated as equal.

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. Select the Search product icon on your dashboard and then select your index.
  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. Likewise, you can also set ignorePlurals and removeStopWords in the Algolia dashboard.
  4. Don’t forget to save your changes.
Did you find this page helpful?