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

Site search #588

Closed
1 task done
icicimov opened this issue Oct 14, 2016 · 19 comments
Closed
1 task done

Site search #588

icicimov opened this issue Oct 14, 2016 · 19 comments

Comments

@icicimov
Copy link

icicimov commented Oct 14, 2016

  • This is a question about using the theme.

Hi Michael,

I 'm thinking about setting up a site search function and came across this plugin https://github.com/slashdotdash/jekyll-lunr-js-search, that looks not too complicated to implement. Was wondering what are your thoughts on this and is there maybe a guide you would recommend for this functionality?

Thanks

@justinrummel
Copy link
Contributor

justinrummel commented Oct 14, 2016

I've got it running on my site. Warning, it doubles the time it takes to generate a site. I was finishing in 20s, but now with Lunr it takes over 40s.

https://www.justinrummel.com/search/

@mmistakes
Copy link
Owner

mmistakes commented Oct 14, 2016

@icicimov I don't have first-hand experience with Lunr but have used similar solutions. The instructions on that repo seem pretty good but if you need more of a "tutorial" there's quite a few if you search around.

I'll echo what @justinrummel said about build times. I haven't read Lunr docs to know if this is true but I would assume it works by querying a .json index file with all of your post data in it. Depending on the complexity of that is what makes build times go up.

Other Jekyll search solutions I've used had you build a .json file that loops over every post and then you can pull out things like post titles, post excerpts, etc. If Lunr is dumping the full content of every post that would certainly increase the bloat.

@justinrummel
Copy link
Contributor

FYI; here are my commits for adding Lunr:

@icicimov
Copy link
Author

@mmistakes and @justinrummel, thank you both for your help and useful tips.

Pretty much following Justin's commit that he generously shared I have created the following structure:

_config.dev.yml:

# Plugins
gems:
  - jekyll-paginate
  - jekyll-sitemap
  - jekyll-gist
  - jekyll-feed
  - jemoji
  - json
  - jekyll-lunr-js-search

# mimic GitHub Pages with --safe
whitelist:
  - jekyll-paginate
  - jekyll-sitemap
  - jekyll-gist
  - jekyll-feed
  - jemoji
  - json
  - jekyll-lunr-js-search

lunr_search:
  excludes: [rss.xml, atom.xml]
  stopwords: "stopwords.txt"
  min_length: 3
  js_dir: "/assets/js/lunr"

Gemfile:
group :jekyll_plugins do
gem "jekyll-lunr-js-search"
end

_plugins/
├── jekyll_lunr_js_search.rb
└── related_posts.rb

assets/js/lunr/
├── date.format.js
├── jquery-1.12.4.min.js
├── jquery.lunr.search.js
├── lunr.min.js
├── mustache.min.js
├── search.min.js
└── URI.min.js

_includes/scripts.html

_includes/search.html

_pages/search.md:

---
author_profile: true
type: pages
layout: single
title: Search
permalink: /search/
exclude_from_search: true
---
{% include search.html %}

but during the local site build the index.json file is not being created and I get ERROR `/blog/assets/js/lunr/index.json' not found.

To me it looks like the plugin is not working for some reason. Do I need to do anything else apart from the above to get the plugin activated?

Thanks again for your help, very much appreciated.
Igor

@icicimov
Copy link
Author

Ok, seams I misinterpreted the plugin help page:

This Jekyll plugin handles the generation of a lunr.js compatible .json index file. Runtime search configuration is provided by a simple jQuery plugin.

and thought the plugin will generate the assets/js/lunr/index.js file instead of the _sites/assets/js/lunr/index.json file ... doh.

Still not working for some reason but after I dropped in a index.json file the plugin generated the index.json file ready for jquery to search but still blank.

@justinrummel
Copy link
Contributor

I've found Lunr to be very picky about the gem order. Please see my Gemfile and _config.yml and replicate.

@twhite96
Copy link

@justinrummel I have Lunr set up, it builds. I have tried to get your layout going with the Tag and Category archives, but I get build warnings: single layout doesn't exist. Then when visiting my site, I see the navigation but it says page not found, when I know for a fact I added those pages. I also don't have the hamburger menu for links that don't fit on the main page. Can you have a look at my repo? https://github.com/twhite96/twhite96.github.io

Thank you.

@mmistakes
Copy link
Owner

@twhite96 I think the issue is your JavaScript. If you fire up the console in your browser you'll see a bunch of errors. That's why the hamburger menu isn't working.

console-errors

@justinrummel
Copy link
Contributor

@twhite96 the "single" is a layout https://github.com/twhite96/twhite96.github.io/blob/master/_layouts/single.html

Not sure why it's not picking it up when it's obviously there in your repo. Only diff I can see between yours and mine is I have removed "{% include base_path %}" from the 5th line.

In addition I use "compress" in my default layout. https://github.com/justinrummel/jr.com-mm/blob/jr-branch/_layouts/default.html

@mmistakes
Copy link
Owner

@twhite96 Looking at your Gemfile.lock you're using some outdated gems... eg. Jekyll isn't the latest. So I would bundle update to make sure you're current.

And you're using the theme-gem along with having all of the _layouts, and _includes with your repo. And when you do that your local versions overwrite anything in the bundled theme gem, which could be why you're getting missing layout errors.

If you're using the theme gem then remove _layouts, _includes, _sass, etc... unless of course you modified any of those files and want them to replace whats in the default theme.

Or if you're not using the theme gem just remove theme: minimal-mistakes-jekyll from your _config.yml

@twhite96
Copy link

Thanks @mmistakes and @justinrummel. I can't seem to get the search page running though. Says page not found. Everything else works after I fixed the js and deleted _layouts _incluses, and _sass. Not sure what's going on there. Can anyone help?

@twhite96
Copy link

@mmistakes and @justinrummel seems that the tag archive and category archive works locally but only as a directory when running jekyll serve. Search doesn't even appear. But when running it at my production site, https://twhite96.surge.sh, pages aren't found. Something weird going on here.

@justinrummel
Copy link
Contributor

@twhite96 I was able to clone your repo locally and noticed you don't have the _pages section setup correctly. It should be files ending in .html will be converted to /filename/. Therefore, take a look at my _pages and use the same format while at the same time remove the .md files. WARNING, I've injected an element from @mmistakes hpstr to arrange all the tags at the top, then use CSS to display correctly... so your site may look different than mine.

In addition, I updated your _config to state

include:
  - .htaccess
  - _pages

Tags, Categories, and Search display correctly now.

Lastly, You did cleanup _includes as suggested when using the gem version of mm, however, you do need to keep the _includes/script.html as seen on my site as a gem override. Once that was in place, searched worked locally.

screen shot 2017-02-11 at 9 40 48 am

@twhite96
Copy link

Thank you @justinrummel! Got it working.

@icicimov
Copy link
Author

Sadly I never got this working on my site :-(

@ghost
Copy link

ghost commented Feb 24, 2017

Here's my favorite Jekyll search experience to date: https://developmentseed.org/ (click the magnifying glass)

@mmistakes
Copy link
Owner

@icicimov As others have gotten this to work I'm going to close it out. If you have additional information to provide to help resolve it feel free to re-open.

@twhite96
Copy link

@JHabdas how was that accomplished?

@ghost
Copy link

ghost commented Apr 28, 2017

lunr.js. they may even have a post about it on that site. those are the guys who created healthcare.gov

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

4 participants