ruby-on-railsthinking-sphinx

What's the correct way to use Thinking Sphinx scope


I am trying to create a TS scope as follows:

include ThinkingSphinx::Scopes
sphinx_scope(:status_approved) {
      {:conditions => {:status => "approved"}}
    }
default_sphinx_scope :status_approved 

My indice file is:

indexes name, status
has user_id, created_at

Two questions:

  1. Does field status needs to be defined as an index in order for the conditions string filter to work? Seems like I get a no field in schema query error if I do not do that.
  2. If it is required to define as part of the indexes, then whenever someone updated the status field, it will not show in the results until the next reindex occurs. Is this the only way to use a string filtering TS scope? Or is there a better way to do this?

I'm using Rails 3.2.16 and TS 3.0.6


Solution

    1. Sphinx scopes are for your Sphinx searches, so yes, you'll need status as a field in your index definition if you're using it in a Sphinx scope.
    2. If you want your Sphinx index data up-to-date as quickly as possible, you may want to investigate using delta indices (perhaps using Delayed Job or Sidekiq, to remove it from your web processes). Or, you could use Sphinx's real-time indices instead.