thinking-sphinx 4.0.0 → 4.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 5dc5424b7f11401d4a408f23c666f50ccab97a62
4
- data.tar.gz: c7d801fd1370b1ea41072dafe3a9493636899d98
2
+ SHA256:
3
+ metadata.gz: f97dda977df8957bc00495056f23faf9e5a7f5c15e72b92f18f7c8e28d8385c2
4
+ data.tar.gz: 7364500f75d1edbc579b4f96bba8be9a3629197ece4cb8e0647077b991c03cfa
5
5
  SHA512:
6
- metadata.gz: d9c5cd36cddef1f7b398c8c9cc09ae8ad64ccdaf46d62bcd5e13e77170b87f19900e0f405a1d2604f19acd912180178d64eb4ff18d689ef2294221466b183b76
7
- data.tar.gz: 0b6189678807dda8e03544872e3db9414f611abf1e5e6ff01a484fb2197ce0a3b3ecac778a62964a64527e26522c7e715383af25375b49ad6d29e2481bdf50b7
6
+ metadata.gz: 0d928656c4ca161ad37f7ecea1a3a0435b1259016dc77e3ea65717d135f2bde6f6b2a9a38390e5a5eaf3768fc152334310bcb4c166747611670856e3cd0107b1
7
+ data.tar.gz: 4faefa5f695f14da95e564b97d5f29844befb36ff77888330051367da3fe5d5d48b10328713493fbffb914b4b167d750ed6e591d9a24fb6498a97b6e4f5d8ed5
data/.gitignore CHANGED
@@ -1,13 +1,15 @@
1
1
  *.gem
2
2
  .bundle
3
3
  .rbx
4
+ .rspec
5
+ .tool-versions
4
6
  gemfiles
5
7
  Gemfile.lock
6
8
  *.sublime-*
7
9
  pkg/*
8
10
  spec/internal/config/test.sphinx.conf
9
11
  spec/internal/db/sphinx
10
- spec/internal/log/*.log
12
+ spec/internal/log
11
13
  !spec/internal/tmp/.gitkeep
12
14
  spec/internal/tmp/*
13
15
  tmp
@@ -1,10 +1,9 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.2.10
4
- - 2.3.7
5
- - 2.4.4
6
- - 2.5.1
7
- - jruby-9.1.16.0
3
+ - 2.3.8
4
+ - 2.4.5
5
+ - 2.5.3
6
+ - 2.6.0
8
7
  addons:
9
8
  apt:
10
9
  packages:
@@ -30,10 +29,14 @@ env:
30
29
  - DATABASE=postgresql SPHINX_VERSION=2.1.9 SPHINX_ENGINE=sphinx
31
30
  - DATABASE=mysql2 SPHINX_VERSION=2.2.11 SPHINX_ENGINE=sphinx
32
31
  - DATABASE=postgresql SPHINX_VERSION=2.2.11 SPHINX_ENGINE=sphinx
33
- - DATABASE=mysql2 SPHINX_VERSION=3.0.2 SPHINX_ENGINE=sphinx
34
- - DATABASE=postgresql SPHINX_VERSION=3.0.2 SPHINX_ENGINE=sphinx
32
+ - DATABASE=mysql2 SPHINX_VERSION=3.0.3 SPHINX_ENGINE=sphinx
33
+ - DATABASE=postgresql SPHINX_VERSION=3.0.3 SPHINX_ENGINE=sphinx
34
+ - DATABASE=mysql2 SPHINX_VERSION=3.1.1 SPHINX_ENGINE=sphinx
35
35
  - DATABASE=mysql2 SPHINX_VERSION=2.6.3 SPHINX_ENGINE=manticore
36
36
  - DATABASE=postgresql SPHINX_VERSION=2.6.3 SPHINX_ENGINE=manticore
37
+ - DATABASE=mysql2 SPHINX_VERSION=2.7.4 SPHINX_ENGINE=manticore
38
+ - DATABASE=postgresql SPHINX_VERSION=2.7.4 SPHINX_ENGINE=manticore
39
+ # - DATABASE=postgresql SPHINX_VERSION=3.1.1 SPHINX_ENGINE=sphinx
37
40
  sudo: false
38
41
  addons:
39
42
  postgresql: '9.4'
@@ -2,6 +2,23 @@
2
2
 
3
3
  All notable changes to this project (at least, from v3.0.0 onwards) are documented in this file.
4
4
 
5
+ ## 4.1.0 - 2018-12-28
6
+
7
+ [Release Notes](https://github.com/pat/thinking-sphinx/releases/tag/v4.1.0)
8
+
9
+ ### Added
10
+
11
+ * 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)).
12
+
13
+ ### Changed
14
+
15
+ * 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).
16
+ * Added MRI 2.6, Sphinx 3.1 and Manticore 2.7 to the test matrix.
17
+
18
+ ### Fixed
19
+
20
+ * Real-time indices now work with non-default integer primary keys (alongside UUIDs or other non-integer primary keys).
21
+
5
22
  ## 4.0.0 - 2018-04-10
6
23
 
7
24
  [Release Notes](https://github.com/pat/thinking-sphinx/releases/tag/v4.0.0)
@@ -1,6 +1,6 @@
1
1
  h1. Thinking Sphinx
2
2
 
3
- 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.
3
+ 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.
4
4
 
5
5
  h2. Upgrading
6
6
 
@@ -14,7 +14,7 @@ It's a gem, so install it like you would any other gem. You will also need to sp
14
14
 
15
15
  <pre><code>gem 'mysql2', '~> 0.3', :platform => :ruby
16
16
  gem 'jdbc-mysql', '~> 5.1.35', :platform => :jruby
17
- gem 'thinking-sphinx', '~> 4.0'</code></pre>
17
+ gem 'thinking-sphinx', '~> 4.1'</code></pre>
18
18
 
19
19
  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.
20
20
 
@@ -29,13 +29,15 @@ h2. Requirements
29
29
  The current release of Thinking Sphinx works with the following versions of its dependencies:
30
30
 
31
31
  |_. Library |_. Minimum |_. Tested Against |
32
- | Ruby | v2.2 | v2.2.9, v2.3.6, v2.4.3, v2.5.0, JRuby 9.1.14 |
33
- | Sphinx | v2.1.2 | v2.1.9, v2.2.11, v3.0.2 |
34
- | Manticore | v2.6.3 | v2.6.3 |
32
+ | Ruby | v2.3 | v2.3.8, v2.4.5, v2.5.3, v2.6.0 |
33
+ | Sphinx | v2.1.2 | v2.1.9, v2.2.11, v3.0.3, v3.1.1 |
34
+ | Manticore | v2.6.3 | v2.6.3, v2.7.4 |
35
35
  | ActiveRecord | v3.2 | v3.2, v4.0, v4.1, v4.2, v5.0, v5.1, v5.2 |
36
36
 
37
37
  It _might_ work with older versions of Ruby, but it's highly recommended to update to a supported release.
38
38
 
39
+ 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.
40
+
39
41
  h3. Sphinx or Manticore
40
42
 
41
43
  Thinking Sphinx v3 is currently built for Sphinx 2.1.2 or newer, or Manticore v2.6+.
@@ -43,7 +43,8 @@ class ThinkingSphinx::ActiveRecord::Callbacks::DeltaCallbacks <
43
43
  end
44
44
 
45
45
  def indices
46
- @indices ||= config.index_set_class.new :classes => [instance.class]
46
+ @indices ||= config.index_set_class.new(:classes => [instance.class]).
47
+ select { |index| index.type == "plain" }
47
48
  end
48
49
 
49
50
  def new_or_changed?
@@ -77,7 +77,9 @@ class ThinkingSphinx::Middlewares::ActiveRecordTranslator <
77
77
  @results_for_models ||= model_names.inject({}) do |hash, name|
78
78
  model = name.constantize
79
79
 
80
- hash[name] = model_relation_with_sql_options(model.unscoped).where(
80
+ model_sql_options = sql_options[name] || sql_options
81
+
82
+ hash[name] = model_relation_with_sql_options(model.unscoped, model_sql_options).where(
81
83
  primary_key_for(model) => ids_for_model(name)
82
84
  )
83
85
 
@@ -85,12 +87,12 @@ class ThinkingSphinx::Middlewares::ActiveRecordTranslator <
85
87
  end
86
88
  end
87
89
 
88
- def model_relation_with_sql_options(relation)
89
- relation = relation.includes sql_options[:include] if sql_options[:include]
90
- relation = relation.joins sql_options[:joins] if sql_options[:joins]
91
- relation = relation.order sql_options[:order] if sql_options[:order]
92
- relation = relation.select sql_options[:select] if sql_options[:select]
93
- relation = relation.group sql_options[:group] if sql_options[:group]
90
+ def model_relation_with_sql_options(relation, model_sql_options)
91
+ relation = relation.includes model_sql_options[:include] if model_sql_options[:include]
92
+ relation = relation.joins model_sql_options[:joins] if model_sql_options[:joins]
93
+ relation = relation.order model_sql_options[:order] if model_sql_options[:order]
94
+ relation = relation.select model_sql_options[:select] if model_sql_options[:select]
95
+ relation = relation.group model_sql_options[:group] if model_sql_options[:group]
94
96
  relation
95
97
  end
96
98
 
@@ -10,9 +10,9 @@ class ThinkingSphinx::RealTime::Index < Riddle::Configuration::RealtimeIndex
10
10
  @attributes = []
11
11
  @conditions = []
12
12
 
13
- Template.new(self).apply
14
-
15
13
  super reference, options
14
+
15
+ Template.new(self).apply
16
16
  end
17
17
 
18
18
  def add_attribute(attribute)
@@ -10,7 +10,7 @@ class ThinkingSphinx::RealTime::Index::Template
10
10
  def apply
11
11
  add_field class_column, :sphinx_internal_class_name
12
12
 
13
- add_attribute :id, :sphinx_internal_id, :bigint
13
+ add_attribute primary_key, :sphinx_internal_id, :bigint
14
14
  add_attribute class_column, :sphinx_internal_class, :string, :facet => true
15
15
  add_attribute 0, :sphinx_deleted, :integer
16
16
  end
@@ -33,4 +33,8 @@ class ThinkingSphinx::RealTime::Index::Template
33
33
  def class_column
34
34
  [:class, :name]
35
35
  end
36
+
37
+ def primary_key
38
+ index.primary_key.to_sym
39
+ end
36
40
  end
@@ -24,7 +24,7 @@ class ThinkingSphinx::RealTime::TranscribeInstance
24
24
  attr_reader :instance, :index, :properties
25
25
 
26
26
  def document_id
27
- index.document_id_for_key instance.id
27
+ index.document_id_for_key instance.public_send(index.primary_key)
28
28
  end
29
29
 
30
30
  def raise_wrapper(error, property)
@@ -86,7 +86,11 @@ describe 'Searching within a model', :live => true do
86
86
  album = Album.create! :name => 'The Seldom Seen Kid', :artist => 'Elbow'
87
87
  index
88
88
 
89
- expect(Album.search.first).to eq(album)
89
+ expect(Album.search(:indices => ['album_core', 'album_delta']).first).
90
+ to eq(album)
91
+
92
+ expect(Album.search(:indices => ['album_real_core']).first).
93
+ to eq(album)
90
94
  end
91
95
  end
92
96
 
@@ -3,3 +3,7 @@
3
3
  ThinkingSphinx::Index.define :album, :with => :active_record, :primary_key => :integer_id, :delta => true do
4
4
  indexes name, artist
5
5
  end
6
+
7
+ ThinkingSphinx::Index.define :album, :with => :real_time, :primary_key => :integer_id, :name => :album_real do
8
+ indexes name, artist
9
+ end
@@ -6,6 +6,8 @@ class Album < ActiveRecord::Base
6
6
  before_validation :set_id, :on => :create
7
7
  before_validation :set_integer_id, :on => :create
8
8
 
9
+ after_save ThinkingSphinx::RealTime.callback_for(:album)
10
+
9
11
  validates :id, :presence => true, :uniqueness => true
10
12
  validates :integer_id, :presence => true, :uniqueness => true
11
13
 
@@ -44,7 +44,8 @@ describe ThinkingSphinx::ActiveRecord::Callbacks::DeltaCallbacks do
44
44
 
45
45
  describe '#after_commit' do
46
46
  let(:index) {
47
- double('index', :delta? => false, :delta_processor => processor)
47
+ double('index', :delta? => false, :delta_processor => processor,
48
+ :type => 'plain')
48
49
  }
49
50
 
50
51
  before :each do
@@ -67,9 +68,9 @@ describe ThinkingSphinx::ActiveRecord::Callbacks::DeltaCallbacks do
67
68
 
68
69
  context 'with delta indices' do
69
70
  let(:core_index) { double('index', :delta? => false, :name => 'foo_core',
70
- :delta_processor => processor) }
71
+ :delta_processor => processor, :type => 'plain') }
71
72
  let(:delta_index) { double('index', :delta? => true, :name => 'foo_delta',
72
- :delta_processor => processor) }
73
+ :delta_processor => processor, :type => 'plain') }
73
74
 
74
75
  before :each do
75
76
  allow(ThinkingSphinx::Deltas).to receive_messages :suspended? => false
@@ -127,7 +128,8 @@ describe ThinkingSphinx::ActiveRecord::Callbacks::DeltaCallbacks do
127
128
 
128
129
  describe '#before_save' do
129
130
  let(:index) {
130
- double('index', :delta? => true, :delta_processor => processor)
131
+ double('index', :delta? => true, :delta_processor => processor,
132
+ :type => 'plain')
131
133
  }
132
134
 
133
135
  before :each do
@@ -119,11 +119,11 @@ describe ThinkingSphinx::Middlewares::ActiveRecordTranslator do
119
119
 
120
120
  context 'SQL options' do
121
121
  let(:relation) { double('relation', :where => []) }
122
+ let(:model_name) { double('article', :constantize => model) }
122
123
 
123
124
  before :each do
124
125
  allow(model).to receive_messages :unscoped => relation
125
126
 
126
- model_name = double('article', :constantize => model)
127
127
  context[:results] << raw_result(1, model_name)
128
128
  end
129
129
 
@@ -167,6 +167,14 @@ describe ThinkingSphinx::Middlewares::ActiveRecordTranslator do
167
167
 
168
168
  middleware.call [context]
169
169
  end
170
+
171
+ it "passes through SQL options defined by model to the relation" do
172
+ search.options[:sql] = {model_name => {:joins => :association}}
173
+
174
+ expect(relation).to receive(:joins).with(:association).and_return(relation)
175
+
176
+ middleware.call [context]
177
+ end
170
178
  end
171
179
  end
172
180
  end
@@ -11,7 +11,7 @@ describe ThinkingSphinx::RealTime::Callbacks::RealTimeCallbacks do
11
11
  :settings => {}) }
12
12
  let(:index) { double('index', :name => 'my_index', :is_a? => true,
13
13
  :document_id_for_key => 123, :fields => [], :attributes => [],
14
- :conditions => []) }
14
+ :conditions => [], :primary_key => :id) }
15
15
  let(:connection) { double('connection', :execute => true) }
16
16
 
17
17
  before :each do
@@ -82,7 +82,7 @@ describe ThinkingSphinx::RealTime::Index do
82
82
  end
83
83
 
84
84
  describe '#model' do
85
- let(:model) { double('model') }
85
+ let(:model) { double('model', :primary_key => :id) }
86
86
 
87
87
  it "translates symbol references to model class" do
88
88
  allow(ActiveSupport::Inflector).to receive_messages(:constantize => model)
@@ -167,7 +167,7 @@ describe ThinkingSphinx::RealTime::Index do
167
167
  end
168
168
 
169
169
  describe '#scope' do
170
- let(:model) { double('model') }
170
+ let(:model) { double('model', :primary_key => :id) }
171
171
 
172
172
  it "returns the model by default" do
173
173
  allow(ActiveSupport::Inflector).to receive_messages(:constantize => model)
@@ -9,7 +9,7 @@ RSpec.describe ThinkingSphinx::RealTime::TranscribeInstance do
9
9
  )
10
10
  end
11
11
  let(:instance) { double :id => 43 }
12
- let(:index) { double :document_id_for_key => 46 }
12
+ let(:index) { double :document_id_for_key => 46, :primary_key => :id }
13
13
  let(:property_a) { double :translate => 'A' }
14
14
  let(:property_b) { double :translate => 'B' }
15
15
  let(:property_c) { double :translate => 'C' }
@@ -5,7 +5,7 @@ $:.push File.expand_path('../lib', __FILE__)
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = 'thinking-sphinx'
8
- s.version = '4.0.0'
8
+ s.version = '4.1.0'
9
9
  s.platform = Gem::Platform::RUBY
10
10
  s.authors = ["Pat Allan"]
11
11
  s.email = ["pat@freelancing-gods.com"]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thinking-sphinx
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 4.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pat Allan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-10 00:00:00.000000000 Z
11
+ date: 2018-12-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -520,8 +520,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
520
520
  - !ruby/object:Gem::Version
521
521
  version: '0'
522
522
  requirements: []
523
- rubyforge_project: thinking-sphinx
524
- rubygems_version: 2.4.5.5
523
+ rubygems_version: 3.0.1
525
524
  signing_key:
526
525
  specification_version: 4
527
526
  summary: A smart wrapper over Sphinx for ActiveRecord