-
Notifications
You must be signed in to change notification settings - Fork 956
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
[WIP] Search #253
[WIP] Search #253
Conversation
components/search/src/lib.rs
Outdated
add_section_to_index(&mut index, section); | ||
} | ||
|
||
index.to_json() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mattico something weird is happening here. I only get title
and body
as key of the JSON but running the book example of mdbook gives me:
"fields": ["title", "body", "breadcrumbs"],
"pipeline": ["trimmer", "stopWordFilter", "stemmer"],
"ref": "id",
"version": "0.9.5",
"index": { // the actual index
Looking at the elasticlunr-rs code, those fields should be serialised but it's somehow not happening?
To try you can cargo build
and run gutenberg build
in the docs
directory. A bit late here now so I will dig more tomorrow
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mdbook creates the index with a breadcrumbs field: let mut index = elasticlunr::Index::new(&["title", "body", "breadcrumbs"]);
. Does that answer your question?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really, I just don't get the version, ref, pipeline, fields fields: the index generated by that line is just {title: {...}, body: {...}}
. Way too late now though here, I'll have a better look tomorrow
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, okay, I understand the question now. The Index
struct is just the index. It doesn't include any of the configuration stuff. If you take a look at MDBook, it creates that configuration by itself. I meant to add those structs to elasticlunr-rs since they're generally useful, but never got around to it. I'll take another look.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here it is: mattico/elasticlunr-rs#9 Let me know what you think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I wasn't clear, it's not the search options that are missing.
The beautified searchindex.js of mdbook after removing the actual doc content for brevity is:
window.search = {
"searchoptions": {
"bool": "AND",
"expand": true,
"limit_results": 20,
"teaser_word_count": 30,
"fields": {
"title": {
"boost": 2
},
"body": {
"boost": 1
},
"breadcrumbs": {
"boost": 2
}
}
},
"index": {
"fields": ["title", "body", "breadcrumbs"],
"pipeline": ["trimmer", "stopWordFilter", "stemmer"],
"ref": "id",
"version": "0.9.5",
"index": {
"breadcrumbs": {
},
"title": {
},
"body": {
}
},
"documentStore": {
}
}
};
The searchoptions
object is added by mdbook as you mentioned and I don't really care about that, I'll set it up in JS directly. Here's what index.to_json
gives me in Gutenberg:
window.searchIndex = {
"body": {
},
"title": {
}
};
In short I'm missing all of fields
, pipeline
etc from the first index
object of mdbook.
The reason is that to_json
does:
pub fn to_json(&self) -> String {
serde_json::to_string(&self.index).unwrap()
}
except elasticlunr expects all those fields (https://github.com/weixsong/elasticlunr.js/blob/master/lib/index.js#L63-L81). It looks like to_json
should be:
pub fn to_json(&self) -> String {
serde_json::to_string(&self).unwrap()
}
but maybe I'm missing something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah. That seems like a rather silly oversight. I'm sure there was I reason I did it that way... but that was several months ago.
@mattico Search is now working, just missing some design work for the docs now If anyone wants to try it, they can clone that branch |
The can_build_search_index test fails since it looks for If I enable search in the config, it complains I've turned it off in my index, but I haven't. Actually, the only way I can get it to compile is disable it in my main index file, which is the section I'd like to search. The resultant search_index.en.js looks quite mangled as a result too:
lines and lines of this. Attempting to search on the site (once I'd dropped in the sections from docs/templates/index.html) didn't return anything at all, no errors in the console either. That was just a quick look though, and it was time for bed a while ago, so I'll take a closer look tomorrow. |
Thanks for the review! I fixed the first 2 points.
Even if you search for something like
I need to get some sleep too :) |
Oh cool, I haven't come across an inverted index before—nice! Won't have time to look at this again until the afternoon. |
Here's the alterations I've done: 7cc3d5d. From the looks of it these are the only changes I should need, although I don't see any updates in the |
You have another element with an id = search in the header so the JS binds the event handling to that one instead. |
Bah! Yes, of course! Can confirm it's working now 🍾 And thanks! Revamping my old site has given me some motivation to actually post more content. |
No description provided.