我用:
rails 4.1.1
ruby 2.1.1
thinking sphinx 3.1.1
mysql2
object_index.rb:
ThinkingSphinx::Index.define :object, :with => :active_record do
indexes price, :sortable => true
...
has created_at, updated_at
end
在sphinx配置中:
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
如何修复它并在价格范围内使用搜索?
UPD: schema.db 当我做它整数问题是相同的:
t.float "price", null: false
thinging_sphinx
生成此配置文件,将其放在此处 - http://pastebin.com/USGABqdt
答案 0 :(得分:2)
我解决了我的问题! 我写在/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
它有效!