Switching Blog Search to Algolia

May 30, 2020 · 2 min read · 315 Words · -Views -Comments

My personal blog was previously using Swiftype for search, but it has a trial period and started showing a 402 error after expiration. The local search experience was very poor, so I switched to Algolia. I found that there are different opinions online about configuring this service, and I encountered some pitfalls. I’m marking it down briefly here.

Current Blog Theme Version

  • hexo - v3.9.0
  • hexo-theme-next - v7.2.0

Note: Configuration may vary with different versions.

Algolia Site Service Registration

  • Log in to the official website, register an account, and create an index.
  • Create an API in API Keys > All API Keys, ensuring it has permissions to search, add, and delete indexes.

The search, admin API Key and index name will be used in the blog configuration.

Theme Configuration File

Enable the Algolia service.

Blog Main Configuration File

algolia:
  appId:
  applicationID:
  apiKey:
  adminApiKey:
  chunkSize: 5000
  indexName: my_blog
  fields:
    - content:strip:truncate,0,500
    - excerpt:strip
    - gallery
    - permalink
    - photos
    - slug
    - tags
    - title

Notes

  • No need to install npm install --save hexo-algolia as mentioned on the Next official website; I recommend npm install hexo-algoliasearch --save instead. Skip this if already installed.
  • appId and applicationID have the same value. The reason for having both is that the configuration items required for site content indexing are inconsistent with those in the theme template, possibly due to version mismatches. I don’t want to check the details; it’s not important.

Index Generation

$ export HEXO_ALGOLIA_INDEXING_KEY=xxxx
$ hexo algolia

Note: The default shell on Windows does not support export; you can execute this in Git Bash.

After the above configuration, the search service is ready to use.

Final Thoughts

I have now tried all the search services supported by the NexT theme: local search, Swiftype, and Algolia. If Algolia also fails, I will have to build a custom search service. Let’s wait for that need to arise.

References

Authors
Developer, digital product enthusiast, tinkerer, sharer, open source lover