Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 太阳黑子solr,顺序_被整数值完全打破_Ruby On Rails_Ruby_Solr_Sunspot Rails - Fatal编程技术网

Ruby on rails 太阳黑子solr,顺序_被整数值完全打破

Ruby on rails 太阳黑子solr,顺序_被整数值完全打破,ruby-on-rails,ruby,solr,sunspot-rails,Ruby On Rails,Ruby,Solr,Sunspot Rails,我在使用太阳黑子宝石时遇到问题 我正在使用git的最新gem(2.1.1也在2.1.0中试用过),我试用过solr版本-3.2、3.5、4.2、4.9 问题是按整数值排序完全不起作用 我的代码是: @ads = Ad.solr_search do paginate :page => params[:page], :per_page => 10000 #just for debug, not working with 25 as well order_by :

我在使用太阳黑子宝石时遇到问题

我正在使用git的最新gem(2.1.1也在2.1.0中试用过),我试用过solr版本-3.2、3.5、4.2、4.9

问题是按整数值排序完全不起作用

我的代码是:

   @ads = Ad.solr_search do
     paginate :page => params[:page], :per_page => 10000 #just for debug, not working with 25 as well
     order_by :priority, :desc
   end
searchable do
  ...
  integer :priority
  time(:priority_to_time){DateTime.new(2014, 1, 1, 0, 0, 0) + self.priority}
end
在模型中,太阳黑子由以下代码初始化:

searchable do
  text :search_name
  text :search_description
  integer :id
  integer :state_id
  integer :city_id
  integer :district_id
  boolean :moderated
  integer :category_id
  integer :priority
  integer :price_index
  latlon(:location) { Sunspot::Util::Coordinates.new(lat, lon) }
  integer :ad_type_id
  boolean :active
  time :created_at
end
结果是一团糟-

我希望具有最高优先级的广告将首先显示,但相反,它们会在最后(!)页上无序显示

有趣的是——当我应用更多的过滤器时——比如价格、城市id、州id和其他——要么开始正常工作,要么至少不太难出错(比如第一页显示的优先级记录,但仍然有一些被洗牌)。但我应用的过滤器越少,排序就越多,直到完全损坏为止

我试过用谷歌搜索类似的问题,但没有发现任何东西,也试过了所有可能影响问题的东西——不同的solr版本,不同的gem版本,试过稍微修改代码(不过修改不多,复制第三期代码就够了)——没有任何改变行为。我大概做了30次reindex——每次我都尝试了不同的版本

有人能建议如何解决这个问题,或者至少还有什么可以尝试的吗


提前谢谢

我也有同样的问题。按整数类型排序不起作用

所以我用了一种有点狡猾的方法。这不是个好办法。但在修复bug之前,它将是临时的替代方案

按时间排序的类型运行良好。所以整数转换成时间

我的代码是:

   @ads = Ad.solr_search do
     paginate :page => params[:page], :per_page => 10000 #just for debug, not working with 25 as well
     order_by :priority, :desc
   end
searchable do
  ...
  integer :priority
  time(:priority_to_time){DateTime.new(2014, 1, 1, 0, 0, 0) + self.priority}
end
搜索代码中的

Post.search do
  ...
  order_by(:priority_to_time, :desc)
end
是的,这是非常奇怪的代码。但它是有效的


如果有人有更好的想法,请为我们提供建议。

默认情况下,太阳黑子的排序结果是“分数”,因此添加额外的行:

order_by(:score, :desc)
order_by :priority, :desc

这会有用的

太阳黑子解决过这个问题吗?非常感谢,为我工作,无法在整数字段上使用order by。