Search code examples
sphinxthinking-sphinx

Thinking Sphinx(v4.4) - Error while indexing after including 'where' condition in index definition


Thinking sphinx gem version - 4.4.1 Sphinx version - 3.3.1

I get

ERROR: index 'article_core': no full text fields in schema, nothing to index!

while indexing after including where condition in the index definition.

Index definition below

ThinkingSphinx::Index.define :article, :with => :active_record do
  indexes title
  # where "text = 'Past Simple'" # type of text column is text: rebuild successful
  # where "id > 1" # type of id column is int: rebuild successful
  where "photo = 'photo'" # type of photo column is String : rebuild fails
end
  1. The issue occurs when we use where condition inside the index
    definition on a string column(char varying)
  2. This issue does not occur when we apply where condition with other data types.
  3. the error statement is 'ERROR: index 'article_core': no full text fields in schema, nothing to index!.'

Solution

  • I'm wondering if you're using PostgreSQL as your application database? And maybe you don't have any articles which match the where condition? There's an issue with Sphinx 3.x releases where empty indices raise an error when indexing (and it seems it's not fixed in v3.3.1, which only came out last week).

    I've lodged this issue with the Sphinx team, but there's not been any response thus far.

    If you really want to use SQL-backed indices, I'm afraid you're going to have to downgrade to Sphinx 2.2.11, or consider switching to Manticore (a drop-in fork of Sphinx that doesn't have this issue). Or, you could instead use real-time indices, which work fine with Sphinx v3. If so, you can use the scope method within an index to limit the results:

    ThinkingSphinx::Index.define :article, :with => :real_time do
      indexes title
    
      scope { Article.where(:photo => "photo") }
    end