Solr/Lucene is it possible to order first by relevance, and then by a second attribute?

半城伤御伤魂 提交于 2019-12-05 17:53:49

问题


In Solr/Lucene is it possible to order first by relevance, and then by a second attribute?

As far as I can tell if I set an ordering parameter, it totally overrides relevance, and sorts by the ordering parameter(s).

How can I have results sorted first by relevance, and then in the case of two entries with exactly the same relevance, giving the nod to the item that, say, comes first alphabetically.

If it makes any difference I'm using Solr through Sunspot in Ruby on Rails.


回答1:


Solved my own problem!

The keyword score can be passed to order the result by relevancy.

So in Rails Sunspot terms:

Article.search do
  keywords params[:query]
  order_by :score, :desc
  order_by :name, :asc
end


来源:https://stackoverflow.com/questions/3705109/solr-lucene-is-it-possible-to-order-first-by-relevance-and-then-by-a-second-att

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!