Skip to main content
Back to work Samuel
Mortenson

Lunr for Drupal

Static searches without custom code
The Lunr logo

After creating Tome, I realized that the two most common requests for static sites would be form submissions (covered by many third parties) and search. Search on a static site is usually done with AJAX, sometimes to a third party or something like Solr. I did some research and found the Lunr project, which was advertised as a lightweight client-side alternative to Solr.

Lunr lets you generate a search index, either at runtime or before hand, which the client then loads and uses to perform fuzzy searches. I created a Drupal integration for Lunr in the form of a module that provides an easy way to take data from a View and use it to generate an index, in addition to having a dedicated page to search through those results.

The fun part of this for me is that so much of the code is in JavaScript - Drupal handles the view and Lunr search index configuration, but the user interface for searching is completely client side. If you want to learn more about the project, your can read the blog post. You can also try out the search on this site at /search.

Project page: https://www.drupal.org/project/lunr