A
A
Artem00712020-09-22 13:23:38
PostgreSQL
Artem0071, 2020-09-22 13:23:38

Search by means of sql?

It is necessary to organize a search for some information in the database.
Now used ilikefor such things. But it just looks for occurrences in the string and returns only those that have it.

I recently learned about full-text search . Looks cool, discards endings, searches for sentences, you can get rank.

But I ran into the problem that here it is necessary to know the exact beginning of the word, otherwise the search stops working.

In general, there is a strange thing:

-- TRUE
select to_tsvector('russian', 'съешь ещё этих мягких французских булок, да выпей чаю') @@ plainto_tsquery('russian', 'чай')

-- FALSE
select to_tsvector('russian', 'съешь ещё этих мягких французских булок, да выпей чаю') @@ plainto_tsquery('russian', 'булка')

-- FALSE
select to_tsvector('russian', 'съешь ещё этих мягких французских булок, да выпей чаю') @@ plainto_tsquery('russian', 'франц')


What is the best way to arrange a search using postgres itself (without using separate search engines like elasticSearch, etc.)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dimonchik, 2020-09-22
@dimonchik2013

plainto_tsquery('russian', 'french*')
in general, study the docks, opportunities will open

M
MaLuTkA_UA, 2020-09-23
@MaLuTkA_UA

Use trigrams, they can be used to make an inaccurate search. Here is an article on habré

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question