太阳黑子 order_by 排序,nil 值排在最后

发布于 12-26 22:42 字数 144 浏览 3 评论 0原文

我正在尝试按价格从小到大的值对太阳黑子搜索结果进行排序。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

冰魂雪魄2025-01-02 22:42:45

将属性“sortMissingLast=true”添加到 schema.xml 中价格字段的定义中

add an attribute "sortMissingLast=true" to the price field's definition in the schema.xml

你对谁都笑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

Yeah, you should should add sortMissingLast=true to the field in schema.xml, something like this:

<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>

Then in your code you can do this:

class MyModel < ActiveRecord::Base
  searchable do
    integer :price, as: :price_sml_int
  end
end
酒中人2025-01-02 22:42:45

schema.xml 中字段的 fieldType 中使用属性 sortMissingLast="true"

重新启动 solr 服务器。

(隐式默认值为 false。)

Use property sortMissingLast="true" in fieldType of the field in schema.xml.

Restart solr server.

(Implicit default value is false.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文