我正在尝试使用doc将 ThinkingSphinx 集成到我的项目中。对于具有属性 User
和first_name
的{{1}} 模型,我已将索引创建为:
User.rb
last_name
然后我运行命令:
define_index do
indexes :first_name
indexes :last_name
end
这开始我的搜索。当我使用以下命令搜索时,我得到了结果:
rake ts:index
rake ts:start
但是当我跑步时
User.search('swati')
它给了我错误:
User.search :with => {:first_name => "swati"}
我在stackoverflow上搜索了一个可能的解决方案,并且已经要求它运行命令Sphinx Sphinx Daemon returned error: index user_core: no such filter attribute 'first_name'
Sphinx Caught Sphinx exception: index user_core: no such filter attribute 'first_name' (0 tries left)
ThinkingSphinx::SphinxError: index user_core: no such filter attribute 'first_name'
from /home/swati/.rvm/gems/ruby-1.9.3-p286/gems/thinking-sphinx-2.0.13/lib/thinking_sphinx/search.rb:438:in `block in populate'
from /home/swati/.rvm/gems/ruby-1.9.3-p286/gems/thinking-sphinx-2.0.13/lib/thinking_sphinx/search.rb:606:in `call'
from /home/swati/.rvm/gems/ruby-1.9.3-p286/gems/thinking-sphinx-2.0.13/lib/thinking_sphinx/search.rb:606:in `retry_on_stale_index'
from /home/swati/.rvm/gems/ruby-1.9.3-p286/gems/thinking-sphinx-2.0.13/lib/thinking_sphinx/search.rb:426:in `populate'
from /home/swati/.rvm/gems/ruby-1.9.3-p286/gems/thinking-sphinx-2.0.13/lib/thinking_sphinx/search.rb:187:in `method_missing'
from /home/swati/.rvm/gems/ruby-1.9.3-p286/gems/railties-3.2.8/lib/rails/commands/console.rb:47:in `start'
from /home/swati/.rvm/gems/ruby-1.9.3-p286/gems/railties-3.2.8/lib/rails/commands/console.rb:8:in `start'
from /home/swati/.rvm/gems/ruby-1.9.3-p286/gems/railties-3.2.8/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
和rake ts:index
。我已经运行了这个命令,但它没有帮助我。
请帮我找出解决方法。
非常感谢。
答案 0 :(得分:6)
您应该在索引中创建 has 的属性重建,然后使用和
has :first_name
有创建属性,带用作过滤器(属性)http://pat.github.com/ts/en/searching.html#filters
另请检查http://pat.github.com/ts/en/indexing.html#attributes过滤器。
答案 1 :(得分:4)
小心,rake ts:reindex
和rake ts:rebuild
不同。
如果添加新索引,则需要重建。
如果你像我一样偏执狂,试试一切:
rake ts:rebuild
rake ts:reindex
rake ts:restart
如果仍然无效,请确保您的索引为defined properly。