#global search

1 messages · Page 1 of 1 (latest)

shy halo
#

How I can implement global search?
I have frontend in Nextjs I have connect frontend to payload using rest api.

There is one search bar to handle all queries.
It should find or search in all the collections.

I have tried to install search plugin but it failed. I am using 3.0 beta

ebon kayakBOT
gaunt dagger
shy halo
#

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

gaunt dagger
#

Remind me again - are you using v2 or v3?

shy halo
#

V3

gaunt dagger
#

Alright, so with v3 you want to do something like:
npm i @payloadcms/plugin-search@beta --legacy-peer-deps

shy halo
#

Perfect 🤩 that worked
Thanks man
You are awesome
You are helping me a lot

gaunt dagger
#

My pleasure!

shy halo
#

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

gaunt dagger
#

Yes exactly

shy halo
#

Okay i will explore it and let you know if i need help
Thank you

cosmic tinsel
#

the search page itself is entirely server rendered too

gaunt dagger
#

Listen to Paul. Paul knows best

shy halo
#

Yes i needed reference
Perfect thank you

shy halo
#

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

gaunt dagger
#

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.

shy halo
#

Ouch... I was scratching my head 6 hours and you solved it within seconds. Thanks man for helping me

gaunt dagger
#

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

shy halo
#

I appreciate it

unique hare
sterile crow
#

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

gaunt dagger
#

By default a collection with slug search is created

unique hare
#

What does this telll me?

#

Can I use it with a wildcard?

gaunt dagger
#

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

unique hare
#

Lets say I want to search for query%

#

Is this what this like does?

#

I need to query all names that start with query

gaunt dagger
#

I believe like is similar but not exactly that, might be sufficient for you

unique hare
#

so what character would be the % sign in this case?

gaunt dagger
#

You wouldn't include the "wildcard" character, you would just type query

unique hare
#

i tried that but i returned moore

gaunt dagger
#

There is no wildcard mechanism as you're describing afaik

unique hare
#

in sql LIKE is used with wildcard % or ?

#

So that's different here then?

#

where dog like 'pit%'

gaunt dagger
#

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?

unique hare
#

Any clue @rigid prawn ?