ruby-on-rails - 找不到价格介于

标签 ruby-on-rails thinking-sphinx

我使用:

rails 4.1.1
ruby 2.1.1
thinking sphinx 3.1.1
mysql2

对象索引.rb:

ThinkingSphinx::Index.define :object, :with => :active_record do
  indexes price, :sortable => true
  ...
  has created_at, updated_at
end

在狮身人面像配置中:

 sql_attr_float = price
 also try
 sql_attr_uint = price
 result was the same

当我尝试搜索价格在 X 和 Y 之间的对象时:

Object.search :with=> {:price => 100..900}

我得到了没有中间的所有记录,但它起作用了。

当我尝试时:

Object.search :conditions => {:with=> {:price => 100..800}}
or
Object.search :conditions => {:with=> {:price => 100.0..800.0}} for float

我遇到了一个错误:

ThinkingSphinx::SphinxError: index object_core: unsupported filter type 'intrange' on string column - SELECT * FROM `object_core` WHERE `price` BETWEEN 100 AND 800 AND `sphinx_deleted` = 0 LIMIT 0, 20; SHOW META
or for float
ThinkingSphinx::SphinxError: index object_core: unsupported filter type 'floatrange' on string column - SELECT * FROM `object_core` WHERE `price` BETWEEN 100.0 AND 900.0 AND `sphinx_deleted` = 0 LIMIT 0, 20; SHOW META

如何修复它并使用价格范围搜索?

更新: 模式.db 当我把它变成整数时,问题是一样的:

  t.float  "price",  null: false

thinging_sphinx 生成这个配置文件,把它放在这里 - http://pastebin.com/USGABqdt

最佳答案

我解决了我的问题! 我写在/inidices/realty_index.rb

indices :price

但我应该写

has :price, :type => float

因为价格不是搜索的字段,而是排序的属性。

Fields are the content for your search queries

Attributes are used for sorting, filtering and grouping your search results

而且有效!

关于ruby-on-rails - 找不到价格介于,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23590916/

相关文章:

ruby-on-rails - Thinking Sphinx 重建索引 - 高 CPU 负载

ruby-on-rails - Thinking Sphinx——在配置文件中找不到索引

ruby-on-rails - Rails 中的 partials 有什么用?

ruby-on-rails - 在 Rails 中停止恶意用户之间的 session 共享

mysql - ThinkingSphinx 匹配精确短语

ruby-on-rails-3 - ThinkingSphinx 错误 : such filter attribute

ruby-on-rails - 如何在 Thinking Sphinx 中一起使用多值属性 (MVA) 和方面?

ruby-on-rails - cucumber 和 Rspec

ruby-on-rails - Rails cron 不发送电子邮件

javascript - 切换按钮操作 OnClick - JQuery + Rails