思考sphinx:日期范围内的语法错误

时间:2013-12-27 16:32:05

标签: ruby-on-rails sphinx thinking-sphinx

我有以下索引:

ThinkingSphinx::Index.define :offer, :with => :active_record do

  indexes tags(:name), as: :tags
  indexes :name, as: :offer_name
  indexes :description, as: :offer_description

  has enabled, as: :offer_enabled

  has customer.is_enabled, as: :customer_enabled
  has customer.is_accepted, as: :customer_accepted

  has category.id, as: :category_id
  has :to, as: offer_to

end

现在进行搜索并使用日期范围作为

等属性
Offer.search( 'some search terms', with: { to: Date.current..(Date.current + 12.months), category_id: 3 } )

我收到以下错误消息:

sphinxql: syntax error, unexpected '-', expecting AND near '-12-27 AND 2014-12-27 AND `category_id` = 9 AND `sphinx_deleted` = 0 LIMIT 0, 50; SHOW META'

我正在使用:

sphinx版本2.1.3 思考sphinx版本3.0.6 rails 4.0.2

1 个答案:

答案 0 :(得分:0)

这已经在Github上的Thinking Sphinx问题中得到了解决,但对于遇到这个问题的其他人来说并且想知道修复是什么:

问题是过滤器中的日期 - Thinking Sphinx(或者更确切地说,Riddle,用于与Sphinx交互的基础Ruby gem)不会将日期转换为整数时间戳,这就是Sphinx存储时间(以及日期)数据的方式

快速解决方法是使用时间或整数时间戳,但Riddle的下一个版本将包含一个补丁,可自动将日期转换为过滤器中的整数时间戳(v1.5.10)。