Skip to content
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

Search with Elasticlunr #472

Closed
wants to merge 14 commits into from
Closed

Search with Elasticlunr #472

wants to merge 14 commits into from

Conversation

Phaiax
Copy link

@Phaiax Phaiax commented Oct 22, 2017

Belongs to Issue #51 , Proof of concept of mdbooks book and of the rustbook

This PR is not ready for merging, but I wanted to allow reviews.

Tracking:

  • Indexing not working properly (uses workaround, investigation needed)
  • Configuration (waiting on Making configuration more flexible #457)
  • Use keys (up/down) for selecting a search result
  • Disabled search must disable search index generation, currently it is simply not written into the indexfile.
  • Measure slow down
  • Bug: Escape scrolls to top.
  • Won't do: Improve teaser generation speed

@Phaiax Phaiax mentioned this pull request Nov 8, 2017
@Michael-F-Bryan
Copy link
Contributor

@Phaiax, would you be able to add a link to your proof-of-concept version in the description so people can see what the user-facing search will be like?

@mattico
Copy link
Contributor

mattico commented Nov 13, 2017

@Phaiax I've updated elasticlunr-rs, and the generated indexes actually work now.

However, for search to not miss any results we need the stemmer used to generate the index to be identical to the one used to search. The version of elasticlunr-rs on crates.io uses a stemmer from rust-stemmers, which doesn't quite have the same output. The version on master on the repo uses a port of the stemmer from elasticlunr.js, but there's a bug where it doesn't work on words ending in "ted" or "ting". Until I get that fixed there may be results missing if you use generated indexes.

@Phaiax
Copy link
Author

Phaiax commented Nov 13, 2017

@mattico: Nice (I saw your comment in the reddit What's everyone working on thread :) )

Today I added configurability. Tomorrow I will update the proof of concept and do the key up/down handler.

One problem appeared. My teaser algorithm is way too slow and needs a rework. In the above example, it did not matter, but it is causing lags in the official rust book.

@Michael-F-Bryan
Copy link
Contributor

@Phaiax, I just had a look at the configuration stuff and it seems pretty good so far.

Something that occurred to me is whether we want to have search enabled by default or not (e.g. enabled is true in Search::default()). If it ends up being pretty slow or expensive then users may prefer to have search deactivated while developing.

/// The searchoptions for elasticlunr.js
#[derive(Serialize)]
struct SearchOptions {
bool: String,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just out of curiosity, what does this guy do?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This mimics the structure of the searchconfig object, that elasticlunr expects. At first i serialized the config::Search struct, but that uses kebab-case which is not nice and would cause hidden breakage if modified.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah fair enough, so it's a elasticlunr-specific thing then. I thought bool was an unusual choice for a variable in a Rust program, given it's also the name of a primitive type.

@Phaiax
Copy link
Author

Phaiax commented Nov 14, 2017

I updated the previews. Links in first post.

@Phaiax
Copy link
Author

Phaiax commented Nov 14, 2017

I will measure the slowdown.

@mattico
Copy link
Contributor

mattico commented Nov 15, 2017

Oh, and I renamed the package (but not the crate!) to "elasticlunr-rs".

@Phaiax
Copy link
Author

Phaiax commented Nov 20, 2017

Almost done. (Commit when elasticlunr-rs 0.2.1 is pushed to crates.io)

Timing with the rust book, second edition:

Search Debug Release
Enabled 52s 2.2s
Disabled 24s 0.86s

You decide if it should be enabled by default, but I think it should. For small books it does not make a difference and for large books such as rust book, they will probably tell their contributors about this option.

@Phaiax
Copy link
Author

Phaiax commented Nov 26, 2017

@Michael-F-Bryan this is ready to merge.

@Phaiax
Copy link
Author

Phaiax commented Nov 26, 2017

Added two more things, but now it should be ready.

@Michael-F-Bryan
Copy link
Contributor

@Phaiax, what are your thoughts on adding a couple tests to this? We'll want to ensure search index generation doesn't accidentally get broken if those sections get refactored later on. Would it make sense to add a couple integration tests for search under the tests/ directory?

@Michael-F-Bryan
Copy link
Contributor

Sorry @Phaiax, it looks like merging #491 broke a fair amount of this PR due to conflicts 😞

We can probably remove most of the changes this PR makes to the book's internal representation because they will have (mostly) been dealt with in #491. So this PR "only" needs to worry about the html renderer and adding a Search struct to the HtmlConfig.

@Phaiax
Copy link
Author

Phaiax commented Dec 14, 2017

@Michael-F-Bryan I'm still planning to do this, but I have limited time in the moment

@Michael-F-Bryan
Copy link
Contributor

@Michael-F-Bryan I'm still planning to do this, but I have limited time in the moment

No stress 🙂 I'd found myself with a lot of spare time recently and was just going through any outstanding PRs and issues, seeing if there's anything I can do to help them along.

I really like this PR and your proof-of-concept looks awesome, so if there's anything I can do to help don't hesitate to let me know!

@mattico
Copy link
Contributor

mattico commented Jan 28, 2018

I'm working on updating this PR: https://github.com/mattico/mdBook/tree/search-eljs-rebase

It's mostly complete, but there are a few JS & styling bugs, and the index is missing some things.

@Phaiax, if you modified the stylus files, could you push your changes? It would help me out a lot.

@cetra3
Copy link
Contributor

cetra3 commented Feb 1, 2018

@mattico, I've got a couple of css/js changes to bring it inline with the original. I've pushed this to this branch here: https://github.com/cetra3/mdBook/tree/search-eljs-css

@mattico
Copy link
Contributor

mattico commented Feb 2, 2018

@cetra3 Moving the searchbar into the header was deliberate, I thought it worked better with the sticky header that we have now. Of course, then the results shouldn't be stuck into the top of the document... Yeah I'll change it back to how it was, we can have style discussions after this is merged. Thanks for the fixes!

@cetra3
Copy link
Contributor

cetra3 commented Feb 2, 2018

@mattico yeah it can be changed. I was just having a hard time lining up the search input with the search text, as there is some indentation with the icons.

@Michael-F-Bryan
Copy link
Contributor

@mattico and @Phaiax this has been succeeded by #604, is it okay to close this PR?

@mattico
Copy link
Contributor

mattico commented Mar 5, 2018

I'd say yes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants