简体   繁体   English

使pg_search返回前缀和后缀的结果

[英]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. 我正在Rails 4.2中使用pg_search gem来搜索模型中的名称。 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'. 如果输入adAd ,则结果为“ Adnan”和“ Adrian”。 What I want is that if I type an I also get the same results. 我想要的是,如果键入an我也会得到相同的结果。 Or if I type dnan I get 'Adnan'. 或者,如果我输入dnan “ Adnan”。 Is that possible with pg_search? pg_search有可能吗?

I'm the author of pg_search. 我是pg_search的作者。

One way you could get postfix searching to work would be to use trigram search instead of tsearch. 使后缀搜索起作用的一种方法是使用Trigram搜索而不是tsearch。 Trigram searches work against any part of the string. Trigram搜索针对字符串的任何部分起作用。

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. 或者,可以为tsearch添加一个postfix选项,该选项的工作方式与prefix相似,但是这需要向gem添加新功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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