DocPad Lunr Plugin
Generates Lunr search indexes from your Docpad collections, and provides helpers for a client-side full-text and faceted search.
npm install --save docpad-plugin-lunr
docpad install lunr
Configure a collection to index in your
To create an index which includes multiple collections you can pass an array of collection names:
Make your search page itself, eg
<%- @getLunrSearchPage('myIndex') %>
Make a "search bar" on other pages that redirects users to your search page above, like in a layout, eg.
<%- @getLunrSearchBlock('my-search-page.html') %>
To control the fields that get indexed and their "boost" levels (ie, relevance), add to the index's configuration in
indexFields:name: "body"boost: 1name: "title"boost: 10name: "tags"boost: 100
To control the fields that are available in search results, add to the lunr configuration in
contentFields:name: "title"name: "url"name: "date"
For faceted search, add to the lunr configuration in
facetFields:name: "tags"label: "Filter by tag"name: "type"label: "Filter by type"
(Note: the faceted search is not part of Lunr, just my own poor-man's version. Also, you may want to put in a bit of CSS to highlight the "active" facet filters, such as:
To provide an Eco template for the search-results, add to the lunr configuration in
<div><a href="<%= post.url %>"><%= post.title %></a><span>posted on <%= post.date %></span></div>
Or provide a template function for search results directly in
:post = contextpostreturn """<div><a href=""></a><span>posted on </span></div>"""
To add your own "stopwords" to prevent certain words from being indexed, add to the index's configuration in
If you want to make your own UI (and your own implementation of facets), here are the basics:
- Currently this plugin is geared towards static sites, and brings everything client-side. Need to allow for dynamic sites to take advantage of having a back-end - ie, keep the index, searching, and content on the back-end.
- Hopefully if faceted search is added to Lunr proper, re-implement using that
- Failing that, add more facet types, like dates and numeric ranges
- Allow for custom pipeline functions