0

im trying to find records that are NOT created in a certain date range using a thinking sphinx query in my rails 4 project with postgresql as database

THIS WORKS

Housing.search "some text",
star: true, 
ranker: :bm25, 
with: {created_at (3.weeks.ago..Time.zone.now)}

BUT THIS DOESN´T

Housing.search "some text",
star: true,
ranker: :bm25,
without: {created_at:(3.weeks.ago..Time.zone.now)}

I´m thinking its a bug in the query since it finds all record within the given date range, but fails to find the opposite?

This is my gemfile

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'

This is my 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

this is the query from the log when using without: {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

And this Is the error I am getting

sphinxql: syntax error, unexpected OR, expecting $end near 'OR created_at > 1378368470 AND   activated_at <> 0 LIMIT 0, 20 OPTION ranker=bm25; SHOW META'

this is the query from the log when using with: {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

so i think what I´m looking for is this query to be executed

AND created_at NOT BETWEEN 1376555152 AND 1378369552
4

1 回答 1

1

我认为 without 方法没有范围,我想是因为你想索引数据的部分而不是没有部分的所有数据,所以你可以使用逆表达式。

没有这样的

without: {created_at (3.weeks.ago..Time.zone.now)}

将是这样的(为您的数据提供安全的一年)

with: {created_at (Time.now.change(:year => 2012)..3.weeks.ago)}

当然,您的案例是一个很好的案例,因为如果数据是一致的,您就不会在“未来”创造事物。

于 2014-04-03T21:27:10.343 回答