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

Since Algolia’s search engine is language-agnostic, it supports all languages and alphabets, 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 either use one index for each language or one index for all languages. The following questions can help you decide, which approach is best for your use case:

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 then select which index to target from the front end.

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?