A
A
Alexander Afanasiev2017-10-02 07:15:32
PostgreSQL
Alexander Afanasiev, 2017-10-02 07:15:32

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('документ')

finds the required entry.
if i search like this:
SELECT *
FROM table
WHERE fts @@ to_tsquery('документ<b>Ы</b>')

finds nothing. to_tsquery('documents') is not converted to "document", even though to_tsquery('documents') is converted to document...
What's the problem?
I will say right away that the Russian dictionary is connected, the word document is there, the word documents is not, and as I understand it, it should not be
UPD:
select ts_lexize('ispell_ru', 'documents') returns "document",
select to_tsquery('russian', 'documents ') too. Is there a way to automatically determine which dictionary to use, Russian or English?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Elena Stepanova, 2017-10-02
@XanderEVG

select plainto_tsquery('документ<b>Ы</b>');
select plainto_tsquery('ru', 'документЫ');  //Вместо 'ru' - название конфигурации, которое указываете в to_tsvector при создании индекса

And what does the function that adds the vector look like for you? when using to_tsvector what language is specified?
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 question

Ask a Question

731 491 924 answers to any question