-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support CJK (mutiple language) search #2052
Comments
refs: Support CJK (mutiple language) search #2052 rust-lang/mdBook#2052
refs: Support CJK (mutiple language) search #2052 rust-lang/mdBook#2052
This is great! It now responds to Japanese! (Sorry, I used it without permission...😓) |
I just created a modified fork in this way, and it worked well. The modified version and the modified commit. It is better to adjust the |
This topic is interesting to me as well, and I would like to see it develop! I have always wanted to know how to reflect search scores. |
Fzf calculates the score according to how the result matches the query and where it occurs. (If my understanding is correct). I just took a look at But it depends on two assumptions: As far as I know, these two assumptions are incorrect in Chinese and Japanese. Though it can be used with Chinese and cause a long context with incorrectly emphasized phrases. To my understanding, we must figure out how |
I see! By the way, this is a bit off topic, but ....... I think this is an |
No. There are not many options for
My understanding: function fzfLoad(index) {
// The argument `index` is generated by crate elasticlunr-rs
// It contains all pages with their title, breadcrumbs, contents, and some metadata
// Extract docs from index
// `docs` is an obj: { [id: number]: { title, breadcrumbs, body, ... } }
const docs = index.documentStore.docs;
// Init fzf
// The first argument is the list to search. (I have tried using Object.entries, but I failed to get it to work)
// The second argument is the option. `selector` tells fzf what the real content to search.
const fzf = new Fzf(Object.keys(docs), {
selector: (id) => {
// These lines concatenate title, breadcrumbs and body to let fzf search them at once.
const doc = docs[id];
return `${doc.title} ${doc.breadcrumbs} ${doc.body}`
}
});
// To be compatible with the original elasticlunr's usage,
// this obj is needed to provide a `search` method.
return {
// `search` takes two arguments, the `term` to search and `options` for elasticlunr
search: (term, _options) => {
// We use fzf to search the term
const entries = fzf.find(term);
// Then we form the result
// `doc` and `ref` are used to make the teaser and the link
const res = entries.map((entry) => {
const { item, _score } = entry;
return {
doc: docs[item],
ref: item,
}
});
return res;
}
}
} |
Ugh, I knew it! ... On the other hand, you mean that we might be able to do it if we really wanted to. Thanks for chatting with us! |
It works but with a little flaw that the matched words are not bolded/highlighted. |
Problem
Anyone who has a CJK search requirement, There is a quick hack way.
Proposed Solution
Just need add two extra JS.
Add them to book.toml additional-js
Play it with docker directly.
Notes
The trick is to replace Elasticlunr.js with fzf.
The text was updated successfully, but these errors were encountered: