2

我正在尝试使用doc将ThinkingSphinx集成到我的项目中。对于具有属性的模型,我将索引创建为:User first_namelast_name

用户.rb

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"}

它给了我错误:

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>'

我在 stackoverflow 上搜索了一个可能的解决方案,它被要求运行命令rake ts:indexrake ts:rebuild. 我已经运行了这个命令,但它没有帮助我。

请帮我找出解决方案。

非常感谢。

4

2 回答 2

6

您应该在索引中使用has创建一个属性, rebuild,然后使用with

has :first_name

创建属性,并用作过滤器(用于属性)http://pat.github.com/ts/en/searching.html#filters

还要检查http://pat.github.com/ts/en/indexing.html#attributes的过滤器。

于 2012-11-23T16:14:29.867 回答
4

小心点,rake ts:reindex与众不同rake ts:rebuild

如果添加新索引,则需要重建。

如果您像我一样偏执,请尝试一切:

rake ts:rebuild
rake ts:reindex
rake ts:restart

如果它仍然不起作用,请确保您的索引定义正确

于 2013-06-18T08:17:13.350 回答