最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin6浏览0评论

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

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

Share Improve this question edited Sep 17, 2021 at 14:55 Lunandd asked Sep 17, 2021 at 14:48 LunanddLunandd 551 silver badge6 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

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

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论