I'm using SearchKick with elastic search, and am trying to return the score. For example, if I did a search like this:
Profile.search("NYC").first
I'm going to get back the record with the highest score that matches that search. I want to also return the score with each record. I know I can grab the searchkick response and parse though it, but is there a faster way to just merge the score into the records that are returned?
答案 0 :(得分:3)
要获得具有相应分数的所有个人资料,请执行以下操作:
results = Profile.search("NYC")
results_with_scores = results.zip(results.hits.map{ |hit| hit["_score"] })
现在results_with_scores
的每个元素都是以下形式:
`[Profile_object, corresponding_score]`
答案 1 :(得分:3)
使用SearchKick v2.0.1或更高版本,您可以执行以下操作:
Profile.search("NYC").first.search_hit['_score']