ruby-on-railsthinking-sphinx

Dealing with ThinkingSphinx realtime indices when destroying records


I'm trying to convert a delta-based index in ThinkingSphinx into a realtime one. Per the docs, I've added this callback:

after_save ThinkingSphinx::RealTime.callback_for(:location)

That works just fine for adding and updating records, woo. My problem is in deleting records, which according to the Rails docs, don't trigger after_save callbacks. I've confirmed this by deleting a record, which is not then deleted from my sphinx index.

I tried

after_destroy ThinkingSphinx::RealTime.callback_for(:location)

But this raises an error (as the realtime callbacks do not support after_destroy).

How can I remove an entry from my index when using a real time index?

(thinking-sphinx 3.3.0, rails 5.0.4, if that helps)


Solution

  • Thinking Sphinx automatically adds its own after_destroy callback to all indexed models, so removal of these records from real-time indices should happen without you needing to add any code.