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

lunr search - doesn't index _pages? #1409

Closed
1 of 5 tasks
Sciss opened this issue Dec 17, 2017 · 12 comments
Closed
1 of 5 tasks

lunr search - doesn't index _pages? #1409

Sciss opened this issue Dec 17, 2017 · 12 comments

Comments

@Sciss
Copy link

Sciss commented Dec 17, 2017

  • 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?

@mmistakes
Copy link
Owner

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

@Sciss
Copy link
Author

Sciss commented Dec 18, 2017

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.

@mmistakes
Copy link
Owner

mmistakes commented Dec 18, 2017

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
Copy link
Owner

Lunr upgrade info https://lunrjs.com/guides/upgrading.html

@nickgarlis
Copy link
Contributor

@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.

@mmistakes
Copy link
Owner

Sounds good @nickgarlis 😀

@nickgarlis
Copy link
Contributor

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.

@Aaronius
Copy link

If anyone has a modified lunr file that supports pages, I'd sure appreciate a copy. ❤️

@mmistakes
Copy link
Owner

mmistakes commented Apr 24, 2018

@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.

@nandahkrishna
Copy link

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.

@rohan-raman
Copy link

Is there a more streamlined way to apply the changes made by @nandahkrishna? While their lunr file works, I do not understand why the changes are not already made default in the minimal-mistakes repo. Is there some sort of drawback?

@ultimape
Copy link
Contributor

I took a shot at implementing this as an optional config in #3352
(so to not break anyone's search if they are depending on existing functionality)

Having page indexing was essential for my current project and shoving everything into a collection doesn't really fit my flow. Hope this is useful.

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

No branches or pull requests

7 participants