思考Sphinx - 在配置文件中找不到索引

时间:2013-03-06 02:42:45

标签: ruby-on-rails ruby-on-rails-3 rake thinking-sphinx

尝试使用Thinking Sphinx进行搜索。跟随this Railscast自制软件安装TS和MySQL(虽然我在我的应用程序中使用pg,显然需要它),将这些行添加到我的gemfile中:

gem 'mysql2'
gem 'thinking-sphinx'

并将以下内容放在我的模型中,低于其他所有内容

post.rb

class Post < ActiveRecord::Base
    #...

    define_index do 
      indexes content
      indexes :name
    end
end

然后我进入终端并尝试rake ts:index,但是我收到了这个错误:

 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'

Fished around on the internet并没有发现任何可以解释的问题。我试过运行rake ts:configure(不抱怨)然后rake ts:index,但它不起作用。

一些背景:我刚刚更改了我的终端shell(使用zsh),这会产生各种奇怪的意外更改。我不得不重新安装bundler,然后重新捆绑安装所有我的宝石,然后独立gem安装rake。然后我捆绑更新为好的措施。现在rake似乎工作,但我仍然得到错误。

错误抱怨的配置文件:

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
}

任何想法发生了什么/答案可能是什么代码?

有趣的更新 - 我按照this Google Group上的Q&amp; A进入我的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> 

2 个答案:

答案 0 :(得分:5)

还将这个问题发布到Thinking Sphinx Google Group并得到了答案,所以我将其粘贴在下面。在回答了上述问题后,我遇到了另一个错误,并在那里进行了跟进,所以如果有人想要更多信息,this discussion应该继续提供帮助。

我引用:

  

嗨Sasha问题在于思考Sphinx的文档主要是   对于v2,但v3是你正在使用的(并且更好)。指数   定义现在位于app / indices中 - 自述文件是您最好的   信息来源(但它没有涵盖的任何东西可能是   与早期版本相同):   https://github.com/pat/thinking-sphinx/blob/master/README.textile

     

仔细阅读,移动你的索引定义,然后你   应该好好去。任何进一步的问题,请联系:)

     

- 帕特

在那个问题之后,我遇到了这个,这显然是因为Sphinx无法访问我的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

我通过卸载Sphinx和两个gems(thinking_sphinx和mysql2)解决了这个问题,然后使用mysql和pgsql标志安装Sphinx,然后重新安装gem。

在那之后,rake ts:index就像魅力一样。

答案 1 :(得分:3)

另一个可能的错误来源是文件夹和文件的命名。额外的空格或带有'i'拼写的标记将无法识别文件,因此不会生成任何索引。

需要看到的东西......

[在我的情况下不会发生这种情况!]