Answer the question
In order to leave comments, you need to log in
What is the correct way to use the to_tsquery function in Postgres?
Hello. set up full-text search, created the fts tsvector field in the required table, words get into it, everything seems to be correct.
for example, if the word "documents" is found in the text, then the word "document" will get into fts,
then I look for this word like this:
SELECT *
FROM table
WHERE fts @@ to_tsquery('документ')
SELECT *
FROM table
WHERE fts @@ to_tsquery('документ<b>Ы</b>')
Answer the question
In order to leave comments, you need to log in
select plainto_tsquery('документ<b>Ы</b>');
select plainto_tsquery('ru', 'документЫ'); //Вместо 'ru' - название конфигурации, которое указываете в to_tsvector при создании индекса
create function fts_name_vector_upd() returns trigger
LANGUAGE plpgsql
AS $$
BEGIN
NEW.fts=setweight( coalesce( to_tsvector('russian', NEW.name),''),'A') || ' ' ||
setweight( coalesce( to_tsvector('russian', NEW.description),''),'B') || ' ';
RETURN NEW;
END;
$$;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question