rake ts:重建执行没有错误,但我无法获取索引页面显示我有这个错误:
sphinxql: syntax error, unexpected AND, expecting CONST_INT (or 3 other tokens) near 'AND `broadcast_date` BETWEEN 0 AND 0 AND `sphinx_deleted` = 0 LIMIT 0, 20; SHOW META'
控制器
@segments = Segment.search params[:name], :with => { :person_id => params[:person_ids] ,:broadcast_date => dbDateFrom.to_i..dbDateTo.to_i}, :page => params[:page], :per_page => 20
型号
class Segment < ActiveRecord::Base
attr_accessible :broadcast_date, :comment, :name, :person_id, :segment, :tv_show_id, :person_ids,:balance
belongs_to :episodes
has_many :personSegments
has_many :people , :through => :personSegments
before_save :compute_balance
end
索引
ThinkingSphinx::Index.define :segment, :with => :active_record do
indexes name, :sortable => true
has created_at, updated_at
has broadcast_date
has people(:id), :as => person_id
end
在索引页面上,参数为空。问题出在哪儿?好像它正在等待person_id的值,但它在表单上是可选的。
的更新 的 *
得到了它:
unless params[:person_ids].blank?
condition = { :broadcast_date => dbDateFrom.to_i..dbDateTo.to_i, :person_id => params[:person_ids] }
else
condition = { :broadcast_date => dbDateFrom.to_i..dbDateTo.to_i }
end
@segments = Segment.search params[:name], :with=> condition ,:page => params[:page], :per_page => 20
答案 0 :(得分:0)
此时,Thinking Sphinx会为:with
哈希中的每个键/值对创建过滤器,无论该值是否为零。因此,如果您更动态地创建搜索请求,那就更好了:
filters = {:broadcast_date => dbDateFrom.to_i..dbDateTo.to_i}
filters[:person_id] = params[:person_ids] if params[:person_ids].present?
@segments = Segment.search params[:name],
:with => filters,
:page => params[:page],
:per_page => 20