【问题标题】:Sunspot Solr Boost on text field文本字段上的 Sunspot Solr Boost
【发布时间】:2018-11-19 13:13:51
【问题描述】:

我想根据任何文本字段提升结果中的文档。

例如。考虑以下模式

class Post < ActiveRecord::Base
  searchable do
    text :title, :body
    text :comments do
      comments.map { |comment| comment.body }
    end
    text :tags
    boolean :featured
  end
end

要提升布尔字段,我们可以像这样简单地添加一个 boost 子句:

Post.search do
  fulltext '*:*' do
    boost(2.0){with(:featured, true)}
  end
end

我想在文本字段上实现提升,假设我想获取所有帖子,但标记为“重要”的帖子必须先出现,如下所示:

Post.search do
  fulltext '*:*' do
    boost(2.0){fulltext 'important', fields: :tags}
  end
end

我知道上面的代码不正确,但解释了所需的行为。

【问题讨论】:

    标签: ruby-on-rails solr sunspot sunspot-solr solr-boost


    【解决方案1】:

    试试这个

       Post.search do
          fulltext '*:*' do
             boost(2) { with(:tags).equal_to('important') }
          end
        end
    

    【讨论】:

      猜你喜欢
      • 2012-01-01
      • 1970-01-01
      • 2014-10-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-13
      • 2012-06-10
      • 1970-01-01
      相关资源
      最近更新 更多