olivernn / lunr.js

A bit like Solr, but much smaller and not as bright
http://lunrjs.com
MIT License
8.91k stars 546 forks source link

Searching for words prepended with underscores doesn't work #286

Closed coliff closed 7 years ago

coliff commented 7 years ago

My documents include many class names such Msg_IDT_ZOOM

I'd like users to be able to search for IDT and ZOOM so that it shows Msg_IDT_ZOOM in the results - how can I do this? I'm using Lunr.js through the mkdocs-material theme (http://squidfunk.github.io/mkdocs-material/)

olivernn commented 7 years ago

This is caused by what lunr considers to be a separator, by default an underscore is not considered a separator.

This is easy to change, as described in this fiddle.

I'm not at all familiar with that mkdocs theme, so I'm not sure how you would make these changes in that context, perhaps open an issue on that project?

coliff commented 7 years ago

Thanks so much for taking the time to reply with the explaination and code example. I'm not really much of a JavaScript coder but I dug in to the JavaScript code for the MkDocs theme and replaced: tokenizer.separator=/[\s\-] with tokenizer.separator=/[\s\-\_] and it worked! 👍

olivernn commented 7 years ago

Nice, glad its working for you!