繁体   English   中英

按列权重结果对Elasticsearch进行排序,并使用Rails项目的轮胎gem

[英]Sorting elasticsearch by column weight results with tire gem for rails project

def self.search(params)
  return [] unless params[:query].present?
   tire.search(load: true) do
   query { string(params[:query], fields: %w(title description topics     
   username discussions)) }
  sort do
    by "likes", "desc"
    by "badges_count", "desc"
  end
  facet :tags do
    terms :tags
  end

  facet :topics do
    terms :topics
  end

    size params[:size] || 5
   end.results
end

我正在尝试对特定模型进行搜索。 尽管当前结果是根据最喜欢的排序,但我还是希望对排序块中的每一列都以百分比为基础。

例如:

基于另一列中的语义匹配强度,“喜欢”为50%(:header)基于“ badges_count”为“ badges_count”为20%

任何帮助都将是巨大的,因为我对如何进一步扩展块并创建按重量排序的迷你算法有些困惑。

使用增强选项索引您的列。 例如:

class YourParticularModel
  mapping do
    indexes :likes,           boost: 100
    indexes :badges_count,    boost: 40
    # .... other indexes
  end
end

然后从您的搜索方法中删除排序。 查询结果将自动为点赞和badges_count匹配加权。

暂无
暂无

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

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