Minimal-mistakes: lunr search - doesn't index _pages?

Created on 17 Dec 2017  路  10Comments  路  Source: mmistakes/minimal-mistakes

  • [x] This is a question about using the theme.
  • [ ] This is a feature request.
  • [ ] I believe this to be a bug with the theme.

    • [ ] I have updated all gems with bundle update.

    • [ ] I have tested locally with bundle exec jekyll build.


Information

The site search is a great feature; I can't find much info here, though: https://mmistakes.github.io/minimal-mistakes/docs/configuration/#site-search - simply enabling search: true in _config.yml makes it possible to search through _posts, but it doesn't seem to index _pages.

How can I make the search feature include all texts in _pages as well?

Bug Support

All 10 comments

Currently only supports posts and collections. You'd have to alter the code to index pages as well.

https://github.com/mmistakes/minimal-mistakes/blob/master/assets/js/lunr-en.js

Thank you; I could use collections now. It's worth noting - perhaps you can add that info to the guide - that lunr breaks if you use a number as a tag. I had this:

tags: [installation, 2015]

and this causes a JavaScript error t.toLowerCase is not a function. Changing to

tags: [installation, "2015"]

makes it work.

Looks like the version of Lunr.js included (0.5.12) with the theme is super old. It's currently at 2.1.5 so perhaps this issue has been fixed.

@nickgarlis Any particular reason you used an older version of Lunr? I did a quick test by updating to the current version and I get Uncaught TypeError: idx.add is not a function, so guessing the API changed slightly. Wondering if we can update since with any sort of functionality/performance gains. Thoughts?

@mmistakes I think it had something to do with the custom stemmer that I use to support Greek characters. The error that you get must be because Lunr now gets the documents added in the configuration function. Other than that, I think that upgrading is a good idea and it is something that I had in mind. I will run some tests and if everything works properly, I can pull request the upgrade.

Sounds good @nickgarlis 馃榾

I just pull requested the update #1419 . Lunr will not break if you use numbers as tags now. Also, Lunr is now configured to search for every word inside of the query string and not just for the whole string.

If anyone has a modified lunr file that supports pages, I'd sure appreciate a copy. 鉂わ笍

@Aaronius The Lunr index currently loops through collections documents (... posts). Here's the relevant code. To add pages to the mix you'd have to loop through site.pages as well.

For a better search experience I'd suggest using Algolia instead.

And if you need an example of how to set it up check out this repo.

Old issue with a really simple fix but here is the modified Lunr file I use to ensure pages are indexed as well. Just in case someone wants to know exactly what to change. Thanks @mmistakes for pointing out the file to change.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

halirutan picture halirutan  路  4Comments

QuantLab picture QuantLab  路  5Comments

svoner picture svoner  路  3Comments

KiarashS picture KiarashS  路  4Comments

satwikkansal picture satwikkansal  路  4Comments