How to Optimize Algolia Search by Language on a Docusaurus Multi-language Site
When implementing Algolia DocSearch on a multi-language (i18n) site built with Docusaurus, I faced the challenge of search results containing mixed languages. It's common for situations to arise that harm the user experience, such as English pages appearing in search results when searching in Japanese.
This article is a record from when it was written. For the continuously maintained procedure, see the technical documentation version.
This article organizes the specific setup steps as a technical memo to solve this problem and achieve an optimal search experience that syncs with the site's display language.
This article's claim that contextualSearch builds the index name (yoursite_ja / yoursite_en) from the current locale was incorrect. In reality, contextualSearch never changes indexName; it queries a single index and narrows results at query time with facetFilters such as language:<locale>. This site has since been consolidated into a single-index setup. See the update note in the technical documentation version for details.
- Filter search results to match the site's display language (Japanese/English).
- Automatically route content to language-specific Algolia indexes based on the URL path (
/or/en/). - Improve search accuracy with index settings tailored to the characteristics of each language, such as Japanese and English.
