I am using the pg_search gem in Rails 4.2 to search names in a model. I have the following:
pg_search_scope :search_for_dashboard,
lambda { |q|
{
against: [:name, :email, :description],
using: {
tsearch: {
prefix: true
}
},
ignoring: :accents,
query: q
}
}
If I type ad
or Ad
, I get results with 'Adnan' and 'Adrian'. What I want is that if I type an
I also get the same results. Or if I type dnan
I get 'Adnan'. Is that possible with pg_search?
I'm the author of pg_search.
One way you could get postfix searching to work would be to use trigram search instead of tsearch. Trigram searches work against any part of the string.
Alternatively, it would be possible to add a
postfix
option for tsearch that works similarly toprefix
, but that would require adding new functionality to the gem.