Skip to content

v4.4.0

Compare
Choose a tag to compare
@pat pat released this 21 Aug 13:00
· 161 commits to develop since this release
3918100

Upgrading

No breaking or major changes.

New features

  • Confirmed Rails 6.0 support.
  • Added ability to have custom real-time index processors (which handles all indices) and populators (which handles a particular index). These are available to get/set via ThinkingSphinx::RealTime.processor and ThinkingSphinx::RealTime.populator.

The processor should accept call with two arguments: an array of index objects, and a block to invoke after each index is processed. Here is a simple example for parallel processing of indices:

# Add the 'parallel' gem to your Gemfile.
ThinkingSphinx::RealTime.processor = Proc.new do |indices, &block|
  Parallel.map(indices) do |index|
    puts "Populating index #{index.name}"
    ThinkingSphinx::RealTime.populator.populate index
    puts "Populated index #{index.name}"

    block.call
  end
end

And the populator should respond to populate, accepting a single argument which is the index object. Here is a simple example for parallel processing.

# Add the 'parallel' gem to your Gemfile.
class ParallelPopulator
  def self.populate(index)
    new(index).call
  end

  def initialize(index)
    @index = index
  end

  def call
    Parallel.each(index.scope.find_in_batches) do |instances|
      transcriber.copy *instances
      true # Don't emit any large object because results are accumulated
    end
    ActiveRecord::Base.connection.reconnect!
  end

  private

  attr_reader :index

  def transcriber
    @transcriber ||= ThinkingSphinx::RealTime::Transcriber.new index
  end
end

ThinkingSphinx::RealTime.populator = ParallelPopulator

Instead of building your own procs/classes from scratch, you may instead wish to subclass the default classes to tweak behaviour - or at the very least, both classes are useful as reference points for your own replacements:

These changes were influenced by discussions in #1134 with @njakobsen about parallel processing of real-time indices.

Changes to behaviour

  • Improve failure message when tables don't exist for models associated with Sphinx indices (Kiril Mitov in #1139).

Bug fixes

  • Injected has-many/habtm collection search calls as default extensions to associations in Rails 5+, as it's a more reliable approach in Rails 6.0.0.