Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Thinking Sphinx -- no indexes found in config file

Trying to use Thinking Sphinx for search. Followed this Railscast by homebrew installing TS and MySQL (though I'm using pg in my app, it's apparently required), adding these lines to my gemfile:

gem 'mysql2'
gem 'thinking-sphinx'

and putting the following in my model, below everything else

post.rb

class Post < ActiveRecord::Base
    #...

    define_index do 
      indexes content
      indexes :name
    end
end

Then I go into the terminal and try rake ts:index, but I get this error:

 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 and found nothing that quite answered this. I've tried running rake ts:configure (which doesn't complain) and then rake ts:index, but it doesn't work.

Some background: I just changed my terminal shell (to use zsh), which made all sorts of weird unexpected changes. I had to reinstall bundler, then re-bundle install all my gems, then independently gem install rake. Then I bundle updated for good measure. Now rake seems to work, but I still get the error.

The config file the error is grumbling about:

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
}

Any ideas what's going on / what code the answer might be in?

INTERESTING UPDATE -- I followed the Q&A on this Google Group to enter my rails console and type "Post.sphinx_indexes.length", but I got this very different error in return. Looks like my model is somehow not getting access to the gem?

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> 
like image 611
Sasha Avatar asked Mar 06 '13 02:03

Sasha


2 Answers

Also posted this question to the Thinking Sphinx Google Group and got the answer there, so I'll paste it below. After answering the above question, I ran into another error and have followed up on it there, so if anyone wants more info, this discussion should hopefully continue to be helpful.

And I quote:

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

After that issue, I ran into this one, which was apparently because Sphinx didn't have access to my PostgreSQL database.

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

I fixed this by uninstalling Sphinx and both gems (thinking_sphinx and mysql2), then brew installing Sphinx with both mysql and pgsql flags, then reinstalling the gems.

After that, rake ts:index worked like a charm.

like image 125
Sasha Avatar answered Nov 13 '22 20:11

Sasha


Another possible source of error is in the naming of the folder and file. An extra space, or indicies spelt with an 'i' will not recognize the files and thus not generate any index.

Things that take yonks to see...

[and in my case happen not so infrequently!]

like image 3
Jerome Avatar answered Nov 13 '22 21:11

Jerome