#Search defaultFields error

20 messages · Page 1 of 1 (latest)

nimble schooner
#

I'm trying to add a search bar and I have this so far

searchPlugin({
collections: ['products'],
searchOverrides: {
fields: ({ defaultFields }) => {
return [
...defaultFields,
{
name: 'description',
type: 'textarea',
label: 'Description',
},
]
},
},
}),

When I added the

({ defaultFields }) => {

It turns red (underlined) in visual studio code and my website dosn't load anymore. I have no clue how to fix this.

thorn lagoonBOT
jaunty wing
#

Hello, to fix your website so it work as before or to make searchPlugin works as expected?

nimble schooner
jaunty wing
#

you might be need the slug:
slug: 'search-results',

  searchPlugin({
    searchOverrides: {
      slug: 'search-results',
      fields: ({ defaultFields }) => [
        ...defaultFields,
        {
          name: 'excerpt',
          type: 'textarea',
          admin: {
            position: 'sidebar',
          },
        },
      ],
    },
  }),
nimble schooner
#

So I have some products on payload and I wt people to be able to search for those products. All the products have a title and a discription. The searchPlugin gets the title from the product but it doesn't get any description cause I haven't added it. So when I try to add it it doesn't work.

jaunty wing
#

your description is richText?

nimble schooner
jaunty wing
#

hmm, probably yes then. I think best way to solve it is to have additional description for search. You can sync them

nimble schooner
#

How do I do that? I'm really new to this.

jaunty wing
#

do you writing product names / descriptions by your self or syncing with POS?

nimble schooner
jaunty wing
#

you can add in your Products collection like searchDescription field and then with hook on change, you can transform the rich text lexical

jaunty wing
#

if you need just text you can go Products and to change the type

nimble schooner
#

I'm just watching this tutorial https://www.youtube.com/watch?v=XGyDU8XZRG4&ab_channel=AllAboutPayload

And it says I have to add this so when I click the product in the search result tab (under collections) it shows description so it would help with searching. I'm stuck at the part to add ths description field. I even red the documention and it says I have to add this field using defaultFields but when I try to add that field the page turns white.

In this video, we dive into search implementation in Payload CMS, exploring different options and focusing on the official Payload Search Plugin. We cover why search is critical, the advantages of using the plugin, and step-by-step implementation. You’ll also learn how to optimize search for performance, relationship data, and multi-collection q...

▶ Play video
nimble schooner