Skip to content

Commit

Permalink
Merge branch 'release/v4.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
pat committed Dec 28, 2018
2 parents 3364c58 + b7ac262 commit edc0050
Show file tree
Hide file tree
Showing 18 changed files with 87 additions and 36 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
*.gem
.bundle
.rbx
.rspec
.tool-versions
gemfiles
Gemfile.lock
*.sublime-*
pkg/*
spec/internal/config/test.sphinx.conf
spec/internal/db/sphinx
spec/internal/log/*.log
spec/internal/log
!spec/internal/tmp/.gitkeep
spec/internal/tmp/*
tmp
Expand Down
17 changes: 10 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
language: ruby
rvm:
- 2.2.10
- 2.3.7
- 2.4.4
- 2.5.1
- jruby-9.1.16.0
- 2.3.8
- 2.4.5
- 2.5.3
- 2.6.0
addons:
apt:
packages:
Expand All @@ -30,10 +29,14 @@ env:
- DATABASE=postgresql SPHINX_VERSION=2.1.9 SPHINX_ENGINE=sphinx
- 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.0.2 SPHINX_ENGINE=sphinx
- DATABASE=postgresql SPHINX_VERSION=3.0.2 SPHINX_ENGINE=sphinx
- DATABASE=mysql2 SPHINX_VERSION=3.0.3 SPHINX_ENGINE=sphinx
- DATABASE=postgresql SPHINX_VERSION=3.0.3 SPHINX_ENGINE=sphinx
- DATABASE=mysql2 SPHINX_VERSION=3.1.1 SPHINX_ENGINE=sphinx
- DATABASE=mysql2 SPHINX_VERSION=2.6.3 SPHINX_ENGINE=manticore
- DATABASE=postgresql SPHINX_VERSION=2.6.3 SPHINX_ENGINE=manticore
- DATABASE=mysql2 SPHINX_VERSION=2.7.4 SPHINX_ENGINE=manticore
- DATABASE=postgresql SPHINX_VERSION=2.7.4 SPHINX_ENGINE=manticore
# - DATABASE=postgresql SPHINX_VERSION=3.1.1 SPHINX_ENGINE=sphinx
sudo: false
addons:
postgresql: '9.4'
Expand Down
17 changes: 17 additions & 0 deletions CHANGELOG.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,23 @@

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

## 4.1.0 - 2018-12-28

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

### Added

* 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](https://github.com/pat/thinking-sphinx/pull/1120)).

### Changed

* 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.

### Fixed

* Real-time indices now work with non-default integer primary keys (alongside UUIDs or other non-integer primary keys).

## 4.0.0 - 2018-04-10

[Release Notes](https://github.com/pat/thinking-sphinx/releases/tag/v4.0.0)
Expand Down
12 changes: 7 additions & 5 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 v4.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 v4.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.3', :platform => :ruby
gem 'jdbc-mysql', '~> 5.1.35', :platform => :jruby
gem 'thinking-sphinx', '~> 4.0'</code></pre>
gem 'thinking-sphinx', '~> 4.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. If you're using JRuby with a version of Sphinx prior to 2.2.11, there is "currently an issue with Sphinx and jdbc-mysql 5.1.36 or newer":http://sphinxsearch.com/forum/view.html?id=13939, so you'll need to stick to nothing more recent than 5.1.35, or upgrade Sphinx.

Expand All @@ -29,13 +29,15 @@ h2. Requirements
The current release of Thinking Sphinx works with the following versions of its dependencies:

|_. Library |_. Minimum |_. Tested Against |
| Ruby | v2.2 | v2.2.9, v2.3.6, v2.4.3, v2.5.0, JRuby 9.1.14 |
| Sphinx | v2.1.2 | v2.1.9, v2.2.11, v3.0.2 |
| Manticore | v2.6.3 | v2.6.3 |
| Ruby | v2.3 | v2.3.8, v2.4.5, v2.5.3, v2.6.0 |
| Sphinx | v2.1.2 | v2.1.9, v2.2.11, v3.0.3, v3.1.1 |
| Manticore | v2.6.3 | v2.6.3, v2.7.4 |
| ActiveRecord | v3.2 | v3.2, v4.0, v4.1, v4.2, v5.0, v5.1, v5.2 |

It _might_ work with older versions of Ruby, but it's highly recommended to update to a supported release.

It should also work with JRuby, but the test environment on Travis CI has been timing out, hence that's not actively tested against at the moment.

h3. Sphinx or Manticore

Thinking Sphinx v3 is currently built for Sphinx 2.1.2 or newer, or Manticore v2.6+.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ def delta_indices?
end

def indices
@indices ||= config.index_set_class.new :classes => [instance.class]
@indices ||= config.index_set_class.new(:classes => [instance.class]).
select { |index| index.type == "plain" }
end

def new_or_changed?
Expand Down
16 changes: 9 additions & 7 deletions lib/thinking_sphinx/middlewares/active_record_translator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,22 @@ def results_for_models
@results_for_models ||= model_names.inject({}) do |hash, name|
model = name.constantize

hash[name] = model_relation_with_sql_options(model.unscoped).where(
model_sql_options = sql_options[name] || sql_options

hash[name] = model_relation_with_sql_options(model.unscoped, model_sql_options).where(
primary_key_for(model) => ids_for_model(name)
)

hash
end
end

def model_relation_with_sql_options(relation)
relation = relation.includes sql_options[:include] if sql_options[:include]
relation = relation.joins sql_options[:joins] if sql_options[:joins]
relation = relation.order sql_options[:order] if sql_options[:order]
relation = relation.select sql_options[:select] if sql_options[:select]
relation = relation.group sql_options[:group] if sql_options[:group]
def model_relation_with_sql_options(relation, model_sql_options)
relation = relation.includes model_sql_options[:include] if model_sql_options[:include]
relation = relation.joins model_sql_options[:joins] if model_sql_options[:joins]
relation = relation.order model_sql_options[:order] if model_sql_options[:order]
relation = relation.select model_sql_options[:select] if model_sql_options[:select]
relation = relation.group model_sql_options[:group] if model_sql_options[:group]
relation
end

Expand Down
4 changes: 2 additions & 2 deletions lib/thinking_sphinx/real_time/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ def initialize(reference, options = {})
@attributes = []
@conditions = []

Template.new(self).apply

super reference, options

Template.new(self).apply
end

def add_attribute(attribute)
Expand Down
6 changes: 5 additions & 1 deletion lib/thinking_sphinx/real_time/index/template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def initialize(index)
def apply
add_field class_column, :sphinx_internal_class_name

add_attribute :id, :sphinx_internal_id, :bigint
add_attribute primary_key, :sphinx_internal_id, :bigint
add_attribute class_column, :sphinx_internal_class, :string, :facet => true
add_attribute 0, :sphinx_deleted, :integer
end
Expand All @@ -33,4 +33,8 @@ def add_field(column, name)
def class_column
[:class, :name]
end

def primary_key
index.primary_key.to_sym
end
end
2 changes: 1 addition & 1 deletion lib/thinking_sphinx/real_time/transcribe_instance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def call
attr_reader :instance, :index, :properties

def document_id
index.document_id_for_key instance.id
index.document_id_for_key instance.public_send(index.primary_key)
end

def raise_wrapper(error, property)
Expand Down
6 changes: 5 additions & 1 deletion spec/acceptance/searching_within_a_model_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,11 @@
album = Album.create! :name => 'The Seldom Seen Kid', :artist => 'Elbow'
index

expect(Album.search.first).to eq(album)
expect(Album.search(:indices => ['album_core', 'album_delta']).first).
to eq(album)

expect(Album.search(:indices => ['album_real_core']).first).
to eq(album)
end
end

Expand Down
4 changes: 4 additions & 0 deletions spec/internal/app/indices/album_index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@
ThinkingSphinx::Index.define :album, :with => :active_record, :primary_key => :integer_id, :delta => true do
indexes name, artist
end

ThinkingSphinx::Index.define :album, :with => :real_time, :primary_key => :integer_id, :name => :album_real do
indexes name, artist
end
2 changes: 2 additions & 0 deletions spec/internal/app/models/album.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ class Album < ActiveRecord::Base
before_validation :set_id, :on => :create
before_validation :set_integer_id, :on => :create

after_save ThinkingSphinx::RealTime.callback_for(:album)

validates :id, :presence => true, :uniqueness => true
validates :integer_id, :presence => true, :uniqueness => true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@

describe '#after_commit' do
let(:index) {
double('index', :delta? => false, :delta_processor => processor)
double('index', :delta? => false, :delta_processor => processor,
:type => 'plain')
}

before :each do
Expand All @@ -67,9 +68,9 @@

context 'with delta indices' do
let(:core_index) { double('index', :delta? => false, :name => 'foo_core',
:delta_processor => processor) }
:delta_processor => processor, :type => 'plain') }
let(:delta_index) { double('index', :delta? => true, :name => 'foo_delta',
:delta_processor => processor) }
:delta_processor => processor, :type => 'plain') }

before :each do
allow(ThinkingSphinx::Deltas).to receive_messages :suspended? => false
Expand Down Expand Up @@ -127,7 +128,8 @@

describe '#before_save' do
let(:index) {
double('index', :delta? => true, :delta_processor => processor)
double('index', :delta? => true, :delta_processor => processor,
:type => 'plain')
}

before :each do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ def raw_result(id, model_name)

context 'SQL options' do
let(:relation) { double('relation', :where => []) }
let(:model_name) { double('article', :constantize => model) }

before :each do
allow(model).to receive_messages :unscoped => relation

model_name = double('article', :constantize => model)
context[:results] << raw_result(1, model_name)
end

Expand Down Expand Up @@ -167,6 +167,14 @@ def raw_result(id, model_name)

middleware.call [context]
end

it "passes through SQL options defined by model to the relation" do
search.options[:sql] = {model_name => {:joins => :association}}

expect(relation).to receive(:joins).with(:association).and_return(relation)

middleware.call [context]
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
:settings => {}) }
let(:index) { double('index', :name => 'my_index', :is_a? => true,
:document_id_for_key => 123, :fields => [], :attributes => [],
:conditions => []) }
:conditions => [], :primary_key => :id) }
let(:connection) { double('connection', :execute => true) }

before :each do
Expand Down
4 changes: 2 additions & 2 deletions spec/thinking_sphinx/real_time/index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
end

describe '#model' do
let(:model) { double('model') }
let(:model) { double('model', :primary_key => :id) }

it "translates symbol references to model class" do
allow(ActiveSupport::Inflector).to receive_messages(:constantize => model)
Expand Down Expand Up @@ -167,7 +167,7 @@
end

describe '#scope' do
let(:model) { double('model') }
let(:model) { double('model', :primary_key => :id) }

it "returns the model by default" do
allow(ActiveSupport::Inflector).to receive_messages(:constantize => model)
Expand Down
2 changes: 1 addition & 1 deletion spec/thinking_sphinx/real_time/transcribe_instance_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
)
end
let(:instance) { double :id => 43 }
let(:index) { double :document_id_for_key => 46 }
let(:index) { double :document_id_for_key => 46, :primary_key => :id }
let(:property_a) { double :translate => 'A' }
let(:property_b) { double :translate => 'B' }
let(:property_c) { double :translate => 'C' }
Expand Down
2 changes: 1 addition & 1 deletion thinking-sphinx.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ $:.push File.expand_path('../lib', __FILE__)

Gem::Specification.new do |s|
s.name = 'thinking-sphinx'
s.version = '4.0.0'
s.version = '4.1.0'
s.platform = Gem::Platform::RUBY
s.authors = ["Pat Allan"]
s.email = ["[email protected]"]
Expand Down

0 comments on commit edc0050

Please sign in to comment.