[英]Searchkick search based on user saved recipes
使用 searchkick 处理一些搜索查询,并且无法弄清楚如何设置 searchkick 搜索以获得我想要的结果。 因此,用户可以保存食谱,并且食谱具有与之关联的标签。 我想从他们保存的食谱中获取所有标签,并搜索具有相同标签的食谱,并根据标签出现的次数对标签进行加权。
所以要获得标签,我可以这样做:
tags = Tagging.where(taggable_id: current_user.saved_recipes.pluck(:recipe_id)).group(:tag_id).count
这将返回如下内容:
{23=>1, 56=>1, 27=>2, 30=>1, 28=>1, 36=>1, 39=>1, 16=>1}
我只是不确定如何传递该数组来加权数字,因此在这种情况下,标签 27 的权重将高于 rest。 我在 elasticsearch 索引中搜索的字段是:tags。
Recipe.search "*", where: [tags: tag]
这就是我的想法,但标签的 hash 有这些数字,不知道如何提高结果。 希望这很清楚
您可以尝试使用boost_where
选项,它允许您针对不同的值通过不同的因子来提升结果。
具体来说,在您的情况下,您可以尝试:
tags = Tagging.where(taggable_id: current_user.saved_recipes.pluck(:recipe_id)).group(:tag_id).count
# Boost any tags with count greater than 1
boost_values = tags.select { |k, v| v > 1 }.map { |k,v| {value: k, factor: v * 10} }
Recipe.search "*", where: [tags: tag], boost_where: {tags: boost_values}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.