Repository navigation
Searching for multiple languages at the same time #984
Replies: 1 comment
|
Pagefind intentionally creates and loads separate indexes by the page's <html lang> attribute. There are two workable approaches depending on whether you want language-aware ranking or one combined result set. Simplest: build one combined index. Set a forced language when indexing: This opts out of automatic multilingual splitting, so both Chinese and English pages are searched together. The trade-off is that every record uses one index language; that can reduce language-specific stemming/segmentation quality. If Chinese search quality matters more, use force_language: zh (and the extended Pagefind build, which npx pagefind uses by default). Keep separate language indexes and merge them in the browser. Build/serve the second language as a separate Pagefind bundle path, then select that language while merging it: Use the actual language keys emitted by your builds (for example zh / en). The additional index must have a different bundle URL; calling mergeIndex on the primary bundle's own path is deliberately skipped. Pagefind documents the language option here: Merging a specific language index. Be aware that merged indexes are searched with the primary instance's WebAssembly language module, so this preserves separate records but does not give each result set an independent analyzer. If language-specific processing is essential, run two independent Pagefind instances and merge/rank their result arrays in your application instead. If your site's lang attribute changes dynamically, remember that Pagefind chooses the primary language when the JS instance initializes. Recreate/configure the instance after a language switch, or deliberately use the merged/forced-language setup. The default behavior is documented in Multilingual search. |
Uh oh!
There was an error while loading. Please reload this page.
I am adding Pagefind to my blog to help visitors find content more easily. However, my blog has a mix of Chinese and English content (yes I dynamically switch the lang attribute on html), while Pagefind only looks for results under the same language. This may make the result seem incomplete.
Is there any workaround for this? Or is it simply not Pagefind designed for?
All reactions