Algolia Search
Integrate Algolia Search with Next Docs
Notice: If you're using Algolia's free tier, you have to display their logo on your search dialog.
Indexing
The default behavior creates a record for each paragraph in your document which officially recommended by Algolia.
Each record contains searchable attributes title
, section
, and content
.
section
is optional, it only exists in paragraphs under headings. Headings and
paragraphs are all indexed as a record, and the attribute for distinct is
page_id
.
Setup
-
Install
algoliasearch
-
Sign up and obtain the required API keys for your search. Store these credentials in environment variables.
-
Create and sync your index with the
sync
function.You may make it a script and manually sync with
node ./update-index.mjs
, or integrate it with your CI/CD pipeline. -
To search documents on the client side, you may use the search dialog provided by Next Docs UI, or implement your own for advanced styling.
In addition, you can use the
useAlgoliaSearch
hook which handles loading states with SWR.
Customise Attributes & Settings
While the default attributes might not suit your case, you can pass extra_data
to index options for adding extra fields to each record.
To customize the default index settings, set index settings, and update
documents with updateDocuments(...)
separately.
Notice that it expects the url
property of a page to be a unique value and
won't duplicated. In other words, you shouldn't have two pages with the same
url.
Last updated on