Lingquan | Blog

Add Search feature By Algolia

Word count: 233Reading time: 1 min
2019/01/11 Share

Add Search Feature By Algolia in Hexo Blog

It is pretty sample to add feature by using third-party. Algolia is one of them.

1.Sign up Algolia

Get an account in Algolia, which can be done by Github account. We can use all
features for free in 14 days and we get 100,000 free operations every month.It is
enough for personal use.

2. Create a index

Give a name for your new index. We will use it for search.

3. Install Algolia

Use the following code to install Algolia in root path of your blog folder.

npm install --save hexo-algolia

4. Get the necessary Keys

Find your Application Id, Serch-Only API key and Admin API key under API keys Tab.



5. Modify configuration file of hexo blog

We need add the following fields in our _config file.

algolia:
applicationID: ‘your applicationID’
apiKey: ‘your apiKey’
indexName: ‘your index name’
chunkSize: 5000

6. Update Index

Run the following code in root path of Hexo Blog

$ export (in windows is set) HEXO_ALGOLIA_INDEXING_KEY=’apiKey’
$ hexo algolia

7. Modify the configure file of your Theme

For example, in the theme I used, I changed the following configuration.

algolia_search:
    enable: true
    hits:
     per_page: 10
    labels:
        input_placeholder: Search for Posts
        hits_empty: "We did not find any results for the search: ${query}"
        hits_stats: "${hits} results found in ${time} ms"

Then you are done! See the effect below.



CATALOG
  1. 1. Add Search Feature By Algolia in Hexo Blog
    1. 1.1. 1.Sign up Algolia
    2. 1.2. 2. Create a index
    3. 1.3. 3. Install Algolia
    4. 1.4. 4. Get the necessary Keys
    5. 1.5. 5. Modify configuration file of hexo blog
    6. 1.6. 6. Update Index
    7. 1.7. 7. Modify the configure file of your Theme