Sphinx/Manticore plugin for ActiveRecord/Rails
No breaking or major changes.
No breaking or major changes.
No breaking or major changes.
after_commit
(including deletions) instead of after_save
/after_destroy
to ensure data is fully persisted to the database before updating Sphinx. More details in #1204.app/indices
from eager_load_paths in Rails 4.2 and 5, to match the behaviour in 6.Both of these fixes are evolutions/improvements to changes introduced in v5.2.0/5.2.1.
No breaking or major changes.
No breaking or major changes.
rails ts:rebuild
. Disabled by default, can be enabled by setting real_time_tidy
to true per environment in config/thinking_sphinx.yml
(and will need ts:rebuild
to restructure indices upon initial deploy). More details in #1192.app/indices
(in both the Rails app and engines) from Rails' eager load paths, which was otherwise leading to indices being loaded more than once. (See #1191 and #1195).No breaking or major changes.
enable_star
is no longer available as a configuration option, as it's been enabled by default in Sphinx since v2.2.2, and is no longer allowed in Sphinx v3.3.1.:path
values to navigate associations for Thinking Sphinx callbacks on SQL-backed indices. Discussed in #1182.Thinking Sphinx v5.0 has one significant change - explicit callbacks - plus drops support for old versions of Rails/Ruby/Sphinx, and adds a few other smaller improvements.
Previous versions of Thinking Sphinx automatically added callbacks to all ActiveRecord models, for the purpose of persisting changes back to Sphinx (whether that be inserts, updates, or deletions). And while the actual overhead for non-indexed models wasn't super slow, it's still far from ideal.
So now, you need to add callbacks yourself, to just the models you're indexing.
With SQL-backed models (defined using :with => :active_record
), you'll very likely want to add one of the two following lines inside your model:
class Article < ApplicationRecord
# If you're not using delta indices:
ThinkingSphinx::Callbacks.append(self, :behaviours => [:sql])
# If you *are* using delta indices:
ThinkingSphinx::Callbacks.append(self, :behaviours => [:sql, :deltas])
end
If you're using real-time indices, you very likely already have callbacks defined in your models, but you can replace them with the new calls:
class Article < ApplicationRecord
# Instead of this...
after_save ThinkingSphinx::RealTime.callback_for(:article)
# use this...
ThinkingSphinx::Callbacks.append(self, :behaviours => [:real_time])
end
For associated models which still fire real-time callbacks, you can use the :path
option with the same call:
class Comment < ApplicationRecord
belongs_to :article
ThinkingSphinx::Callbacks.append self,
:behaviours => [:real_time],
:path => [:article]
end
And if you're using a custom block with your old real-time callback, you can pass that same block to the new approach as well:
class Article < ApplicationRecord
ThinkingSphinx::Callbacks.append(
self, :behaviours => [:real_time]
) do |instance|
# returning an array of instances to index. You could add
# custom logic here if you don't want indexing to happen
# in some cases.
end
end
At this point in time, the older callback style for real-time indices will continue to work, but it's still recommended to update your code to the new style instead.
On the off chance you are using SQL-backed indices and you have attribute_updates
enabled in config/thinking_sphinx.yml
, you'll want to specify that in your :behaviours
option:
ThinkingSphinx::Callbacks.append(self, :behaviours => [:sql, :updates])
Sphinx 2.1 is no longer supported - and ideally, it's best to upgrade any 2.2.x release to 2.2.11.
Sphinx 3.x releases are supported, but there are known issues with indexing SQL-backed indices on a PostgreSQL database (real-time indices are fine though).
As part of this change, Sphinx's docinfo setting is no longer configured, so the skip_docinfo
setting in config/thinking_sphinx.yml
can be removed.
When it comes to Manticore as a drop-in replacement for Sphinx, we're testing against the latest 2.x and 3.x releases, which are currently 2.8.2 and 3.4.2 respectively.
Versions of Ruby less than 2.3 are no longer supported, sorry. We're currently testing against 2.4 through to 2.7.
It's been a long time coming, but Rails 3.2 (and 4.0 and 4.1) are no longer supported. The current supported versions are 4.2 through to 6.0 (and 6.1 will likely work as well, once it's released).
send
, replaced with public_send
as that's available in all supported Ruby versions.:instances
option to be set alongside :classes
, which is useful in cases to limit the indices returned if you're splitting index data for given classes/models into shards. (Introduced in PR #1171 after discussions with @lunaru in #1166.)reference_name
as per custom index_set_class
definitions. Previously, the class method was called on ThinkingSphinx::IndexSet
even if a custom subclass was configured. (As per discussions with @kalsan in #1172.)None.
No breaking or major changes.
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.
No breaking or behaviour changes.