#global search
1 messages · Page 1 of 1 (latest)
Help is on the way! To mark it as solved, use the /solve command. In the meantime, here are some existing threads that may help you:
Documentation:
Hey @shy halo,
The Search plugin was designed exactly for this use-case. Make sure you are installing the beta version of the plugin if you're using Payload@beta: https://payloadcms.com/docs/beta/plugins/search#installation
I tried
npm i @ivory fractal/plugin-search
But it giving me an error
Could not resolve dependency:
npm error peer react@"^16.8.0 || ^17.0.0 || ^18.0.0" from @payloadcms/[email protected]
@gaunt dagger
Remind me again - are you using v2 or v3?
V3
Alright, so with v3 you want to do something like:
npm i @payloadcms/plugin-search@beta --legacy-peer-deps
Perfect 🤩 that worked
Thanks man
You are awesome
You are helping me a lot
My pleasure!
So I have added searchOverrides and set slug: ‘search’
So now if i want to send search request
I should use
/api/search?where=[some text]
Is that correct?
@gaunt dagger
Yes exactly
Okay i will explore it and let you know if i need help
Thank you
we've implemented search into our website template as well using the plugin if you need a reference https://github.com/payloadcms/payload/tree/beta/templates/website/src/search
the search page itself is entirely server rendered too
Listen to Paul. Paul knows best
Yes i needed reference
Perfect thank you
I have implemented the search as the reference provided by @cosmic tinsel
But it is not able search the fields
I have created categories collection attached to my products collection
One search result collection got created automatically
If I add categories to product, it gets added in search results
If I query like /api/search?where=[galaxy] via rest api
it is responding all the entries available in search results and not filtering the data
I have copied paste from the reference and changed the collections in payload-config.ts -> plugins -> searchPlugin
What I am doing wrong?
@gaunt dagger
I have added beforeSync and fieldOverrides.ts files and copied code from reference
You're almost there!
With the search plugin, what you want to do if you're searching based off of some input text and you're trying to query product title (as you mentioned in in our previous issue on Discord) is to adjust your query to the REST api like so:
/api/search?where[title][contains]=<your-input-text-string>
Refer to the docs for more info on queries: https://payloadcms.com/docs/beta/queries/overview#rest-api
And the RESTful API: https://payloadcms.com/docs/beta/rest-api/overview
Now imagine you have thousands upon thousands of products that fit your query, it may not be practical to fetch all of them at once, so you may consider adding a limit query parameter to the end of your url to limit how many docs you're fetching, you can also add a pagination cursor, sorting, etc.
Ouch... I was scratching my head 6 hours and you solved it within seconds. Thanks man for helping me
Learning something new from scratch is tough! it takes a real software engineer to encounter roadblocks for hours on end and still have the motivation to look for solutions. I commend you for it! Keep it up! I'll be here if you need me
I appreciate it
How do I use like as startsWith? What is the wildcard character?
Also, is there a way to use this as some sort of "internal" search? I would love to have a global search inside payload to get to the desired entry in the collections configured
Have a look at how the website template deals with the like operator: https://github.com/payloadcms/payload/blob/main/templates/website/src/app/(frontend)/search/page.tsx#L21-L61
Yes for sure, you can use the collection generated by the search plugin to query all docs right in the admin ui
By default a collection with slug search is created
It shows you how to use it with a like operator exactly as you asked.
I don't know what you mean by wildcard in this context
Lets say I want to search for query%
Is this what this like does?
I need to query all names that start with query
I believe like is similar but not exactly that, might be sufficient for you
so what character would be the % sign in this case?
You wouldn't include the "wildcard" character, you would just type query
i tried that but i returned moore
There is no wildcard mechanism as you're describing afaik
in sql LIKE is used with wildcard % or ?
So that's different here then?
where dog like 'pit%'
You're right in typical sql statements, but not sure tbh, @rigid prawn knows more than I would here. Is there a way to specify how to handle wildcards?
Any clue @rigid prawn ?