我在集成Rails时遇到了一些问题。 3.2.13,轮胎0.6.0,弹性搜索0.90.2和延迟作业3.0.5。
当我尝试使用延迟作业推迟索引操作时,索引正常,但忽略了搜索排序。如果我用rake环境轮胎重新索引整个索引:import:all,一切正常。
我的代码:
class Task < ActiveRecord::Base
#...getters/setters omitted...
include Tire::Model::Search
#include Tire::Model::Callbacks #don't use callback, we use delayed job indexing
after_commit {tire.delay.update_index } #DELAYED JOB
after_destroy {tire.delay.update_index } #DELAYED JOB
mapping do
indexes :id, :index => :not_analyzed
indexes :title
indexes :is_open, type: 'boolean'
end
def self.search(params)
tire.search(:page => (params[:page] || 1), load: true) do
query { string params[:q], :default_operator=>"AND"} if params[:q].present?
sort do
by :is_open, "desc" #THIS SORT IS IGNORED WHEN I INDEX WITH DELAYED JOB, BUT IT WORKS WHEN I INDEX WITHOUT IT (WITH TIRE CALLBACKS OR WITH delay OMITTED).
end
end
end
end
你知道我做错了什么吗?
谢谢。
Jiri Hradil