Repository navigation
Refactor search plugin - #1418
Conversation
Put web worker stuff to a new plugin and leave legacy_search with its former behavior.
Fixes mkdocs#1218, fixes mkdocs#1127, and partially addresses mkdocs#859.
Remove all unnesecary whitespace. Closes mkdocs#1128.
In mkdocs.yml define seperator like this:
plugins:
- search:
seperator: '[\\s\\-\\.]+'
Fixes mkdocs#867.
This only works in a worker.
Fails as the code tries to run before all scripts are loaded. Not sure how best to deal with that.
Still need to use it. To display search results the raw docs data is still needed by the browser. As we need to pass everything to the browser we might as well put it all in one file.
Testing with MkDocs documentation the index file size went from 219 KB to 809 KB by adding the prebuilt index to the file. While having the index prebuilt may be faster, it is not nessecarily lighter. So let's give users the option to choose.
Users don't need the extra language support files for languages they don't support. No need to bloat their site.
This makes for more consistent handling. Sometimes worker.js is run in a seperate thread. Somethimes in the main thread (as a fallback) and sometimes the index is prebuilt. That's three different envionments where the index can be build, each with a different possable base_url. By only applying the base_url in the main thread when search results are displayed, we ensure consistancy.
If using a single lang, can be a string, otherwise expects a list. Each lang provided is checked against lang support files and validation error is raised if support file is not found. Adding new langs is as simple as adding the support file.
|
Anyone reviewing this (especially theme authors @squidfunk) should take a close look at the structure of the
Note that the A word of caution: if the user does not set |
|
@waylan Well, I think upgrade complexity and necessary effort are very important aspects. When I'm running an Open Source project as large as Material I try always to minimize breakage across versions, even minor versions. I try to keep them to major releases and so far there have been two. I don't want my users to bother with more setup than they currently have, only to support search which all users take for granted and which works very well for Material. Introducing such a change would incur a silent penalty (prebuilt index is on by default) that probably nobody would notice. It would mean that the setup for every theme is getting more complex and there are more potential traps to fall into. There are a lot of users asking simple questions on the issue tracker already. When you want themes to adopt different plugins, you also need themes to explicitly state what they want to support for those plugins. This is the very reason we have the search index configurations in the top-level theme object which were added in 0.17.1. It would be perfect if themes can define which features they support and turn on/off default flags for plugins, if they are available. Otherwise, if the user specifies the plugin themselves, I would expect that the user's choices take precedence. The configuration options I added are partly there because MkDocs doesn't support some features. Search is probably a topic which Material addresses in a very specific way and therefore added a lot of options. I will do my best to merge them with the new options for the search plugin. Regarding the languages - Material integrates the languages from lunr-languages and adds support for more languages by configuring stemmers, trimmers and tokenizers in specific ways - see the language files. Language support doesn't include stemming, yes, but otherwise search wouldn't work at all, that's the reason Material does that. |
I agree. However, it is important to remember that you are currently developing against a pre-1.0 version of Mkdocs. At this point I'm more interesting in getting things "right" than backward compatibility. The next release of MkDocs (which will include the refactored search) will be 1.0, so from my perspective, if we are going to break anything, now is the time to do it. What we settle on now is what we're stuck with going forward.
That's understandable and a consideration of mine as well. I realize search is a special case, but it is also the first plugin using our new API so its the testing ground for the API. I want to get that API right and how plugins and themes interact is a much bigger factor than I originally anticipated.
Thank you. That's helpful feedback. And that more-or-less is what I am proposing. Unfortunately, I expect that means backward incompatible changes with the 1.0 release of MkDocs but I havn't fleshed out the details yet. |
Annoyingly I tested against 3.6 but earlier versions are different.
|
@yeraydiazdiaz we have a couple jshint errors for your code that I'm not clear how to resolve. Any assistance would be appreciated. As a warning, I rebased the code since your last commit, so you may not be able to merge cleanly. |
|
Should be fixed via yeraydiazdiaz@8597619 |
| } else if (lang.length > 1) { | ||
| this.use(lunr.multiLanguage.apply(null, lang)); | ||
| } | ||
| this.field('title', { boost: 10 }); |
There was a problem hiding this comment.
As has been mentioned in #1319 and olivernn/lunr.js#312 field boosts are not currently supported by Lunr 2.x. The second parameter here will be ignored, I'm not sure that does any harm, but perhaps a comment might help.
When I get around to implementing field boosts it will almost certainly use this interface (same as Lunr 1.x) so you could leave this here to take advantage of field boosts when they arrive.
There was a problem hiding this comment.
Thanks. I realize boost is being ignored. But your right, no point in leaving it there. It will just cause confusion later when we forget that.
| @@ -0,0 +1,2977 @@ | |||
| /** | |||
| * lunr - http://lunrjs.com - A bit like Solr, but much smaller and not as bright - 2.1.5 | |||
There was a problem hiding this comment.
FYI Lunr 2.1.6 was released which includes a performance improvement when building indexes. I don't know how you intend on keeping up with releases of Lunr, but thought you might appreciate faster building!
There was a problem hiding this comment.
Thanks for the heads up. Might as well release with the most recent version.
|
Thinking about this some more, I think maybe we should change the default for It occurs to me that this could present a problem in that a user could build the same project from two different machines and get two different results if one has node installed and the other doesn't. The way things are now, there would be no warning to the user. Instead, to prebuild the index, we should require the user to explicitly request it and then issue either a warning or error if it fails. I'm thinking perhaps a warning (which would still fail in "strict mode") as things will still "work" without it. While it's true that we loose the prebuilt index as a default, it really only benefits users with large sites anyway. Those users are going to be willing to do the extra work to set the config setting and install Node.js. If, at some point in the future, we get a Python solution for pre-building the index, then we can reconsider the default at that time. |
That's a very valid point and great idea. Users having problems with the search will want to go the extra mile. You could add a section on performance improvements for search in the documentation and add the |
|
The |
Well, now that you mention it, I just published v0.1.1a1 of Lunr.py 😄 I honestly thought it'd take me longer to port but @olivernn did an excellent job with the JS version, especially with the unit tests which helped quite a bit to get the building blocks sorted quickly. There's still a few places in the API I'd like to tweak to make it more Pythonic, but I'm happy to say it produces the same results searches on the MkDocs Have a look at the repo if you like, of course any feedback is appreciated. |
|
@waylan Many thanks for your efforts here - I hope this makes the search also usable for my rather large documentation without blocking the browser. Do you already know when this is going to be released officially? |
|
@josuahunziker this will be part of the 1.0 release. Version 1.0 will be released when the milestone is complete. |
|
@waylan Ok, many thanks! I'm looking forward! 😃 |
Uh oh!
There was an error while loading. Please reload this page.