Rails3 SOLR sort order using a child field

邮差的信 提交于 2019-12-12 03:45:27

问题


I have a working search using SOLR in a Rails 3 app. My controller returns results in pubdate order. I am trying to sub-order by the Section.name. How can I add the child field to the order-by syntax?

Here is my code:

@stories = Story.search do
    paginate(:page => params[:page])
    order_by :pubdate, :desc
    order_by :section_id                <---want to suborder by Section.name
    fulltext params[:search_query]
end

回答1:


You would need to add the section name to the parent field to be able to sort it using the Section name.
You can check on Solr Join feature for any JIRA to enable sorting on the Child fields.

Documentation mentions :-

For people who are used to SQL, it's important to note that Joins in Solr are not really equivalent to SQL Joins because no information about the table being joined "from" is carried forward into the final result. A more appropriate SQL analogy would be an "inner query"



来源:https://stackoverflow.com/questions/14204316/rails3-solr-sort-order-using-a-child-field

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