Techiio-author
Started by Lidig TinilaloSep 18, 2021

Open
Is there a way to perform full text search on multiple columns on Supabase with Javascript?

4 VIEWES 0 LIKES 0 DISLIKES SHARE
0 LIKES 0 DISLIKES 4 VIEWES SHARE

I've tried using many symbols to separate columns; ||, |, &&, & with and without spaces.

For instance

.textSearch("username, title, description", "...");
.textSearch("username|title|description", "...");

And nothing has worked :(

1 Replies

Techiio-commentatorPeter Daniels replied 3 months ago0 likes0 dislikes

You could make a SQL function to perform a search like this:

create or replace function search_posts(keyword text)
returns table([YOUR_TABLE_DEFINITION])
as
$func$
select 
  * 
from 
  posts
where 
  to_tsvector(username || ' ' || title || ' ' || description) -- concat columns, but be sure to include a space to separate them!
  @@ to_tsquery(keyword);
$func$
language sql;

You can call this function like this:

const {data, error} = await supabase.rpc('search_posts', { keyword: '[YOUR_SEARCH_TERM_HERE]' })

I think this solution solves your problem....!

You must be Logged in to reply
Techiio-logo

Techiio is on the journey to build an ocean of technical knowledge, scouring the emerging stars in process and proffering them to the corporate world.

Follow us on:

Subscribe to get latest updates

You can unsubscribe anytime from getting updates from us
Developed and maintained by Wikiance
Developed and maintained by Wikiance