cmfcmf / docusaurus-search-local

Offline / Local Search for Docusaurus v2. Try it live at:
https://cmfcmf.github.io/OpenWeatherMap-PHP-API/
MIT License
446 stars 67 forks source link

Indexing in different languages #3

Closed artycorp closed 4 years ago

artycorp commented 4 years ago

Good afternoon!

I wanted to index the document in Russian:

result:

Uncaught (in promise) Error: Cannot load unregistered function: stemmer-ru
    at 2.6c5301c6.js:2
    at Array.forEach (<anonymous>)
    at Function.P.Pipeline.load (2.6c5301c6.js:2)
    at Function.P.Index.load (2.6c5301c6.js:2)
    at 2.6c5301c6.js:2
    at async Promise.all (/index 0)

i am not strong in js can you help me?

yoichiwo7 commented 4 years ago

I suspect you only modified src/index.js. This modification will let you generate multi-language index file but you can't load the index file unless you also modify the SearchBar side.

You'll also need to add lunr-languages statements into src/theme/SearchBar/index.js so that SearchBar can load the multi-language index file. Just add the statements after the following line. (adding require statements works but I'm not sure mixing import/require statements is appropriate)

https://github.com/cmfcmf/docusaurus-search-local/blob/4dfd5c6870f629554ad3949ea71347a290a0bb4c/src/theme/SearchBar/index.js#L8

cmfcmf commented 4 years ago

Interesting, I hadn't thought about stemming non-English languages. I am wondering whether there really is the usecase of using multiple languages on the same page/document or if we can assume that every page is written in a single language? @artycorp are your pages a mix of Russian and English?

cmfcmf commented 4 years ago

I added support for multiple languages in 187b6d2 - took some time to wrap my head around how lunr-languages works, but it should now work fine for single and multiple languages :tada: