fix(plugin-search): customizable search collection slug
Description
I have a custom search enpoint in my payload backend. After adding the this plugin, the collection api of the generated "search" collection overrides the custom endpoint. So I wanted to override the collection slug but the default name was hardcoded at many locations. This fix should allow to override the default slug.
- [x] I have read and understand the CONTRIBUTING.md document in this repository.
Type of change
- [ ] Chore (non-breaking change which does not add functionality)
- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] Change to the templates directory (does not affect core functionality)
- [ ] Change to the examples directory (does not affect core functionality)
- [ ] This change requires a documentation update
Checklist:
- [ ] I have added tests that prove my fix is effective or that my feature works
- [ ] Existing test suite passes locally with my changes
- [ ] I have made corresponding changes to the documentation
Hello, any update on this fix? Having the same issues
Hey @louisnt,
You can already customize the search collection slug via the searchOverrides property passed directly into the plugin config.
Hey @louisnt,
You can already customize the
searchcollection slug via thesearchOverridesproperty passed directly into the plugin config.
Thank you for the quick reply. Yes, the issue in the latest version of the plugin is that the 'search' slug is hardcoded, ignoring the searchOverride config.
Not sure how we can bump this PR?
try {
if (operation === 'create') {
if (doSync) {
await payload.create({
collection: 'search',
data: {
...dataToSave,
priority: defaultPriority
},
req
});
}
}
if (operation === 'update') {
try {
// find the correct doc to sync with
const searchDocQuery = await payload.find({
collection: 'search',
depth: 0,
req,
where: {
'doc.relationTo': {
equals: collection
},
'doc.value': {
equals: id
}
}
});
Version
"@payloadcms/plugin-search": "3.0.0-beta.117",
Hey @louisnt,
So, this PR seeks to make changes to the main branch which is for Payload V2. It seems, by your version of the plugin, that you're on V3 in which case this PR would not impact you. I see what you're saying though - it does indeed seem that the slug is hardcoded in the hooks, even for V3.
This pull request was automatically closed due to lack of activity.
If you believe this PR is critical, please resolve all merge conflicts and re-open it.
If this is a feature, please create a new PR against the latest codebase.
Thank you for being part of the Payload community! 🙌