简体   繁体   中英

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

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:(

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

create or replace function search_posts(keyword text)
returns setof posts
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]' })

You can read more about textSearch here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM