Search code examples
next.jssupabase

How do I make a search function for my Next.js web app that uses Supabase


So, I have a database of people. I want to have a search functionality for the database in the web app.

I tried using the Full Text Search functionality described here: https://supabase.com/docs/guides/database/full-text-search

But it only works for entire words when I want it to work letter by letter. For example, I am using the last name of the people as my column that I want to search. If the list of last names is ['Adams', 'Charles', 'Brown'] when I type C, it should return ['Charles'].

Thank you for any help you can contribute!


Solution

  • You can use iLike() filter.

    const { data, error } = await supabase
      .from('people')
      .select()
      .ilike('name', '%Ch%') // Will return any people where `name` contains `Ch` such as Charles