太阳黑子 order_by 排序,nil 值排在最后
我正在尝试按价格从小到大的值对太阳黑子搜索结果进行排序。
order_by :price, :asc
然而,有些物品的价格为零。它们被放置在结果的前面。有没有一种好的方法可以在最后显示它们而不是将它们遗漏?
I am trying to order the Sunspot search results by price from the smaller to bigger values.
order_by :price, :asc
However there are some items which have nil price values. They are placed at the front of results. Is there a good way to display those at the end instead of leaving them out?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

发布评论
评论(3)
你对谁都笑2025-01-02 22:42:45
是的,您应该将 sortMissingLast=true 添加到 schema.xml 中的字段,如下所示:
<schema name="sunspot" version="1.0">
<types>
...
<!-- My custom types -->
<fieldType name="sml_int" class="solr.SortableIntField" sortMissingLast="true" omitNorms="true"/>
</types>
<fields>
...
<!-- My custom fields -->
<dynamicField name="*_sml_int" type="sml_int" multiValued="false" indexed="true"/>
</fields>
...
</schema>
然后在您的代码中您可以执行以下操作:
class MyModel < ActiveRecord::Base
searchable do
integer :price, as: :price_sml_int
end
end
~没有更多了~
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
将属性“sortMissingLast=true”添加到 schema.xml 中价格字段的定义中
add an attribute "sortMissingLast=true" to the price field's definition in the schema.xml