【问题标题】:Rails 4 - PG Search not returning exact match with tagsRails 4 - PG搜索不返回与​​标签完全匹配的标签
【发布时间】:2015-12-27 19:51:16
【问题描述】:

在 Rails 4 上,充当可标记的 gem。我的搜索目前没有首先返回完全匹配。似乎标签的权重不正确。当我摆脱 :associated_against => { :tags => {:name => 'D'}} 时,首先返回完全匹配。有没有人遇到过这个问题?有什么建议吗?

这是我的搜索范围:

pg_search_scope :search, :against => { :specific => 'A', :title => 'B', :aka => 'B'},
                        :associated_against => { :tags => {:name => 'D'}},
                        :using => { dmetaphone: {}, tsearch: { dictionary: 'english' }, 
                        trigram: {:threshold => 0.3} },
                        ignoring: :accents

【问题讨论】:

    标签: ruby-on-rails ruby ruby-on-rails-4 tags pg-search


    【解决方案1】:

    您能否将其余代码发布到控制器等中。我的应用程序中有以下内容:

    # tools.rb    
    include PgSearch
            pg_search_scope :search_including_tags,
            :against => [:description, :barcode],
            :associated_against => {:tags => [:name] }
    

    然后在我的控制器中搜索我有:

    #tools_controller.rb
        def index
            if params[:search]
              @tools = Tool.where("(barcode) LIKE (?)", "%#{params[:search]}")
            elsif params[:tag]
              @tools = Tool.tagged_with(params[:tag])
            elsif params[:id]
              @tool = Tool.find(params[:id])
            else
              @tools = Tool.all
              @tool = Tool.first
            end
          end
    

    最后是我的搜索控制器

    def new
      @tools = Tool.search_including_tags(params[:query])
    end
    

    希望这会有所帮助。如果没有看到所有的代码,真的不能说太多。但我最终使用了这个有效的方法::associated_against => {:tags => [:name] }

    【讨论】:

      猜你喜欢
      • 2011-09-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-05
      • 1970-01-01
      相关资源
      最近更新 更多