Syncs documents from selected Payload collections to Algolia using collection hooks. It is added through the plugins array with Algolia credentials and a list of collection slugs. Requires Payload 3.x. Drafts are not indexed and globals are not supported.
Algolia search plugin for PayloadCMS
Installation
npm i payload-plugin-algolia17
Stars
2
Forks
3
Open Issues
3 months ago
Last Updated
0
Weekly Downloads
v1.0.2
npm Version
26.3 KB
Unpacked Size
1
Dependencies
Trends appear after 7 days of data. Daily snapshots have not started yet.
Trends appear after 7 days of data. Daily snapshots have not started yet.
Each point is npm's rolling 7-day download count.
Health Score
Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.
Badge for your README
[](https://payloaddirectory.dev/plugins/786237326-root)<a href="https://payloaddirectory.dev/plugins/786237326-root"><img src="https://payloaddirectory.dev/badge/786237326-root.svg" alt="Payload Directory"></a>README
PayloadCMS plugin that syncs collections with Algolia search
Requires Payload 3.x (payload peer dependency).
npm i payload-plugin-algolia
At a minimum, the plugin requires Algolia credentials and a list of enabled collections.
// payload.config.ts
import { buildConfig } from 'payload'
import { AlgoliaSearchPlugin } from 'payload-plugin-algolia'
import Pages from './collections/Pages'
import Posts from './collections/Posts'
export default buildConfig({
collections: [Pages, Posts],
plugins: [
AlgoliaSearchPlugin({
algolia: {
appId: process.env.ALGOLIA_APP_ID,
apiKey: process.env.ALGOLIA_ADMIN_API_KEY,
index: process.env.ALGOLIA_INDEX,
},
collections: ['pages', 'posts'],
}),
],
// ...more config
})
generateSearchAttributesBy default, the plugin will pass the entire document through to Algolia, with two appended keys:
objectID: format ${collection}:${id} eg pages:1collection: the collection slugYou can modify search attributes by providing a custom generateSearchAttributes function:
import { type GenerateSearchAttributes } from 'payload-plugin-algolia'
interface PageRecord {
title: string
text: string
}
interface PostRecord extends PageRecord {
image: string
}
const generateSearchAttributes: GenerateSearchAttributes<PageRecord | PostRecord> = async ({
doc,
collection,
req: { payload },
}) => {
switch (collection.slug) {
case 'posts': {
if (doc.featured_image) {
const { url } = await payload.findByID({
collection: 'media',
id: doc.featured_image as number,
})
return {
...doc,
image: url,
}
}
return doc
}
default:
return doc
}
}
waitForHook
Boolean, default =false
Set to true to wait for algolia set / delete operations during the collection hooks.
The current scope of the plugin is quite limited. PRs welcome!
Drafts are not indexed. If a document is unpublished, it gets removed from search results. Otherwise, draft updates to a published document have no effect.
Globals are not currently supported for indexing.
The internal Algolia client accepts all options. Beyond that, the rest of the setup for a typical Algolia configuration is outside the scope of the plugin (setting search attributes and facets, etc).
After cloning the repo and installing dependencies, run pnpm exec simple-git-hooks to setup automatic pre-commit linting.
Tags
search
Generate fast-to-query search records from your Payload documents
10083.1k/wk45.4kv3
algolia search
Sync Payload collections to Algolia with draft-aware indexing, admin reindexing and headless React search hooks
540/wk15v3
payload meilisearch
Sync Payload collections to Meilisearch indexes on create, update and delete
320/wk39v1
payload algolia search
Sync Payload collections to Algolia with search and re-index endpoints and optional result enrichment
280/wk1v3
payload typesense
Typesense search for Payload with automatic document sync, search endpoints and a React search component
83235/wk32v3
payload related items
Related posts for Payload using BM25 and Jaccard similarity scoring, with no external AI service
410/wk3v3