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;
1条答案
按热度按时间mnowg1ta1#
You could create a SQL function to perform search like this:
You can call this function like this:
You can read more about textSearch here