Server-side search for Ghost blogs using elasticlunr
This is a hacky but functional way of offering search on your Ghost blog.
Why do it this way instead of using GhostHunter?
GhostHunter requires jQuery. jQuery was the bee's knees half a decade ago. Now it's just overhead.
The alternative scrapes the RSS feed rather than querying the Ghost API. It's just better to use the API. It's a lot simpler to capture JSON objects and map them to DOM nodes, and there's also the issue that Ghost might not keep the RSS feed around forever.
This solution upgrades to elasticlunr. Elasticlunr is a fork of lunr which adds some cool features to improve search fidelity. Well worth it.
How to use ghost-search
You'll obviously need to have a Ghost blog. You can add this before or after you install your Ghost blog, but it's probably easier after you have a few posts so you can test it properly.
First, get elasticlunr and add it to your other npm modules in Ghost:
npm install elasticlunr
Next, add the route you want to use:
cd /var/www/ghost/core/server/routes && sudo nano frontend.js
Save and exit.
Then, get the search controller in place:
cd /var/www/ghost/core/server/controllers/frontend/ && sudo nano index.js
Append the aptly named script. Save and exit.
Finally, let's consider the view.
This is pretty damned fast. Even if you like jQuery on the client-side, you should still implement search with this controller because it will enable you to tap in to the Ghost API rather than scrape the RSS feed. This method has a lot more potential in general.