Skip to content

Commit ebbd6ad

Browse files
JianJrohpaulpopus
andauthored
feat(plugin-search): pass collection slug to beforeSync hook (#11581)
The following is the use case. ```typescript plugins: [ searchPlugin({ collections: ['products', 'posts'], beforeSync: ({ originalDoc, searchDoc,collectionSlug }) => { return { ...searchDoc, title: collectionSlug === 'products' ? originalDoc.name : originalDoc.title, } }, }), ] ``` --------- Co-authored-by: Paul Popus <paul@payloadcms.com>
1 parent b278a17 commit ebbd6ad

2 files changed

Lines changed: 2 additions & 0 deletions

File tree

packages/plugin-search/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export type DocToSync = {
1919
}
2020

2121
export type BeforeSync = (args: {
22+
collectionSlug: string
2223
originalDoc: {
2324
[key: string]: any
2425
}

packages/plugin-search/src/utilities/syncDocAsSearchIndex.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export const syncDocAsSearchIndex = async ({
7979
})
8080
}
8181
dataToSave = await beforeSync({
82+
collectionSlug: collection,
8283
originalDoc: docToSyncWith,
8384
payload,
8485
req,

0 commit comments

Comments
 (0)