Search using multiple search parameters

System Information
  • Strapi Version:
  • Operating System:
  • Database:
  • Node Version:
  • NPM Version:
  • Yarn Version:

Hi, all.

I have created a search based on multiple params

export async function getServerSideProps({ query: searchTerm }) {
  const query = qs.stringify(
    {
      filters: {
        $or: [
          {
            name: {
              $contains: searchTerm,
            },
          },
          {
            venue: {
              $contains: searchTerm,
            },
          },
          {
            performers: {
              $contains: searchTerm,
            },
          },
        ],
      },
    },
    {
      // encodeValuesOnly: true, // prettify URL
    }
  );

 const res = await fetch(`${API_URL}/api/events?filters${query}`);
  console.log(query);
  const events = await res.json();

  return {
    props: { events },
  };
}

For my search with multiple params, above, I get an error (500)


However, If I run this search with a single param in insomnia I get a return value based on the search term

http://localhost:1337/api/events?filters[name][$contains]=man

Can anyone see anything wrong with my multi-search params query? I have followed the documentation so not too sure why it is bringing back nothing.

Ok. Looks like the issue is fixed.
This

({ query: searchTerm })

Needed changing to this:

({ query: { searchTerm} })

This seems to have resolved the issue I have been struggling with for hours!

1 Like

Glad you got it sorted :blush::+1: