2013-03-06 116 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