How to use the to_tsquery function in Postgres?

Hello. configured full text search in the table provided the fts tsvector, get words, everything seems to be correct.
for example, if in the text the word "documents", then fts will get the word "document"

then look for this word:
SELECT *
FROM table
WHERE fts @@ to_tsquery('document')

finds the record you want.

if you are looking for this:
SELECT *
FROM table
WHERE fts @@ to_tsquery('document<b>S</b>')

finds nothing. to_tsquery('documents') are not converted to "document", although to_tsquery('documents') are converted into document...
Tell me what's the problem?

I have to say that Russian dictionary is connected, the word document is there, the word document is not, and I understand it should not

UPD:
select ts_lexize('ispell_ru', 'documents') gives "the document",
select to_tsquery('English', 'documents'), too. is there a way to determine automatically which dictionary to use Russian or English?
June 14th 19 at 21:01
1 answer
June 14th 19 at 21:03
Solution
select plainto_tsquery('document<b>S</b>');
select plainto_tsquery('ru', 'documents'); //Instead of 'EN' is the name of the configuration in to_tsvector which indicate when the index is created


And the function which adds the vector of how yours looks? when using to_tsvector the language indicated?
create function fts_name_vector_upd() returns trigger
LANGUAGE plpgsql
AS $$
BEGIN
 NEW.fts=setweight( coalesce( to_tsvector('English', NEW.name),"),'A') || '' ||
 setweight( coalesce( to_tsvector('English', NEW.description),"),'B') || ' ';
 RETURN NEW;
END;
$$;
1)select plainto_tsquery('documentS');
'documents'

2)
CREATE OR REPLACE FUNCTION public.table_vector_update()
 RETURNS trigger AS
$BODY$
BEGIN
 IF (TG_OP = 'UPDATE') THEN
 IF ( OLD.name <> NEW.name or OLD.text <> NEW.text or OLD.number <> NEW.number) THEN
 NEW.fts=setweight( coalesce( to_tsvector('EN', NEW.name),"),'A') || '' ||
 setweight( coalesce( to_tsvector('EN', NEW.text),"),'B') || '' ||
 setweight( coalesce( to_tsvector('EN', NEW.number),"),'D');
 RETURN NEW;
ELSE
 RETURN NEW;
 END IF;
 ELSIF (TG_OP = 'INSERT') THEN
 NEW.fts=setweight( coalesce( to_tsvector('EN', NEW.name),"),'A') || '' ||
 setweight( coalesce( to_tsvector('EN', NEW.text),"),'B') || '' ||
 setweight( coalesce( to_tsvector('EN', NEW.number),"),'D');
 RETURN NEW;
 END IF;
 RETURN NULL;
END;
- August20 commented on June 14th 19 at 21:06
then use
select plainto_tsquery('ru', 'documents');
You train yourself to 'EN' indexing - Brett.Haley commented on June 14th 19 at 21:09
,
then if the request comes from the English word what? software to track the language?

upd: select plainto_tsquery('ru', 'documents'); for some reason works correctly. we assume this is the solution, thank you - August20 commented on June 14th 19 at 21:12
, 'EN' actually is not the name of the language, is the name of the configuration! configuration we can specify several dictionaries, and so on.

I can not leave
https://postgrespro.ru/docs/postgrespro/9.6/textsearch - Brett.Haley commented on June 14th 19 at 21:15

Find more questions by tags PostgreSQL