2013-03-06 111 views
5

试图使用Thinking Sphinx进行搜索。其次是自制软件安装TS和MySQL(虽然我在我的应用程序所使用的PG,它显然是必需的)this Railscast,这些行添加到我的Gemfile:思维狮身人面像 - 在配置文件中找不到索引

gem 'mysql2' 
gem 'thinking-sphinx' 

,并把在我的模型以下,低于其他一切

post.rb

class Post < ActiveRecord::Base 
    #... 

    define_index do 
     indexes content 
     indexes :name 
    end 
end 

然后我去到终端,并尝试耙TS:索引,但我得到这个错误:

using config file '/Users/<personal>/rails_projects/<personal>/config/development.sphinx.conf'... 
    FATAL: no indexes found in config file '/Users/<personal>/rails_projects/<personal>/config/development.sphinx.conf' 

Fishedaroundon the internet并没有发现任何相当有答案的东西。我试过运行rake ts:configure(它不会抱怨),然后耙ts:index,但它不起作用。

一些背景:我只是改变了我的终端shell(使用zsh),这使得各种奇怪的意想不到的变化。我不得不重新安装捆绑软件,然后重新安装我所有的宝石,然后独立安装耙宝石。然后我捆绑更新为好措施。现在耙似乎工作,但我仍然得到错误。

配置文件中的错误是抱怨:

indexer 
{ 
} 

searchd 
{ 
    listen = 127.0.0.1:9306:mysql41 
    log = /Users/<personal>/rails_projects/<personal>/log/development.searchd.log 
    query_log = /Users/<personal>/rails_projects/<personal>/log/development.searchd.query.log 
    pid_file = /Users/<personal>/rails_projects/<personal>/log/development.sphinx.pid 
    workers = threads 
    binlog_path = /Users/<personal>/rails_projects/<personal>/tmp/binlog/development 
} 

任何想法是怎么回事/什么代码,答案可能是吗?

有趣UPDATE - 我跟着第q & A于this Google Group进入我的rails控制台,输入“Post.sphinx_indexes.length”,但我得到的回报这个非常不同的错误。看起来我的模型不知何故无法获得宝石?

NoMethodError: undefined method `define_index' for #<Class:0x007f9c06c611b0> 
     from /Users/<personal>/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.11/lib/active_record/dynamic_matchers.rb:55:in `method_missing' 
     from /Users/<personal>/rails_projects/<personal>/app/models/post.rb:55:in `<class:Post>' 
     from /Users/<personal>/rails_projects/<personal>/app/models/post.rb:13:in `<top (required)>' 
     from /Users/<personal>/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:469:in `load' 
     from /Users/<personal>/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:469:in `block in load_file' 
     from /Users/<personal>/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:639:in `new_constants_in' 
     from /Users/<personal>/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:468:in `load_file' 
     from /Users/<personal>/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:353:in `require_or_load' 
     from /Users/<personal>/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:502:in `load_missing_constant' 
     from /Users/<personal>/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:192:in `block in const_missing' 
     from /Users/<personal>/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:190:in `each' 
     from /Users/<personal>/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:190:in `const_missing' 
     from (irb):1 
     from /Users/<personal>/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/commands/console.rb:47:in `start' 
     from /Users/<personal>/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/commands/console.rb:8:in `start' 
     from /Users/<personal>/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.11/lib/rails/commands.rb:41:in `<top (required)>' 
     from script/rails:6:in `require' 
     from script/rails:6:in `<main>'irb(main):002:0> 

回答

5

也发布了这个问题到思维狮身人面像谷歌组,并得到了答案,所以我会粘贴下面。回答上述问题后,我遇到了另一个错误,并且在那里跟进了,所以如果有人想要更多信息,this discussion应该有希望继续有帮助。

我引述:

Hi Sasha The issue is that Thinking Sphinx's documentation is mostly for v2, but v3 is what you're using (and much better). Index definitions are now located in app/indices - the README is your best source of information (but anything it doesn't cover is probably the same as earlier versions): https://github.com/pat/thinking-sphinx/blob/master/README.textile

Have a read through of that, move your index definition, and you should be good to go. Any further issues, get in touch :)

-- Pat

这个问题后,我碰到了这一个,这显然是因为狮身人面像没有访问我的PostgreSQL数据库。

indexing index 'post_core'... 
ERROR: source 'post_core_0': unknown type 'pgsql'; skipping. 
ERROR: index 'post_core': failed to configure some of the sources, will not index. 
total 0 reads, 0.000 sec, 0.0 kb/call avg, 0.0 msec/call avg 
total 0 writes, 0.000 sec, 0.0 kb/call avg, 0.0 msec/call avg 

我通过卸载斯芬克斯和两个宝石(thinking_sphinx和mysql2)固定这一点,那么冲泡既MySQL和pgsql的标志安装斯芬克斯,然后重新安装的宝石。

之后,rake ts:index就像一个魅力。

2

另一个可能的错误来源是命名文件夹和文件。一个额外的空间,或与'我'拼写指示不会识别这些文件,因此不会产生任何索引。

带yonks看的东西...

[在我的情况发生并不是很少!]

+0

谢谢杰罗姆......正是我所做的 - 拼写错误的指数。 – backwardm 2014-06-25 18:48:19

+0

一种情况下多的是,我相信,misdefined。索引会导致更少的错误,并成为铁路专家。 – Jerome 2014-06-26 09:05:32

+0

我去“指数”,因为“指标”也是分度的动作(处理索引),我想,以避免混淆。因此,我尽量使用索引作为索引的复数。 – pat 2014-08-13 15:00:27