Ruby on rails 模型中的Rails条件,以便使用太阳黑子solr对结果进行排序

Ruby on rails 模型中的Rails条件,以便使用太阳黑子solr对结果进行排序,ruby-on-rails,solr,model,Ruby On Rails,Solr,Model,目前我正在使用solr在数据库中进行搜索。 我想按日期排序 问题:日期在数据库中序列化为数组,因为它可以本地化 然后,我的逻辑将查找特定于国家的条目,如果没有,则使用默认条目 所以它可以是这样的: [{"DE" => "localizeddate"}, {"EN" => "localizeddate"}, ...] [{"default" => "defaultdate"}] 或者像这样: [{"DE" => "localizeddate"}, {"EN" =&g

目前我正在使用solr在数据库中进行搜索。 我想按日期排序

问题:日期在数据库中序列化为数组,因为它可以本地化

然后,我的逻辑将查找特定于国家的条目,如果没有,则使用默认条目

所以它可以是这样的:

 [{"DE" => "localizeddate"}, {"EN" => "localizeddate"}, ...]
[{"default" => "defaultdate"}]
或者像这样:

 [{"DE" => "localizeddate"}, {"EN" => "localizeddate"}, ...]
[{"default" => "defaultdate"}]
现在,我的班级看起来像这样

class Product < ActiveRecord::Base
serialize :colors, Array
serialize :variants, Array
serialize :images, Array
serialize :sizes, Array
serialize :online_from, Array


searchable do

    text :dw_productid, :display_name, :short_description       
    time :online_from # This is the date that solr will pick up for sorting
end
end
类产品
问题是我不能把
:online\u从
传递到solr。
如何在此处插入逻辑?我在模型中是否这样做

谢谢


本杰明

我终于想出了办法:

因此,在可搜索的方法中,您可以添加
time:something do
,以便用它做更多的事情

类产品
serialize :colors, Array
serialize :variants, Array
serialize :images, Array
serialize :sizes, Array
serialize :online_from, Array



searchable do

    text :dw_productid, :display_name, :short_description       

    # Sort products according to the online from date
    time :online_from do |onlinefromdate|
        if onlinefromdate.online_from[0] != nil
            @onlinefromdate = onlinefromdate.online_from[0]["DE"] if onlinefromdate.online_from[0]["DE"] != nil
            @onlinefromdate = onlinefromdate.online_from[0]["default"] if onlinefromdate.online_from[0]["default"] != nil
            @onlinefromdate = onlinefromdate.online_from[0][0]
        else
            @onlinefromdate = Date.parse('2001-02-03')
        end
    end
end
end