Having search functionality can be a really useful for viewers in order to find content on your site. In this post we are going to explore the currently available options for adding search functionality to your Ghost blog theme.

A simple but powerful search library for Ghost, available on GitHub this package is compatible with Ghost 3.0.

It uses fuzzysort under the hood.

Requirements:

  • Ghost Content API
  • an input field for the search
  • initializing the ghost-search library
  • setup a Custom Integration in Ghost Admin

Options:

  • url - your custom integration(site) url
  • key - your custom integration content api key
  • version - by default v3 for Ghost 3.0
  • input - the id of the input field
  • results - the id of the element where the results should appear
  • button - the id of the element to trigger the search, by default it's empty as the search is performed while you type
  • defaultValue - you can set a default value for the input
  • template - the template used to render the search result
  • trigger - can be focus (load data when the input is in focus) or load (load data on page load)
  • options - other options from the fuzzysort library
  • api - refers to the Ghost Content API
  • on - there are four events available here: beforeDisplay, afterDisplay, beforeFetch and afterFetch.

As you can see, there are quite a lot of options to customize how the search will work. The great thing about this library is that the whole script in minified version is under 12KB.

This is the plugin we use in all our Ghost Themes.

Ghost Finder

This one works somewhat similar to the first library, also available on GitHub.

Requirements:

  • add the script to your theme
  • add the input element for search
  • create an instance of the search
  • setup a Custom Integration in Ghost Admin

Options:

  • input - the search input
  • showResult - the element where the search results will be placed
  • homeUrl - your site url
  • contentApiKey - the content api key from the custom integration
  • resultTemplate - the template for the results
  • singleResultTemplate - the template for a single result
  • excerpt_length - the length of the excerpt (number)
  • time_format - the format string for the date 'MMM Do YYYY'

Available variables to use within the result template:

  • ##title - Post title
  • ##url - Post url
  • ##primary_tag_name - Name of primary tag
  • ##primary_tag_url - Url of primary tag
  • ##primary_author_name - Name of primary author
  • ##primary_author_url - Profile url of primary author
  • ##primary_author_avatar - Profile photo of primary author
  • ##excerpt - show some words of the post content. Default words count is 15
  • ##published_at - Post publication date. Format can be change by time_format option
  • ##feature_image - Post featured image url
  • ##resultCount - Matched result count

Compared to Ghost Search we have somewhat less options.

Ghost Hunter

GhostHunter was the first search plugin created for Ghost. The major drawback is that it uses jQuery which would bloat the script size you would add to your site, thus affecting the performance.

Requirements:

  • add the script to your theme
  • setup a Custom Integration in Ghost Admin

Options:

  • results - the JQuery ID of the element into which search results should be inserted
  • onKeyUp - for instant search-as-you-type set the value true
  • result_template - the handlebars template used to render the results
  • info_template - to display the number of search items found
  • displaySearchInfo - to display the info_template
  • subpath - to set the site to a sub folder like "/blog"
  • onPageLoad - should the indexing happen on page load
  • before - event before the result list is shown
  • onComplete - event after the results are displayed

GhostHunter was developed before Ghost 1.0 and many things have changed within Ghost since then, the other plugins seem to be a better option right now.

Site Search 360

Site Search 360 is an another way to add search to your Ghost site.

Requirements:

  • add the search code to the theme
  • create a search page and style it

There is a tutorial by the Ghost Team how you can integrate it into your Ghost Theme.

The main advantage of using a tool like Site Search 360 is that you’ll be able to monitor usage. You can see how often people are using the search and what they are searching for so you can improve the navigation experience.

Let us know if you found another option to add search to your Ghost theme.