我正在尝试按价格从小到大对太阳黑子搜索结果进行排序。
order_by :price, :asc
但是,有些商品的价格值为零。它们位于结果的前面。有没有一种好方法可以在最后显示它们而不是将它们排除在外?
我正在尝试按价格从小到大对太阳黑子搜索结果进行排序。
order_by :price, :asc
但是,有些商品的价格值为零。它们位于结果的前面。有没有一种好方法可以在最后显示它们而不是将它们排除在外?
向 schema.xml 中价格字段的定义添加属性“sortMissingLast=true”
在schema.xml中字段的 fieldType 中使用属性sortMissingLast="true"。
重启 solr 服务器。
(隐式默认值为 false。)
是的,您应该将 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