🎉 Try the public beta of the new docs site at algolia.com/doc-beta! 🎉
Guides / Managing results / Optimize search results / Handling natural languages

Algolia’s search engine supports all writing systems and many languages, including symbol-based languages such as Chinese and Japanese. Algolia also handles multiple languages on the same website/app, meaning some users could search in French and some in English, using the same Algolia account.

The purpose of this guide is to explain how to organize your indices to enable multi-language search.

Depending on your use case, you can use either one index for each language or one for all languages. The following questions can help you decide which approach is best for your use case:

  • Use multiple indices, one for each language, if:

    • You need a custom ranking per language/country. For example, you want to sort by price, and there are different pricing structures in different countries.
    • You want to support many languages.
  • Use one index for all languages, if:

    • You want to support querying in multiple languages. For example, an Arabic-speaking user might use Arabic text for some words and the Roman alphabet for brand names.

One index per language

This approach simplifies:

In this solution, you create one index per language:

1
2
3
4
5
6
[
  {
    "objectID": 1,
    "title": "The Wolf of Wall Street"
  }
]
1
2
3
4
5
6
[
  {
    "objectID": 1,
    "title": "Le loup de Wall Street"
  }
]
1
2
3
4
5
6
[
  {
    "objectID": 1,
    "title": "El lobo de Wall Street"
  }
]

Once your records are in different indices, you can select which index to target from the frontend.

One index for all records

Before deciding on this approach, find out if all the text you require from your list of supported languages will exceed Algolia’s record size limits. If they do exceed the limit, use one index per language.

In this solution, you create one index for all languages. Your records contain text for each language and look like this:

1
2
3
4
5
6
7
8
[
  {
    "objectID": 1,
    "title_eng": "The Wolf of Wall Street",
    "title_fr": "Le Loup de Wall Street",
    "title_es": "El lobo de Wall Street"
  }
]

You now need to set the searchable attributes for all languages using searchableAttributes.

1
2
3
4
5
$client->initIndex("movies")->setSettings(array(
  "searchableAttributes" => array(
    "title_eng", "title_fr", "title_es"
  )
));

Then at query time you must specify which attributes you want to be searchable, depending on the user’s language. Here’s how to do this with the JavaScript API client:

1
2
3
4
5
6
// search only in the French titles
index.search('wolf', {
  'restrictSearchableAttributes': 'title_fr'
}).then(({ hits }) => {
  console.log(hits);
});
Did you find this page helpful?