Integrating Full Text Search with supabase

Hi, I have few questions regarding implementation of Supabase full text search, I was reading the docs here https://supabase.com/docs/guides/database/full-text-search#to_tsvector Currently I have custom react hook function:
const getFullTextSearchIngredients = async (
queryString: string | undefined
) => {
let query = supabase
.from<SupabaseIngredient>('ingredients')
.select(
'*',
{
count: 'exact'
}
)
.order('popularity', { ascending: false })
.limit(20);

if (queryString) {
query = query.textSearch('product_name', queryString, {
type: 'phrase'
});
}

const { data, count, error } = await query;

if (error) {
throw new Error(`${error.message}: ${error.details}`);
}

if (count === 0) {
return null;
}
return data;
};
const getFullTextSearchIngredients = async (
queryString: string | undefined
) => {
let query = supabase
.from<SupabaseIngredient>('ingredients')
.select(
'*',
{
count: 'exact'
}
)
.order('popularity', { ascending: false })
.limit(20);

if (queryString) {
query = query.textSearch('product_name', queryString, {
type: 'phrase'
});
}

const { data, count, error } = await query;

if (error) {
throw new Error(`${error.message}: ${error.details}`);
}

if (count === 0) {
return null;
}
return data;
};
I pictured an example query, if you have a look "Chicken, broiler or fryes, breast, skinless..." should've been retrieved in both queries, but is only present in the first one. Now, I do realise that the ingredient name is very obscure and could be renamed, however as I was reading docs there were different functions mentioned such as: to_tsvector() to_tsquery() @@. I don't understand what they do, but can they be included in supabase javascript method .textSearch() to improve the search? Or is it just postgres limitations and I should simply rename the ingredients 😁
Full Text Search | Supabase
How to use full text search in PostgreSQL.
No description
1 Reply
garyaustin
garyaustin3y ago
You probably want to use plain instead of phrase This section mentions the difference when describing how websearch works: https://supabase.com/docs/reference/javascript/textsearch#websearch This is the Postgres description of details. https://www.postgresql.org/docs/current/textsearch-controls.html
PostgreSQL Documentation
12.3. Controlling Text Search
12.3. Controlling Text Search 12.3.1. Parsing Documents 12.3.2. Parsing Queries 12.3.3. Ranking Search Results 12.3.4. Highlighting Results To implement full text …
textSearch() | Supabase
Only relevant for text and tsvector columns. Match only rows where

Did you find this page helpful?