A
A
Anton2016-01-28 14:03:27
PostgreSQL
Anton, 2016-01-28 14:03:27

How to implement partial word search in PostgreSQL for a RoR project?

Hello!
Can you please tell me how to implement a search in a table for a specific field using part of a word?
For example, for the query "mar", I should display the names:
- Mark
- Lamar
- Maria
- Margot
Tried this gem - https://github.com/Casecommons/pg_search , but the problem is that with it I could only implement the search by whole name. That is, at the request "Margo" it will give me all Margo, and at the request "mar" there will be emptiness (there are no records in the table).
I would be very grateful if you could suggest a suitable gem or implementation using pg_search. Well, or there are some other alternatives for implementing this idea.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
Jeiwan, 2016-01-28
@hummingbird

query = "мар"
User.where("name ILIKE '%?%'", query)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question