Skip to content

feat(plugin-search): pass collection slug to beforeSync hook#11581

Merged
paulpopus merged 3 commits intopayloadcms:mainfrom
JianJroh:feat/pass-collection
Apr 8, 2026
Merged

feat(plugin-search): pass collection slug to beforeSync hook#11581
paulpopus merged 3 commits intopayloadcms:mainfrom
JianJroh:feat/pass-collection

Conversation

@JianJroh
Copy link
Copy Markdown
Contributor

@JianJroh JianJroh commented Mar 7, 2025

The following is the use case.

plugins: [
    searchPlugin({
      collections: ['products', 'posts'],
      beforeSync: ({ originalDoc, searchDoc,collectionSlug }) => {
        return {
          ...searchDoc,
          title: collectionSlug === 'products' ? originalDoc.name : originalDoc.title,
        }
      },
    }),
]

Comment thread packages/plugin-search/src/types.ts Outdated
@JianJroh JianJroh force-pushed the feat/pass-collection branch from 8e1ab42 to 6114008 Compare March 11, 2025 07:39
@paulpopus
Copy link
Copy Markdown
Contributor

Thank you! Looks good, we'll get this merged

@github-actions github-actions Bot added the stale label Apr 13, 2025
@github-actions github-actions Bot removed the stale label Jan 21, 2026
@github-actions github-actions Bot added the stale label Feb 20, 2026
@paulpopus paulpopus merged commit ebbd6ad into payloadcms:main Apr 8, 2026
312 of 314 checks passed
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 8, 2026

🚀 This is included in version v3.82.0

milamer pushed a commit to milamer/payload that referenced this pull request Apr 20, 2026
…adcms#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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants