0

I'm pretty new to Supabase and Postgresql as a whole. I'm attempting to add some sort of fuzzy searching ability within a table for example a list of tags that might include "Business" should be returned for a query of "Bus" or "Busness".

I have enabled the FUZZYSTRMATCH extension but can't figure out how to query in the Javascript client lib. I currently have this but it's only matching the whole word.

supabase
.from('tags')
.select()
.limit(10)
.order('tag', {ascending: true})
.textSearch('tag', `'${query}'`)
.then(({data, error}) => {
  if (error) {
    reject(error);
  } else {
    resolve(data);
  }
});
Kieran Crown
  • 307
  • 5
  • 16
  • "Bus" is a word in its own right, and could easily be an abbreviation for other words beside "business". How is any system supposed to know that the "bus" to "business" conversion is the correct one to make? Do you have a precompiled list of slang? – jjanes May 15 '23 at 14:51
  • I'm expecting some sort of logic that starts suggesting items as you type. Similar to how when you search for something in YouTube it starts suggesting titles. – Kieran Crown May 17 '23 at 10:07
  • As far as I can tell form a very brief poking, youtube only suggests fixing typos once there are no longer any exact prefix matches. So it is deploying a mixture of different strategies, (which is what I would expect them to do). – jjanes May 17 '23 at 17:23
  • 1
    If you want the query to match as you type even the user hasn't typed the entire word, you would have to go with the good old `like` filter. https://supabase.com/docs/reference/javascript/ilike – dshukertjr May 22 '23 at 06:46
  • 1
    @dshukertjr Thanks, this was exactly what I was looking for. Happy to accept an answer if you create one. If not I'll answer myself and mark as answered. Thanks! – Kieran Crown May 23 '23 at 20:14

1 Answers1

1

If you want to match against part of a word or a sentence, you might want to use the ilike filter offered by Supabase.

const { data, error } = await supabase
  .from('tags')
  .select()
  .ilike('tag', `${query}%`)
dshukertjr
  • 15,244
  • 11
  • 57
  • 94