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.

Set the index language in the dashboard

  1. Go to the Algolia dashboard and select your Algolia application.
  2. On the left sidebar, select Search.
  3. Select your Algolia index:

    Select your Algolia application and index

  4. On the Configuration tab, click Language.
  5. 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.
  6. Save your changes.

Set the index language with 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
]);
Did you find this page helpful?