thinking-sphinx 4.3.0 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +16 -21
  3. data/Appraisals +2 -17
  4. data/CHANGELOG.markdown +62 -1
  5. data/README.textile +14 -16
  6. data/bin/loadsphinx +20 -5
  7. data/lib/thinking_sphinx/active_record/association_proxy.rb +1 -2
  8. data/lib/thinking_sphinx/active_record/association_proxy/attribute_finder.rb +1 -1
  9. data/lib/thinking_sphinx/active_record/base.rb +17 -6
  10. data/lib/thinking_sphinx/active_record/callbacks/delete_callbacks.rb +1 -1
  11. data/lib/thinking_sphinx/active_record/callbacks/delta_callbacks.rb +3 -2
  12. data/lib/thinking_sphinx/active_record/callbacks/update_callbacks.rb +1 -1
  13. data/lib/thinking_sphinx/active_record/interpreter.rb +4 -4
  14. data/lib/thinking_sphinx/active_record/sql_source.rb +12 -0
  15. data/lib/thinking_sphinx/active_record/sql_source/template.rb +2 -2
  16. data/lib/thinking_sphinx/callbacks.rb +9 -0
  17. data/lib/thinking_sphinx/callbacks/appender.rb +47 -0
  18. data/lib/thinking_sphinx/commands/index_real_time.rb +1 -3
  19. data/lib/thinking_sphinx/configuration.rb +9 -3
  20. data/lib/thinking_sphinx/core/index.rb +5 -2
  21. data/lib/thinking_sphinx/deletion.rb +18 -17
  22. data/lib/thinking_sphinx/index_set.rb +7 -3
  23. data/lib/thinking_sphinx/middlewares/sphinxql.rb +1 -1
  24. data/lib/thinking_sphinx/railtie.rb +9 -1
  25. data/lib/thinking_sphinx/real_time.rb +17 -0
  26. data/lib/thinking_sphinx/real_time/index.rb +4 -0
  27. data/lib/thinking_sphinx/real_time/interpreter.rb +8 -6
  28. data/lib/thinking_sphinx/real_time/populator.rb +1 -1
  29. data/lib/thinking_sphinx/real_time/processor.rb +36 -0
  30. data/lib/thinking_sphinx/real_time/transcriber.rb +35 -19
  31. data/lib/thinking_sphinx/subscribers/populator_subscriber.rb +0 -4
  32. data/spec/acceptance/big_integers_spec.rb +1 -1
  33. data/spec/acceptance/merging_spec.rb +1 -1
  34. data/spec/acceptance/real_time_updates_spec.rb +2 -2
  35. data/spec/acceptance/sql_deltas_spec.rb +3 -3
  36. data/spec/acceptance/suspended_deltas_spec.rb +3 -3
  37. data/spec/internal/app/models/admin/person.rb +3 -1
  38. data/spec/internal/app/models/album.rb +3 -1
  39. data/spec/internal/app/models/animal.rb +1 -0
  40. data/spec/internal/app/models/article.rb +2 -0
  41. data/spec/internal/app/models/bird.rb +1 -0
  42. data/spec/internal/app/models/book.rb +2 -0
  43. data/spec/internal/app/models/car.rb +1 -1
  44. data/spec/internal/app/models/city.rb +2 -0
  45. data/spec/internal/app/models/product.rb +1 -1
  46. data/spec/internal/app/models/tee.rb +2 -0
  47. data/spec/internal/app/models/user.rb +2 -0
  48. data/spec/thinking_sphinx/active_record/callbacks/update_callbacks_spec.rb +2 -1
  49. data/spec/thinking_sphinx/active_record/index_spec.rb +0 -12
  50. data/spec/thinking_sphinx/active_record/interpreter_spec.rb +15 -14
  51. data/spec/thinking_sphinx/active_record/sql_source_spec.rb +38 -0
  52. data/spec/thinking_sphinx/configuration_spec.rb +17 -16
  53. data/spec/thinking_sphinx/deletion_spec.rb +5 -4
  54. data/spec/thinking_sphinx/index_set_spec.rb +28 -12
  55. data/spec/thinking_sphinx/middlewares/sphinxql_spec.rb +2 -1
  56. data/spec/thinking_sphinx/real_time/index_spec.rb +38 -12
  57. data/spec/thinking_sphinx/real_time/interpreter_spec.rb +14 -14
  58. data/spec/thinking_sphinx/real_time/transcriber_spec.rb +9 -1
  59. data/thinking-sphinx.gemspec +3 -5
  60. metadata +9 -8
@@ -31,7 +31,7 @@ describe ThinkingSphinx::Middlewares::SphinxQL do
31
31
  let(:query) { double('query') }
32
32
  let(:configuration) { double('configuration', :settings => {},
33
33
  index_set_class: set_class) }
34
- let(:set_class) { double(:new => index_set) }
34
+ let(:set_class) { double(:new => index_set, :reference_name => :article) }
35
35
 
36
36
  before :each do
37
37
  stub_const 'Riddle::Query::Select', double(:new => sphinx_sql)
@@ -115,6 +115,7 @@ describe ThinkingSphinx::Middlewares::SphinxQL do
115
115
  model = double('model', :connection => double,
116
116
  :ancestors => [ActiveRecord::Base], :name => 'Animal')
117
117
  allow(index_set.first).to receive_messages :reference => :animal
118
+ allow(set_class).to receive_messages(:reference_name => :animal)
118
119
 
119
120
  search.options[:classes] = [model]
120
121
 
@@ -11,6 +11,44 @@ describe ThinkingSphinx::RealTime::Index do
11
11
  allow(ThinkingSphinx::Configuration).to receive_messages :instance => config
12
12
  end
13
13
 
14
+ describe '#add_attribute' do
15
+ let(:attribute) { double('attribute', name: 'my_attribute') }
16
+
17
+ it "appends attributes to the collection" do
18
+ index.add_attribute attribute
19
+
20
+ expect(index.attributes.collect(&:name)).to include('my_attribute')
21
+ end
22
+
23
+ it "replaces attributes with the same name" do
24
+ index.add_attribute double('attribute', name: 'my_attribute')
25
+ index.add_attribute attribute
26
+
27
+ matching = index.attributes.select { |attr| attr.name == attribute.name }
28
+
29
+ expect(matching).to eq([attribute])
30
+ end
31
+ end
32
+
33
+ describe '#add_field' do
34
+ let(:field) { double('field', name: 'my_field') }
35
+
36
+ it "appends fields to the collection" do
37
+ index.add_field field
38
+
39
+ expect(index.fields.collect(&:name)).to include('my_field')
40
+ end
41
+
42
+ it "replaces fields with the same name" do
43
+ index.add_field double('field', name: 'my_field')
44
+ index.add_field field
45
+
46
+ matching = index.fields.select { |fld| fld.name == field.name }
47
+
48
+ expect(matching).to eq([field])
49
+ end
50
+ end
51
+
14
52
  describe '#attributes' do
15
53
  it "has the internal id attribute by default" do
16
54
  expect(index.attributes.collect(&:name)).to include('sphinx_internal_id')
@@ -31,18 +69,6 @@ describe ThinkingSphinx::RealTime::Index do
31
69
  end
32
70
  end
33
71
 
34
- describe '#docinfo' do
35
- it "defaults to extern" do
36
- expect(index.docinfo).to eq(:extern)
37
- end
38
-
39
- it "can be disabled" do
40
- config.settings["skip_docinfo"] = true
41
-
42
- expect(index.docinfo).to be_nil
43
- end
44
- end
45
-
46
72
  describe '#document_id_for_key' do
47
73
  it "calculates the document id based on offset and number of indices" do
48
74
  allow(config).to receive_message_chain(:indices, :count).and_return(5)
@@ -10,6 +10,10 @@ describe ThinkingSphinx::RealTime::Interpreter do
10
10
  let(:index) { Struct.new(:attributes, :fields, :options).new([], [], {}) }
11
11
  let(:block) { Proc.new { } }
12
12
 
13
+ before :each do
14
+ allow(index).to receive_messages(:add_attribute => nil, :add_field => nil)
15
+ end
16
+
13
17
  describe '.translate!' do
14
18
  let(:instance) { double('interpreter', :translate! => true) }
15
19
 
@@ -51,17 +55,15 @@ describe ThinkingSphinx::RealTime::Interpreter do
51
55
  end
52
56
 
53
57
  it "adds an attribute to the index" do
54
- instance.has column
58
+ expect(index).to receive(:add_attribute).with(attribute)
55
59
 
56
- expect(index.attributes).to include(attribute)
60
+ instance.has column
57
61
  end
58
62
 
59
63
  it "adds multiple attributes when passed multiple columns" do
60
- instance.has column, column
64
+ expect(index).to receive(:add_attribute).with(attribute).twice
61
65
 
62
- expect(index.attributes.select { |saved_attribute|
63
- saved_attribute == attribute
64
- }.length).to eq(2)
66
+ instance.has column, column
65
67
  end
66
68
  end
67
69
 
@@ -88,17 +90,15 @@ describe ThinkingSphinx::RealTime::Interpreter do
88
90
  end
89
91
 
90
92
  it "adds a field to the index" do
91
- instance.indexes column
93
+ expect(index).to receive(:add_field).with(field)
92
94
 
93
- expect(index.fields).to include(field)
95
+ instance.indexes column
94
96
  end
95
97
 
96
98
  it "adds multiple fields when passed multiple columns" do
97
- instance.indexes column, column
99
+ expect(index).to receive(:add_field).with(field).twice
98
100
 
99
- expect(index.fields.select { |saved_field|
100
- saved_field == field
101
- }.length).to eq(2)
101
+ instance.indexes column, column
102
102
  end
103
103
 
104
104
  context 'sortable' do
@@ -135,9 +135,9 @@ describe ThinkingSphinx::RealTime::Interpreter do
135
135
  end
136
136
 
137
137
  it "adds an attribute to the index" do
138
- instance.indexes column, :sortable => true
138
+ expect(index).to receive(:add_attribute).with(attribute)
139
139
 
140
- expect(index.attributes).to include(attribute)
140
+ instance.indexes column, :sortable => true
141
141
  end
142
142
  end
143
143
  end
@@ -6,7 +6,8 @@ RSpec.describe ThinkingSphinx::RealTime::Transcriber do
6
6
  let(:subject) { ThinkingSphinx::RealTime::Transcriber.new index }
7
7
  let(:index) { double 'index', :name => 'foo_core', :conditions => [],
8
8
  :fields => [double(:name => 'field_a'), double(:name => 'field_b')],
9
- :attributes => [double(:name => 'attr_a'), double(:name => 'attr_b')] }
9
+ :attributes => [double(:name => 'attr_a'), double(:name => 'attr_b')],
10
+ :primary_key => :id }
10
11
  let(:insert) { double :replace! => replace }
11
12
  let(:replace) { double :to_sql => 'REPLACE QUERY' }
12
13
  let(:connection) { double :execute => true }
@@ -40,6 +41,13 @@ RSpec.describe ThinkingSphinx::RealTime::Transcriber do
40
41
  subject.copy instance_a, instance_b
41
42
  end
42
43
 
44
+ it "deletes previous records" do
45
+ expect(connection).to receive(:execute).
46
+ with('DELETE FROM foo_core WHERE sphinx_internal_id IN (48, 49)')
47
+
48
+ subject.copy instance_a, instance_b
49
+ end
50
+
43
51
  it "skips instances that aren't in the database" do
44
52
  allow(instance_a).to receive(:persisted?).and_return(false)
45
53
 
@@ -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.3.0'
8
+ s.version = '5.0.0'
9
9
  s.platform = Gem::Platform::RUBY
10
10
  s.authors = ["Pat Allan"]
11
11
  s.email = ["pat@freelancing-gods.com"]
@@ -14,8 +14,6 @@ Gem::Specification.new do |s|
14
14
  s.description = %Q{An intelligent layer for ActiveRecord (via Rails and Sinatra) for the Sphinx full-text search tool.}
15
15
  s.license = 'MIT'
16
16
 
17
- s.rubyforge_project = 'thinking-sphinx'
18
-
19
17
  s.files = `git ls-files`.split("\n")
20
18
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f|
@@ -23,9 +21,9 @@ Gem::Specification.new do |s|
23
21
  }
24
22
  s.require_paths = ['lib']
25
23
 
26
- s.add_runtime_dependency 'activerecord', '>= 3.1.0'
24
+ s.add_runtime_dependency 'activerecord', '>= 4.2.0'
27
25
  s.add_runtime_dependency 'builder', '>= 2.1.2'
28
- s.add_runtime_dependency 'joiner', '>= 0.2.0'
26
+ s.add_runtime_dependency 'joiner', '>= 0.3.4'
29
27
  s.add_runtime_dependency 'middleware', '>= 0.1.0'
30
28
  s.add_runtime_dependency 'innertube', '>= 1.0.2'
31
29
  s.add_runtime_dependency 'riddle', '~> 2.3'
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.3.0
4
+ version: 5.0.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: 2019-05-18 00:00:00.000000000 Z
11
+ date: 2020-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 3.1.0
19
+ version: 4.2.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 3.1.0
26
+ version: 4.2.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: builder
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 0.2.0
47
+ version: 0.3.4
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: 0.2.0
54
+ version: 0.3.4
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: middleware
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -232,6 +232,7 @@ files:
232
232
  - lib/thinking_sphinx/attribute_types.rb
233
233
  - lib/thinking_sphinx/batched_search.rb
234
234
  - lib/thinking_sphinx/callbacks.rb
235
+ - lib/thinking_sphinx/callbacks/appender.rb
235
236
  - lib/thinking_sphinx/capistrano.rb
236
237
  - lib/thinking_sphinx/capistrano/v2.rb
237
238
  - lib/thinking_sphinx/capistrano/v3.rb
@@ -329,6 +330,7 @@ files:
329
330
  - lib/thinking_sphinx/real_time/index/template.rb
330
331
  - lib/thinking_sphinx/real_time/interpreter.rb
331
332
  - lib/thinking_sphinx/real_time/populator.rb
333
+ - lib/thinking_sphinx/real_time/processor.rb
332
334
  - lib/thinking_sphinx/real_time/property.rb
333
335
  - lib/thinking_sphinx/real_time/transcribe_instance.rb
334
336
  - lib/thinking_sphinx/real_time/transcriber.rb
@@ -521,8 +523,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
521
523
  - !ruby/object:Gem::Version
522
524
  version: '0'
523
525
  requirements: []
524
- rubyforge_project: thinking-sphinx
525
- rubygems_version: 2.7.6.2
526
+ rubygems_version: 3.0.3
526
527
  signing_key:
527
528
  specification_version: 4
528
529
  summary: A smart wrapper over Sphinx for ActiveRecord