Skip to content

Commit

Permalink
Merge branch 'release/v5.1.0' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
pat committed Dec 28, 2020
2 parents 971f513 + 23f81d1 commit 454b026
Show file tree
Hide file tree
Showing 29 changed files with 370 additions and 81 deletions.
150 changes: 150 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
version: 2.1

orbs:
ruby: circleci/[email protected]

workflows:
test:
jobs:
- test:
name: "Sphinx 2.2.11 with MySQL"
database: mysql2
sphinx_version: 2.2.11
sphinx_engine: sphinx
debian: jessie
ruby: '2.4.6'
- test:
name: "Sphinx 2.2.11 with PostgreSQL"
database: postgresql
sphinx_version: 2.2.11
sphinx_engine: sphinx
debian: jessie
ruby: '2.4.6'
- test:
name: "Sphinx 3.3.1 with MySQL"
database: mysql2
sphinx_version: 3.3.1
sphinx_engine: sphinx
debian: buster
matrix:
parameters:
ruby: [ '2.4.9', '2.5.8', '2.6.6', '2.7.2' ]
# - test:
# database: postgresql
# sphinx_version: 3.3.1
# sphinx_engine: sphinx
# matrix:
# parameters:
# ruby: [ '2.4', '2.5', '2.6', '2.7' ]
- test:
name: "Manticore 2.8.2 with MySQL"
database: mysql2
sphinx_version: 2.8.2
sphinx_engine: manticore
debian: stretch
matrix:
parameters:
ruby: [ '2.4.9', '2.5.8', '2.6.6' ]
- test:
name: "Manticore 2.8.2 with PostgreSQL"
database: postgresql
sphinx_version: 2.8.2
sphinx_engine: manticore
debian: stretch
matrix:
parameters:
ruby: [ '2.4.9', '2.5.8', '2.6.6' ]
- test:
name: "Manticore 3.5.4 with MySQL"
database: mysql2
sphinx_version: 3.5.4
sphinx_engine: manticore
debian: buster
matrix:
parameters:
ruby: [ '2.4.9', '2.5.8', '2.6.6', '2.7.2' ]
- test:
name: "Manticore 3.5.4 with PostgreSQL"
database: postgresql
sphinx_version: 3.5.4
sphinx_engine: manticore
debian: buster
matrix:
parameters:
ruby: [ '2.4.9', '2.5.8', '2.6.6', '2.7.2' ]

jobs:
test:
parameters:
ruby:
type: string
database:
type: string
sphinx_version:
type: string
sphinx_engine:
type: string
debian:
type: string

docker:
- image: circleci/ruby:<< parameters.ruby >>-<< parameters.debian >>

- image: circleci/postgres:10
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: thinking_sphinx
POSTGRES_DB: thinking_sphinx

- image: circleci/mysql:5.7
environment:
MYSQL_ROOT_PASSWORD: thinking_sphinx
MYSQL_DATABASE: thinking_sphinx

working_directory: ~/app

steps:
- checkout

- restore_cache:
keys:
- v1-dependencies-<< parameters.ruby >>

- run:
name: install bundler
command: |
if [ "<< parameters.ruby >>" == "2.7.2" ]; then
export BUNDLER_VERSION=2.1.4
else
export BUNDLER_VERSION=1.17.3
fi
export BUNDLE_PATH=vendor/bundle
gem install bundler:$BUNDLER_VERSION
- run:
name: install dependencies
command: |
bundle install --jobs=4 --retry=3 --path vendor/bundle
bundle update
- run:
name: set up appraisal
command: bundle exec appraisal update

- save_cache:
paths:
- ./vendor/bundle
key: v1-dependencies-<< parameters.ruby >>

- run:
name: set up sphinx
command: "./bin/loadsphinx << parameters.sphinx_version >> << parameters.sphinx_engine >>"

- run:
name: tests
environment:
CI: "true"
DATABASE: << parameters.database >>
SPHINX_VERSION: << parameters.sphinx_version >>
SPHINX_ENGINE: << parameters.sphinx_engine >>
command: bundle exec appraisal rspec
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ env:
matrix:
- DATABASE=mysql2 SPHINX_VERSION=2.2.11 SPHINX_ENGINE=sphinx
- DATABASE=postgresql SPHINX_VERSION=2.2.11 SPHINX_ENGINE=sphinx
- DATABASE=mysql2 SPHINX_VERSION=3.2.1 SPHINX_ENGINE=sphinx
- DATABASE=mysql2 SPHINX_VERSION=3.3.1 SPHINX_ENGINE=sphinx
- DATABASE=mysql2 SPHINX_VERSION=2.8.2 SPHINX_ENGINE=manticore
- DATABASE=postgresql SPHINX_VERSION=2.8.2 SPHINX_ENGINE=manticore
- DATABASE=mysql2 SPHINX_VERSION=3.4.2 SPHINX_ENGINE=manticore
- DATABASE=postgresql SPHINX_VERSION=3.4.2 SPHINX_ENGINE=manticore
# - DATABASE=postgresql SPHINX_VERSION=3.2.1 SPHINX_ENGINE=sphinx
- DATABASE=mysql2 SPHINX_VERSION=3.5.0 SPHINX_ENGINE=manticore
- DATABASE=postgresql SPHINX_VERSION=3.5.0 SPHINX_ENGINE=manticore
# - DATABASE=postgresql SPHINX_VERSION=3.3.1 SPHINX_ENGINE=sphinx
sudo: false
addons:
postgresql: '9.4'
Expand Down
6 changes: 6 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,9 @@ appraise 'rails_6_0' do
gem 'mysql2', '~> 0.5.0', :platform => :ruby
gem 'pg', '~> 1.0', :platform => :ruby
end if RUBY_PLATFORM != 'java' && RUBY_VERSION.to_f >= 2.5

appraise 'rails_6_1' do
gem 'rails', '~> 6.1.0'
gem 'mysql2', '~> 0.5.0', :platform => :ruby
gem 'pg', '~> 1.0', :platform => :ruby
end if RUBY_PLATFORM != 'java' && RUBY_VERSION.to_f >= 2.5
22 changes: 21 additions & 1 deletion CHANGELOG.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,26 @@

All notable changes to this project (at least, from v3.0.0 onwards) are documented in this file.

## 5.1.0 - 2020-12-28

[Release Notes](https://github.com/pat/thinking-sphinx/releases/tag/v5.1.0)

### Added

* Support for Sphinx v3.3 and Manticore v3.5.
* Support for Rails 6.1 (via [joiner](https://rubygems.org/gems/joiner) v0.6.0).

### Changed

* `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.
* All timestamp attributes are now considered plain integer values from Sphinx's perspective. Sphinx was already expecting integers, but since Sphinx v3.3.1 it doesn't recognise timestamps as a data type. There is no functional difference with this change - Thinking Sphinx was always converting times to their UNIX epoch integer values.
* Allow configuration of the maximum statement length ([@kalsan](https://github.com/kalsan) in [#1179](https://github.com/pat/thinking-sphinx/pull/1179)).
* Respect `:path` values to navigate associations for Thinking Sphinx callbacks on SQL-backed indices. Discussed in [#1182](https://github.com/pat/thinking-sphinx/issues/1182).

### Fixed

* Don't attempt to update delta flags on frozen model instances.

## 5.0.0 - 2020-07-20

[Release Notes](https://github.com/pat/thinking-sphinx/releases/tag/v5.0.0)
Expand All @@ -20,7 +40,7 @@ All notable changes to this project (at least, from v3.0.0 onwards) are document
* Remove internal uses of `send`, replaced with `public_send` as that's available in all supported Ruby versions.
* Deletion statements are simplified by avoiding the need to calculate document keys/offsets (@njakobsen via [#1134](https://github.com/pat/thinking-sphinx/issues/1134)).
* Real-time data is deleted before replacing it, to avoid duplicate data when offsets change (@njakobsen via [#1134](https://github.com/pat/thinking-sphinx/issues/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 discussinos with @kalsan in [#1172](https://github.com/pat/thinking-sphinx/issues/1172).)
* 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](https://github.com/pat/thinking-sphinx/issues/1172).)

## 4.4.1 - 2019-08-23

Expand Down
4 changes: 2 additions & 2 deletions README.textile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
h1. Thinking Sphinx

Thinking Sphinx is a library for connecting ActiveRecord to the Sphinx full-text search tool, and integrates closely with Rails (but also works with other Ruby web frameworks). The current release is v5.0.0.
Thinking Sphinx is a library for connecting ActiveRecord to the Sphinx full-text search tool, and integrates closely with Rails (but also works with other Ruby web frameworks). The current release is v5.1.0.

h2. Upgrading

Expand All @@ -14,7 +14,7 @@ It's a gem, so install it like you would any other gem. You will also need to sp

<pre><code>gem 'mysql2', '~> 0.4', :platform => :ruby
gem 'jdbc-mysql', '~> 5.1.35', :platform => :jruby
gem 'thinking-sphinx', '~> 5.0'</code></pre>
gem 'thinking-sphinx', '~> 5.1'</code></pre>

The MySQL gems mentioned are required for connecting to Sphinx, so please include it even when you're using PostgreSQL for your database.

Expand Down
18 changes: 13 additions & 5 deletions bin/loadsphinx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ load_sphinx () {
format="deb"
distro="trusty";;
2.2.11)
url="http://sphinxsearch.com/files/sphinxsearch_2.2.11-release-1~xenial_amd64.deb"
url="http://sphinxsearch.com/files/sphinxsearch_2.2.11-release-1~jessie_amd64.deb"
format="deb";;
3.0.3)
url="http://sphinxsearch.com/files/sphinx-3.0.3-facc3fb-linux-amd64.tar.gz"
Expand All @@ -23,7 +23,10 @@ load_sphinx () {
url="http://sphinxsearch.com/files/sphinx-3.1.1-612d99f-linux-amd64.tar.gz"
format="gz";;
3.2.1)
url="http://www.sphinxsearch.com/files/sphinx-3.2.1-f152e0b-linux-amd64.tar.gz"
url="http://sphinxsearch.com/files/sphinx-3.2.1-f152e0b-linux-amd64.tar.gz"
format="gz";;
3.3.1)
url="http://sphinxsearch.com/files/sphinx-3.3.1-b72d67b-linux-amd64.tar.gz"
format="gz";;
*)
echo "No Sphinx version $version available"
Expand All @@ -37,7 +40,9 @@ load_sphinx () {

if [ "$format" == "deb" ]; then
curl --location $url -o sphinx.deb
sudo apt-get install ./sphinx.deb
sudo apt-get install libodbc1
sudo dpkg -i ./sphinx.deb
sudo apt-get install -f
else
curl $url -o sphinx.tar.gz
tar -zxvf sphinx.tar.gz
Expand All @@ -54,16 +59,19 @@ load_manticore () {
2.7.5)
url="https://github.com/manticoresoftware/manticoresearch/releases/download/2.7.5/manticore_2.7.5-181204-4a31c54-release-stemmer.xenial_amd64-bin.deb";;
2.8.2)
url="https://github.com/manticoresoftware/manticoresearch/releases/download/2.8.2/manticore_2.8.2-190402-4e81114-release-stemmer.xenial_amd64-bin.deb";;
url="https://github.com/manticoresoftware/manticoresearch/releases/download/2.8.2/manticore_2.8.2-190402-4e81114d-release-stemmer.stretch_amd64-bin.deb";;
3.4.2)
url="https://github.com/manticoresoftware/manticoresearch/releases/download/3.4.2/manticore_3.4.2-200410-6903305-release.xenial_amd64-bin.deb";;
3.5.4)
url="https://repo.manticoresearch.com/repository/manticoresearch_buster/pool/m/manticore/manticore_3.5.4-201211-13f8d08d_amd64.deb";;
*)
echo "No Manticore version $version available"
exit 1;;
esac

curl --location $url -o manticore.deb
sudo apt-get install ./manticore.deb
sudo dpkg -i ./manticore.deb
sudo apt-get install -f
}

if [ "$engine" == "sphinx" ]; then
Expand Down
2 changes: 0 additions & 2 deletions lib/thinking_sphinx.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
require 'active_support/core_ext/module/attribute_accessors'

module ThinkingSphinx
MAXIMUM_STATEMENT_LENGTH = (2 ** 23) - 5

def self.count(query = '', options = {})
search_for_ids(query, options).total_entries
end
Expand Down
1 change: 1 addition & 0 deletions lib/thinking_sphinx/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ module Depolymorph; end
require 'thinking_sphinx/active_record/sql_builder'
require 'thinking_sphinx/active_record/sql_source'

require 'thinking_sphinx/active_record/callbacks/association_delta_callbacks'
require 'thinking_sphinx/active_record/callbacks/delete_callbacks'
require 'thinking_sphinx/active_record/callbacks/delta_callbacks'
require 'thinking_sphinx/active_record/callbacks/update_callbacks'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class ThinkingSphinx::ActiveRecord::Attribute::SphinxPresenter
SPHINX_TYPES = {
:integer => :uint,
:boolean => :bool,
:timestamp => :timestamp,
:timestamp => :uint,
:float => :float,
:string => :string,
:bigint => :bigint,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

class ThinkingSphinx::ActiveRecord::Callbacks::AssociationDeltaCallbacks
def initialize(path)
@path = path
end

def after_commit(instance)
Array(objects_for(instance)).each do |object|
object.update :delta => true unless object.frozen?
end
end

private

attr_reader :path

def objects_for(instance)
path.inject(instance) { |object, method| object.send method }
end
end
40 changes: 26 additions & 14 deletions lib/thinking_sphinx/callbacks/appender.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,41 @@ def initialize(model, reference, options, &block)
end

def call
add_core_callbacks
add_delta_callbacks if behaviours.include?(:deltas)
add_real_time_callbacks if behaviours.include?(:real_time)
add_update_callbacks if behaviours.include?(:updates)
end

private

attr_reader :model, :reference, :options, :block

def add_core_callbacks
model.after_destroy ThinkingSphinx::ActiveRecord::Callbacks::DeleteCallbacks
end

if behaviours.include?(:deltas)
def add_delta_callbacks
if path.empty?
model.before_save ThinkingSphinx::ActiveRecord::Callbacks::DeltaCallbacks
model.after_commit ThinkingSphinx::ActiveRecord::Callbacks::DeltaCallbacks
end

if behaviours.include?(:real_time)
model.after_save ThinkingSphinx::RealTime.callback_for(
reference, path, &block
)
end

if behaviours.include?(:updates)
model.after_update(
ThinkingSphinx::ActiveRecord::Callbacks::UpdateCallbacks
else
model.after_commit(
ThinkingSphinx::ActiveRecord::Callbacks::AssociationDeltaCallbacks
.new(path)
)
end
end

private
def add_real_time_callbacks
model.after_save ThinkingSphinx::RealTime.callback_for(
reference, path, &block
)
end

attr_reader :model, :reference, :options, :block
def add_update_callbacks
model.after_update ThinkingSphinx::ActiveRecord::Callbacks::UpdateCallbacks
end

def behaviours
options[:behaviours] || []
Expand Down
4 changes: 4 additions & 0 deletions lib/thinking_sphinx/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ def self.new
connection_class.new options
end

def self.clear
@pool = nil
end

def self.connection_class
return ThinkingSphinx::Connection::JRuby if RUBY_PLATFORM == 'java'

Expand Down
Loading

0 comments on commit 454b026

Please sign in to comment.