[英]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
I'm attempting to perform a search on a particular model. 我正在尝试对特定模型进行搜索。 Although the results are currently sorting based on the most likes, and I'd like to base it more on a percentage basis for each column in the sort block.
尽管当前结果是根据最喜欢的排序,但我还是希望对排序块中的每一列都以百分比为基础。
for example: 例如:
50% for "likes" based on strength of semantic match in another column(:header) 20% for "badges_count" based on "badges_count" 基于另一列中的语义匹配强度,“喜欢”为50%(:header)基于“ badges_count”为“ badges_count”为20%
Any help would be great as I am a bit stuck on how to expand the block more and create a mini algorithm to sort based by weight. 任何帮助都将是巨大的,因为我对如何进一步扩展块并创建按重量排序的迷你算法有些困惑。
Index your columns with boost options. 使用增强选项索引您的列。 ex:
例如:
class YourParticularModel
mapping do
indexes :likes, boost: 100
indexes :badges_count, boost: 40
# .... other indexes
end
end
Then remove sort from your search method. 然后从您的搜索方法中删除排序。 The query result will auto weight the likes and badges_count matches.
查询结果将自动为点赞和badges_count匹配加权。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.