Thinking Sphinx v5.0.0 Release Notes

Release Date: 2020-07-20 // over 3 years ago
  • Major Features and Breaking Changes

    ๐Ÿ’Ž 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.

    Explicit Callbacks

    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 \< ApplicationRecordbelongs\_to :articleThinkingSphinx::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 \< ApplicationRecordThinkingSphinx::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.endend
    

    ๐Ÿ’… 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.2.11 or newer is required

    ๐Ÿš€ 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.

    ๐Ÿ’Ž Ruby 2.4 or newer is required

    ๐Ÿ”– Versions of Ruby less than 2.3 are no longer supported, sorry. We're currently testing against 2.4 through to 2.7.

    ๐Ÿš… Rails 4.2 or newer is required

    ๐Ÿš€ 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).

    Other changes to behaviour

    • โœ‚ Remove internal uses of send, replaced with public_send as that's available in all supported Ruby versions.
    • Custom index_set_class implementations can now expect the :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.)
    • Deletion statements are simplified by avoiding the need to calculate document keys/offsets (@njakobsen via #1134).
    • Real-time data is deleted before replacing it, to avoid duplicate data when offsets change (@njakobsen via #1134).
    • Use 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.)
    • 0๏ธโƒฃ Fields and attributes can be overriden - whichever's defined last with a given name is the definition that's used. This is an edge case, but useful if you want to override any of the default fields/indices. (Requested by @kalsan in #1172.)

    ๐Ÿ› Bug fixes

    None.


Previous changes from v4.4.1

  • โฌ†๏ธ Upgrading

    No breaking or major changes.

    ๐Ÿ”„ Changes to behaviour

    • ๐Ÿšš Automatically remove app/indices from Zeitwerk's autoload paths in Rails 6.0 onwards (if using Zeitwerk as the autoloader).