Manage delta indexes via Delayed Job for Thinking Sphinx
Latest commit 0aef219 Oct 17, 2016 @pat committed on GitHub Merge pull request #52 from JasonBarnabe/rails5.1-deprecation
Fix Rails 5 deprecation in cancel_jobs
Failed to load latest commit information.
gemfiles Cleaning up dependencies, using Appraisal for dual testing. Apr 24, 2013
lib Fix comment on delete_all deprecation version Oct 17, 2016
spec Binary Sphinx test support. Apr 24, 2013
.gitignore Ignore Appraisal Gemfile.lock files. Apr 24, 2013
.travis.yml Use gemfiles instead of Appraisal directly. Apr 21, 2014
Appraisals Cleaning up dependencies, using Appraisal for dual testing. Apr 24, 2013
Gemfile Cleaning up dependencies, using Appraisal for dual testing. Apr 24, 2013
LICENSE Updating docs and Travis to match edge expectations. Sep 16, 2012
README.textile 2.0.2 Apr 21, 2014
ts-delayed-delta.gemspec Fix Rails 5.1 deprecation in cancel_jobs Oct 17, 2016


Delayed Deltas for Thinking Sphinx


This version works with Thinking Sphinx v1.5.0, v2.1.0 and v3.×.

In your Gemfile, it’ll likely look something like this:

gem 'ts-delayed-delta', '~> 2.0.2'

Or, if you’re referring directly to the git repository:

gem 'ts-delayed-delta',
  :git    => 'git://',
  :branch => 'master',
  :ref    => 'use-latest-commit-here'

And given this gem’s built for Delayed Job, we’re presuming you’ve got that set up (with the database table), and you know how to run it. This gem no longer provides a custom task for that purpose – there’s no need.


In your index definitions, make sure you set the :delta setting to ThinkingSphinx::Deltas::DelayedDelta:

ThinkingSphinx::Index.define :book, :with => :active_record, :delta => ThinkingSphinx::Deltas::DelayedDelta do
  # ...

For those still on pre-v3 versions of Thinking Sphinx, the delta option goes within the define_index block:

define_index do
  # ...

  set_property :delta => ThinkingSphinx::Deltas::DelayedDelta

If you’ve never used delta indices before, you’ll want to add the boolean column named delta to each model that is using the approach. It probably doesn’t hurt to add an index to that column as well.

add_column :books, :delta, :boolean, :default => true, :null => false
add_index  :books, :delta

And that’s pretty much it. Make sure Delayed Job is running, and it’ll take care of the jobs to keep your Sphinx indices up to date.

Please keep in mind that you need to run the Delayed Job workers on the same machine as Sphinx, as direct access to Sphinx files (and the Sphinx command-line tools) is essential.


Contributions are very much welcome – but keep in mind the following:

  • Keep patches in a separate branch
  • Don’t mess with the version number. I’ll take care of that when the patch is merged in.
  • Please write tests – currently, there’s only acceptance tests in place, because the underlying code is simple enough. If you get stuck into anything complex, unit tests are a smart move.



Copyright © 2009-2014, Thinking Sphinx Delayed Deltas (ts-delayed-delta) is developed and maintained by Pat Allan, and is released under the open MIT Licence. Many thanks to all who have contributed patches.