简体   繁体   中英

Make pg_search return results for prefixes AND postfixes

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 to prefix , but that would require adding new functionality to the gem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM