Releases: pat/thinking-sphinx
v4.4.0
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
andThinkingSphinx::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.
v4.3.2
v4.3.1
v4.3.0
Upgrading
No breaking or major changes.
New features
- Allow overriding of Sphinx's running state by setting
skip_running_check
to true/false inconfig/thinking_sphinx.yml
for appropriate environments. This is useful when Sphinx commands are interacting with a remote Sphinx daemon. As per discussions in #1131. - Allow skipping of directory creation by setting
skip_directory_creation
to true/false inconfig/thinking_sphinx.yml
for appropriate environments. As per discussions in #1131.
Bug fixes
- Use ActiveSupport's lock monitor where possible (Rails 5.1.5 onwards) to avoid database deadlocks. Essential investigation by Jonathan del Strother (#1132).
- Allow facet searching on distributed indices (#1135).
v4.2.0
Upgrading
No breaking or major changes.
New features
- Allow changing the default encoding for MySQL database connections from
utf8
to something else via themysql_encoding
setting inconfig/thinking_sphinx.yml
. In the next significant release, the default will change toutf8mb4
(which is supported in MySQL 5.5.3 and newer). - Added Rails 6.0 and Manticore 2.8 to the test matrix.
Changes to behaviour
- Use Arel's SQL literals for generated order clauses, to avoid warnings from Rails 6.
Bug fixes
- Fix usage of alternative primary keys in update and deletion callbacks and attribute access.
- Ensure
respond_to?
takes Sphinx scopes into account (Jonathan del Strother in #1124). - Add
:excerpts
as a known option for search requests. - Fix depolymorphed association join construction with Rails 6.0.0.beta2.
- Reset ThinkingSphinx::Configuration's cached values when Rails reloads, to avoid holding onto stale references to ActiveRecord models (#1125).
- Don't join against associations in
sql_query
if they're only used by query-sourced properties (Hans de Graaff in #1127).
v4.1.0
Upgrading
No breaking or major changes, though Ruby 2.2 is now no longer officially supported - but this release will almost certainly still work on it.
New features
- The
:sql
search option can now accept per-model settings with model names as keys. e.g.ThinkingSphinx.search "foo", :sql => {'Article' => {:include => :user}}
(Sergey Malykh in #1120).
Changes to behaviour
- Drop MRI 2.2 from the test matrix, and thus no longer officially supported (though the code will likely continue to work with 2.2 for a while).
- Added MRI 2.6, Sphinx 3.1 and Manticore 2.7 to the test matrix.
Bug fixes
- Real-time indices now work with non-default integer primary keys (alongside UUIDs or other non-integer primary keys).
v4.0.0
Major Features and Changes
Thinking Sphinx v4.0 has been in development for a little while, and includes some significant changes (as befitting a major release):
Merging Indices
Merging indices is now supported via the new ts:merge
rake task. This is useful when you're using delta indices as an alternative to running ts:index
regularly to have new/changed records populated into the core indices. Merging should be reliably faster (and it avoids hitting your database to reprocess all the records).
Running ts:index
every now and then to catch any records changed/modified without callbacks is probably wise (perhaps once a day compared to more frequent ts:merge
calls).
Run the daemon on a UNIX socket
If you've got Sphinx and your Rails app all on a single machine, you may want to have the daemon (searchd
) hosting connections via a UNIX socket instead of a TCP socket. Just set the socket
value in each appropriate environment within config/thinking_sphinx.yml
(and do not set mysql41
unless you want the daemon to also be available via that TCP port).
production:
socket: /var/tmp/production.sphinx
This feature is limited to MRI, as JRuby doesn't seem to have a way to connect to UNIX sockets for MySQL-protocol connections.
ActiveRecord 5.2 Support
The new release of ActiveRecord/Rails is happily supported by this release.
Manticore Support
The recent fork of Sphinx known as Manticore is supported, and can be used as a drop-in replacement for Sphinx. In particular, the v2.6.3 release is included in the test matrix.
Breaking Changes
Sphinx 2.1.2 or newer is required
Sphinx 2.0 is no longer supported - make sure you're running at least 2.1.2, but 2.2.11 is recommended if possible.
Ruby 2.2 or newer is required
Versions of Ruby less than 2.2 are no longer supported, sorry.
Removed auto-typing of search filter values
If you're filtering via human-entered values (say, via request parameters), then in the past you were allowed to send those string values straight through to Sphinx.
However, Sphinx now supports string filtering, so it's not possible to make assumptions about filter types. Thinking Sphinx v3.4.0 introduced automatic typing of these values, but this was an extra overhead which was far from ideal and was always flagged as temporary.
So, please cast your filter values where appropriate:
Model.search :with => {:foo_id => params[:foo_id]}
# should become:
Model.search :with => {:foo_id => params[:foo_id].to_i}
Minor features
- If you want to remove the
docinfo
setting from the generated Sphinx configuration (to avoid warnings in Sphinx 2.2+), addskip_docinfo: true
to each appropriate environment inconfig/thinking_sphinx.yml
. - Sphinx 3.0 is now supported.
- You can now use relative paths in
config/thinking_sphinx.yml
, but you must also addabsolute_paths: true
to each environment for them to be converted to absolute paths for the generated configuration.
Changes to behaviour
- The INDEX_FILTER environment variable is applied when running ts:index on SQL-backed indices.
- Useful error messages are now displayed if processing real-time indices is attempted when the daemon isn't running.
- Rake task code has been refactored into separate command classes under the hood (which allows for
flying-sphinx
to override when appropriate). - Added
frozen_string_literal: true
pragma comments for safe frozen string literals. - Exceptions are logged when processing real-time indices without halting the processing.
- Update polymorphic properties to support Rails 5.2.
- Allow configuration of the index guard approach (e.g.
ThinkingSphinx::Configuration.instance.guarding_strategy = ThinkingSphinx::Guard::None
). - Output a warning if guard files exist when calling ts:index.
- Delete index guard files as part of ts:rebuild and ts:clear.
Bug fixes
- Don't attempt to interpret indices for models that don't have a database table.
- Handle situations where no exit code is provided for Sphinx binary calls.
v3.4.2
Upgrading
No breaking or major changes, just three small fixes and a couple of minor changes.
Changes to behaviour
- Allow use of deletion callbacks for rollback events.
- Remove extra deletion code in the Populator - it's also being done by the real-time rake interface.
Bug fixes
- Real-time callback syntax for namespaced models accepts a string (as was already documented).
- Fix up logged warnings (and avoiding overwriting the existing warn method).
- Add missing search options to known values to avoid incorrect warnings.
v3.4.1
Upgrading
No breaking or major changes, just two small fixes.
Changes to behaviour
- Errors with "Lost connection to MySQL server" are now treated as connection errors (Manuel Schnitzer).
Bug fixes
- Index normalisation will now work even when index model tables don't exist.
v3.4.0
Upgrading
There are a few significant changes in this release. There's nothing that's going to break your code, but there are some deprecations (and thus, there will be breaking in later releases), so reading through is highly recommended.
Basic type checking for attribute filters.
Given Riddle now quotes string values in filters (because Sphinx now supports filtering on string attributes), we need to be a little more careful about attribute filter values coming in through params. In the past, Riddle would presume any string value was not actually a string, and that's no longer a safe presumption.
As of this release, Thinking Sphinx will do its best to cast your filter values to their appropriate types, but it's not going to be perfect, and this will be removed in a future release. So, best to do the casting yourself:
Model.search :with => {:foo_id => params[:foo_id]}
# should become:
Model.search :with => {:foo_id => params[:foo_id].to_i}
This is likely going to crop up any time you're using params data in filters, because they'll always be strings.
If you're confident that you're casting all filter values to their appropriate types, you can remove the search middleware that's attempting to auto-cast (and thus, get a bit of a speed boost) by putting the following in an initialiser:
ThinkingSphinx::Middlewares::DEFAULT.delete(
ThinkingSphinx::Middlewares::AttributeTyper
)
ThinkingSphinx::Middlewares::RAW_ONLY.delete(
ThinkingSphinx::Middlewares::AttributeTyper
)
ThinkingSphinx::Middlewares::IDS_ONLY.delete(
ThinkingSphinx::Middlewares::AttributeTyper
)
Warnings for unknown options in search calls.
Thinking Sphinx will now output a warning to your logs when unexpected options are used in search queries.
If you’re adding your own middleware in or have something else that may allow for custom options, make sure you add them to ThinkingSphinx::Search.valid_options
.
If you don’t want this behaviour to occur, you can remove the middleware from your stack by putting the following in an initialiser:
ThinkingSphinx::Middlewares::DEFAULT.delete(
ThinkingSphinx::Middlewares::ValidOptions
)
ThinkingSphinx::Middlewares::RAW_ONLY.delete(
ThinkingSphinx::Middlewares::ValidOptions
)
ThinkingSphinx::Middlewares::IDS_ONLY.delete(
ThinkingSphinx::Middlewares::ValidOptions
)
Unified Rake Tasks
Rake tasks are now unified, so the original tasks will operate on real-time indices as well. What this means is that ts:generate
and ts:regenerate
can be changed to ts:index
and ts:rebuild
. All standard tasks will perform their appropriate behaviours on all indices.
If you wish to perform operations on specific types of indices, then there are now tasks available for that, including:
ts:sql:index
(the old behaviour ofts:index
)ts:sql:rebuild
(the old behaviour ofts:rebuild
)ts:rt:index
(the old behaviour ofts:generate
)ts:rt:rebuild
(the old behaviour ofts:regenerate
)
Minor Features
- Automatically use UTF8 in Sphinx for encodings that are extensions of UTF8 (such as
utf8mb4
). - Allow generation of a single real-time index (Tim Brown) with the
INDEX_FILTER
environment variable.
Changes to behaviour
- Handle non-computable queries as parse errors.
- Don't search multi-table inheritance ancestors.
- Set a default Sphinx connection timeout of 5 seconds.
- Use saved_changes if it's available (in Rails 5.1+).
- Add support for Ruby's frozen string literals feature.
- Display SphinxQL deletion statements in the log.
- Allow for unsaved records when calculating document ids (and return nil).
- Delta callback logic now prioritises checking for high level settings rather than model changes.
Bug Fixes
- Ensure ts:index now respects rake silent/quiet flags.
- Use the base class of STI models for polymorphic join generation (via Andrés Cirugeda).
- Fix multi-field conditions.
- Fix handling of attached starts of Sphinx (via Henne Vogelsang).
- Get bigint primary keys working in Rails 5.1.
- Always close the SphinxQL connection if Innertube's asking (via @cmaion).
- Fix long SphinxQL query handling in JRuby.
- Fix Sphinx connections in JRuby.
- Index normalisation now occurs consistently, and removes unneccesary sphinx_internal_class_name fields from real-time indices.