Software engineering notes

Blog search

leave a comment »

Problem statement

I’d like to provide a quick way to retrieve information from this blog.

In terms of constraints, this blog is statically generated and hosted on Github, which disallows arbitrary plugins, limiting many solutions to client-side and/or external vendors. I’d also prefer to keep things free.

Solutions

Tags

Jekyll supports tags, and the Forestry CMS I use enables me to manage tags alongside content, so I can start by including tags in my index of notes.

Client-side search

Ideally, I could provide inline keyword search.

Search providers understandably require UI control.

Lunr provides a convenient JS library to perform keyword extraction and lookup, and supports pre-building the search index to improve client performance. However, the index for my content was 500kb and the search syntax, although powerful, was unintuitive for my simple needs.

Google’s published the most common English words. I could strip these from my content and then include the remainder in my index, eg:

{% raw %}
  {% unless site.data.stop_words contains word %}
    {{word}}
  {% endunless %}
{% endraw %}

This still yields more words than wieldy for displaying in an index. I’m also limited to Liquid syntax for index generation, which complicates things like excluding code snippets.

So far, the best solution has been constructing a regex from an input string, applying it to the titles and tags of my index and then hiding entries that don’t match.

Server-side search

I can take advantage of Google’s search indexing by defining a Jekyll sitemap. I can get closer to inline filtering by using Chrome’s omnibox. Here’s the blog’s opensearch.xml.

Written by Erik

July 29, 2017 at 12:54 pm

Posted in tool

Tagged with , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: