这项工作
Housing.search "some text",
star: true,
ranker: :bm25,
with: {created_at (3.weeks.ago..Time.zone.now)}
但这不是
Housing.search "some text",
star: true,
ranker: :bm25,
without: {created_at:(3.weeks.ago..Time.zone.now)}
我认为它是查询中的一个错误,因为它找到了给定日期范围内的所有记录,但未能找到相反的结果?
这是我的宝石文件
gem 'mysql2', '0.3.12b4'
gem 'thinking-sphinx', github: 'pat/thinking-sphinx'
gem 'flying-sphinx', github: 'flying-sphinx/flying-sphinx'
gem 'delayed_job_active_record', '>= 4.0.0.beta2'
gem 'delayed_job_web'
gem 'ts-delayed-delta', github: 'pat/ts-delayed-delta'
这是我的housing_indices
ThinkingSphinx::Index.define :housing, :with => :active_record, :delta => ThinkingSphinx::Deltas::DelayedDelta do
has created_at
< + OTHER FIELDS THAT ARE INDEXED >
set_property :enable_star => true
set_property :min_infix_len => 1
set_property :html_strip => true
set_property :charset_type => "utf-8"
end
这是在没有使用时从日志中查询:{created_at:(3.weeks.ago..Time.zone.now)}
Sphinx Query (1.0ms) SELECT * FROM `housing_core`, `housing_delta` WHERE MATCH('@location_name *Krimml*') AND max_capacity BETWEEN 1 AND 1000 AND number_of_bathrooms BETWEEN 1 AND 3 AND number_of_bed_places BETWEEN 2 AND 10 AND sphinx_deleted = 0 AND created_at < 1376554070 OR created_at > 1378368470 AND activated_at <> 0 LIMIT 0, 20 OPTION ranker=bm25
这就是我得到的错误
sphinxql: syntax error, unexpected OR, expecting $end near 'OR created_at > 1378368470 AND activated_at <> 0 LIMIT 0, 20 OPTION ranker=bm25; SHOW META'
这是使用时日志中的查询:{created_at:(3.weeks.ago..Time.zone.now)}
Sphinx Query (3.9ms) SELECT * FROM `housing_core`, `housing_delta` WHERE MATCH('@location_name *Krimml*') AND created_at BETWEEN 1376555152 AND 1378369552 AND max_capacity BETWEEN 1 AND 1000 AND number_of_bathrooms BETWEEN 1 AND 3 AND number_of_bed_places BETWEEN 2 AND 10 AND sphinx_deleted = 0 AND activated_at <> 0 LIMIT 0, 20
所以我认为我要找的是要执行的查询
AND created_at NOT BETWEEN 1376555152 AND 1378369552
答案 0 :(得分:1)
我认为没有方法没有范围,我想是因为你想要索引部分数据而不是没有部分数据的所有数据,所以你可以使用逆表达式。
A不喜欢这个
without: {created_at (3.weeks.ago..Time.zone.now)}
将是这样的(对您的数据有一个安全的年份)
with: {created_at (Time.now.change(:year => 2012)..3.weeks.ago)}
当然,你的情况就是一个很好的例子,因为你不会在&#34;未来&#34;如果数据是一致的。