Search code examples
rubyruby-on-rails-5thinking-sphinx

FATAL: no indexes found in '/home/XXXX/searchengine/config/development.sphinx.conf'


sphinx show me this error when i want to ( rake ts:start ) im using rails 5.1.4 and ruby 2.4.1

Sphinx 2.2.9-id64-release (rel22-r5006)
Copyright (c) 2001-2015, Andrew Aksyonoff
Copyright (c) 2008-2015, Sphinx Technologies Inc (http://sphinxsearch.com)
using config file '/home/snoura/searchengine/config/development.sphinx.conf'...
FATAL: no indexes found in '/home/snoura/searchengine/config/development.sphinx.conf'

The Sphinx start command failed:
Command: searchd --pidfile --config "/home/snoura/searchengine/config/development.sphinx.conf"
Status:  1
Output:  See above

There may be more information about the failure in /home/snoura/searchengine/log/development.searchd.log.

this is what i have in my model Post.rb

define_index do
indexes content
indexes :name, sortable: true
end

Solution

  • Two things to note here.

    First: you're using a very old syntax for defining indices (Taryn's comment on your question is spot on). define_index within a model is the approach of Thinking Sphinx v1/v2. Thinking Sphinx v3 (which is the version that supports Rails 3.2 through to 5.x) expects index definitions to live within the app/indices directory. So, you'll want to add a file there (perhaps post_index.rb) which contains the following:

    ThinkingSphinx::Index.define :post, :with => :active_record do
      indexes content
      indexes name, sortable: true
    end
    

    The full index definition syntax is available in the documentation: https://freelancing-gods.com/thinking-sphinx/indexing.html

    The second thing to note is that you need to have your indices processed before starting the daemon. This means running rake ts:index.