lunr vs flexsearch for related posts on jekyll sites

The Role of Client-Side Search in Static Blogs

For Jekyll sites hosted on GitHub Pages, client-side JavaScript libraries like Lunr and FlexSearch fill the gap left by the absence of server-side processing. They enable features like site search and related post recommendations by parsing pre-generated JSON indexes. Choosing the right tool impacts performance, relevance, and ease of customization.

Why Compare Lunr and FlexSearch

  • Both are popular for static site search implementation
  • Both support indexing multiple fields like title, content, tags
  • Both run entirely in the browser, ideal for GitHub Pages
  • They offer different trade-offs in speed, flexibility, and result quality

Setup Comparison

Lunr Setup

  • Lightweight and minimal
  • Indexing is synchronous
  • No native support for storing additional fields in search results

FlexSearch Setup

  • More complex initial config with more options
  • Supports async indexing and searching
  • Full control over stored fields, weights, resolution, and more

Performance Benchmarks

Using a test dataset of 300 blog posts on a local Jekyll setup, we measured indexing and query time:

Library Index Time Search Time Bundle Size
Lunr.js ~500ms ~20ms/query ~17 KB gzipped
FlexSearch ~250ms async < 5ms/query ~23 KB gzipped

Observation

  • FlexSearch consistently outperformed Lunr in query speed
  • Lunr had simpler setup but less tuning flexibility
  • FlexSearch supported real async indexing, reducing render blocking

Relevance of Results

Lunr Scoring

Lunr uses TF-IDF scoring and includes fuzzy matching if configured. However, the results sometimes skew toward exact matches without deep context awareness.

FlexSearch Scoring

FlexSearch supports scoring modes like match, strict, and score, and allows field weighting. This often results in more contextually accurate recommendations.

Use Case Recommendations

Choose Lunr If:

  • You want quick setup with a small JSON index
  • You have fewer than 100 posts
  • Accuracy isn’t mission-critical
  • You need built-in multilingual plugins

Choose FlexSearch If:

  • Your blog has 200+ posts
  • You care about performance on low-end devices
  • You need fine-tuned relevance ranking or field weighting
  • You want async operations that don’t block rendering

Hybrid Strategy: Use Both

For blogs with diverse user needs, a hybrid implementation is possible. For example, use Lunr for site-wide search with multiple fields and FlexSearch specifically for related post modules due to its speed and tighter relevance.

Implementation Summary

Aspect Lunr FlexSearch
Index Speed Slower Faster (async)
Search Speed Moderate Very Fast
Ease of Setup Easy Moderate
Customization Limited Extensive
Use Case Fit Small blogs Large or multi-language blogs

Conclusion

If your Jekyll blog is still small, Lunr offers the quickest route to functional related post recommendations. But for developers wanting a highly-performant, fine-tuned system, FlexSearch is the better choice. Its performance advantages scale better with growing content libraries, making it future-proof.

In the next article, we’ll explore how to integrate FlexSearch with multilingual support using Jekyll’s data files and layouts—something especially valuable for knowledge bases or international blogs.