cmfcmf / docusaurus-search-local

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

Chineses language not suport #46

Closed Elinpf closed 3 years ago

Elinpf commented 3 years ago

hi! i found lunr-language is support chinese now, i install the depend module nodejieba to support it. and setting languages: ['en', 'zh']; in config file. building is OK.

But it doesn’t seem to be running very well, what should i do?

thanks.

cmfcmf commented 3 years ago

Hi @Elinpf, I'm afraid that Chinese (zh) is not yet supported by this plugin. I looked into it a bit this morning (see https://github.com/cmfcmf/docusaurus-search-local/pull/47), but this appears to be a non-trivial task due to the difficulty in tokenizing Chinese (tokenizing = extracting words from a series of characters). The tokenizer used by lunr-languages uses a C++ library under the hood, which we can't run in the browser. We could possibly use a different library, compiled to Web Assembly, but I don't have the time right now to look into that, I'm afraid.

Elinpf commented 3 years ago

hi @celizi, 这个看不了源码呀,受限了。你这边能把config的内容贴出来我参考下吗? 非常感谢!

celizi commented 3 years ago

i18n: { defaultLocale: 'zh-Hans', locales: ['zh-Hans'], }, plugins: [ // yarn add @cmfcmf/docusaurus-search-local [require.resolve('@cmfcmf/docusaurus-search-local'), { // warning: Use '@cmfcmf/docusaurus-search-local' (without the require.resolve) if you use Docusaurus before v2.0.0-alpha.56 blogBasePath: '/blog', // must correspond to the base path configured for the blog plugin docsBasePath: '/docs', // must correspond to the base path configured for the docs plugin indexBlog: true, // whether to index blog pages indexDocs: true, // whether to index docs pages indexPages: false, // whether to index static pages // /404.html is never indexed language: "zh" // language of your documentation, see next section } ] ],

会提示安装结巴 jieba

国际化文件 项目/ i18n / zh-Hans / code.json { "cmfcmf/d-s-l.searchBar.placeholderWithoutVersion": { "message": "搜索", "description": "搜索" }, "cmfcmf/d-s-l.searchBar.placeholderWithVersion": { "message": "搜索", "description": "搜索" }, "cmfcmf/d-s-l.searchBar.noResults": { "message": "无数据", "description": "无数据" } }

然后一些样式配置

项目/ src / css / custom.css

.aa-DetachedSearchButton { height: 40px !important; border-radius: 20px !important; border: 1px solid rgba(0, 0, 0, 0.1) !important; }

.aa-DetachedSearchButton:hover { box-shadow: 0px 0px 1px 1px var(--ifm-color-primary) !important; }

.aa-DetachedSearchButton:focus { box-shadow: 0px 0px 2px 3px var(--ifm-color-primary) !important; }

.aa-DetachedSearchButtonIcon, .aa-SubmitIcon, .aa-ClearIcon { color: var(--ifm-color-primary) !important; cursor: pointer !important; }

.aa-Form, .aa-DetachedFormContainer { border: 1px solid rgba(0, 0, 0, 0.1) !important; }

.aa-Form:focus, .aa-Form:focus-within { box-shadow: none !important; }

/ .aa-DetachedCancelButton { display: none !important; }/

.aa-DetachedSearchButtonPlaceholder { color: rgba(128, 126, 163, .6) !important; width: 50px; }

.aa-Input::-webkit-input-placeholder { color: rgba(128, 126, 163, .6) !important; }

celizi commented 3 years ago

npm install nodejieba --registry=https://registry.npm.taobao.org --nodejieba_binary_host_mirror=https://npm.taobao.org/mirrors/nodejieba yarn install --registry=https://registry.npm.taobao.org

Elinpf commented 3 years ago

@celizi @cmfcmf thanks very much! I found an error. I set the options in the plug-in configuration incorrectly. language is set to languages. So it can't work. Fix it. everything will get better.

celizi commented 3 years ago

ok

cmfcmf commented 3 years ago

@celizi @cmfcmf thanks very much! I found an error. I set the options in the plug-in configuration incorrectly. language is set to languages. So it can't work. Fix it. everything will get better.

Good to know! I added some code to validate options in https://github.com/cmfcmf/docusaurus-search-local/commit/0a19de56bddca3561704e9122526f87677f83e8b, so typos like these will no longer be an issue.