thinking-sphinx 4.4.1 → 5.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +218 -0
  3. data/.travis.yml +12 -21
  4. data/Appraisals +16 -19
  5. data/CHANGELOG.markdown +93 -0
  6. data/README.textile +17 -17
  7. data/bin/loadsphinx +22 -4
  8. data/lib/thinking_sphinx/active_record/association_proxy/attribute_finder.rb +1 -1
  9. data/lib/thinking_sphinx/active_record/attribute/sphinx_presenter.rb +1 -1
  10. data/lib/thinking_sphinx/active_record/base.rb +2 -6
  11. data/lib/thinking_sphinx/active_record/callbacks/association_delta_callbacks.rb +21 -0
  12. data/lib/thinking_sphinx/active_record/callbacks/delete_callbacks.rb +6 -2
  13. data/lib/thinking_sphinx/active_record/callbacks/delta_callbacks.rb +3 -2
  14. data/lib/thinking_sphinx/active_record/callbacks/update_callbacks.rb +1 -1
  15. data/lib/thinking_sphinx/active_record/interpreter.rb +4 -4
  16. data/lib/thinking_sphinx/active_record/sql_source/template.rb +2 -2
  17. data/lib/thinking_sphinx/active_record/sql_source.rb +12 -0
  18. data/lib/thinking_sphinx/active_record.rb +3 -0
  19. data/lib/thinking_sphinx/callbacks/appender.rb +63 -0
  20. data/lib/thinking_sphinx/callbacks.rb +9 -0
  21. data/lib/thinking_sphinx/connection/client.rb +6 -1
  22. data/lib/thinking_sphinx/connection.rb +4 -0
  23. data/lib/thinking_sphinx/core/index.rb +1 -2
  24. data/lib/thinking_sphinx/deletion.rb +18 -17
  25. data/lib/thinking_sphinx/errors.rb +1 -1
  26. data/lib/thinking_sphinx/index_set.rb +7 -3
  27. data/lib/thinking_sphinx/middlewares/sphinxql.rb +1 -1
  28. data/lib/thinking_sphinx/railtie.rb +20 -7
  29. data/lib/thinking_sphinx/real_time/index/template.rb +12 -0
  30. data/lib/thinking_sphinx/real_time/index.rb +5 -3
  31. data/lib/thinking_sphinx/real_time/interpreter.rb +8 -6
  32. data/lib/thinking_sphinx/real_time/populator.rb +4 -1
  33. data/lib/thinking_sphinx/real_time/transcriber.rb +41 -19
  34. data/lib/thinking_sphinx/real_time/translator.rb +1 -0
  35. data/lib/thinking_sphinx/search/stale_ids_exception.rb +2 -1
  36. data/lib/thinking_sphinx/search.rb +1 -1
  37. data/lib/thinking_sphinx/settings.rb +13 -9
  38. data/lib/thinking_sphinx/sinatra.rb +1 -1
  39. data/lib/thinking_sphinx/test.rb +1 -1
  40. data/lib/thinking_sphinx.rb +0 -3
  41. data/spec/acceptance/attribute_access_spec.rb +10 -2
  42. data/spec/acceptance/big_integers_spec.rb +1 -1
  43. data/spec/acceptance/geosearching_spec.rb +13 -3
  44. data/spec/acceptance/merging_spec.rb +1 -1
  45. data/spec/acceptance/paginating_search_results_spec.rb +18 -2
  46. data/spec/acceptance/real_time_updates_spec.rb +2 -2
  47. data/spec/acceptance/searching_with_filters_spec.rb +3 -3
  48. data/spec/acceptance/sql_deltas_spec.rb +16 -4
  49. data/spec/acceptance/support/sphinx_controller.rb +6 -4
  50. data/spec/acceptance/support/sphinx_helpers.rb +4 -4
  51. data/spec/acceptance/suspended_deltas_spec.rb +3 -3
  52. data/spec/internal/app/indices/article_index.rb +0 -1
  53. data/spec/internal/app/indices/colour_index.rb +7 -0
  54. data/spec/internal/app/models/admin/person.rb +3 -1
  55. data/spec/internal/app/models/album.rb +3 -1
  56. data/spec/internal/app/models/animal.rb +1 -0
  57. data/spec/internal/app/models/article.rb +2 -0
  58. data/spec/internal/app/models/bird.rb +1 -0
  59. data/spec/internal/app/models/book.rb +2 -0
  60. data/spec/internal/app/models/car.rb +1 -1
  61. data/spec/internal/app/models/city.rb +2 -0
  62. data/spec/internal/app/models/colour.rb +2 -0
  63. data/spec/internal/app/models/product.rb +1 -1
  64. data/spec/internal/app/models/tee.rb +5 -0
  65. data/spec/internal/app/models/user.rb +2 -0
  66. data/spec/internal/config/database.yml +6 -1
  67. data/spec/internal/db/schema.rb +1 -0
  68. data/spec/thinking_sphinx/active_record/callbacks/update_callbacks_spec.rb +2 -1
  69. data/spec/thinking_sphinx/active_record/index_spec.rb +3 -13
  70. data/spec/thinking_sphinx/active_record/interpreter_spec.rb +15 -14
  71. data/spec/thinking_sphinx/active_record/sql_source_spec.rb +41 -3
  72. data/spec/thinking_sphinx/connection/mri_spec.rb +49 -0
  73. data/spec/thinking_sphinx/deletion_spec.rb +5 -4
  74. data/spec/thinking_sphinx/index_set_spec.rb +28 -12
  75. data/spec/thinking_sphinx/middlewares/sphinxql_spec.rb +2 -1
  76. data/spec/thinking_sphinx/real_time/index_spec.rb +51 -13
  77. data/spec/thinking_sphinx/real_time/interpreter_spec.rb +14 -14
  78. data/spec/thinking_sphinx/real_time/transcriber_spec.rb +9 -1
  79. data/thinking-sphinx.gemspec +3 -3
  80. metadata +17 -12
  81. data/spec/acceptance/connection_spec.rb +0 -25
@@ -11,14 +11,16 @@ class ThinkingSphinx::Settings
11
11
  lemmatizer_base mysql_ssl_cert mysql_ssl_key mysql_ssl_ca
12
12
  ].freeze
13
13
  DEFAULTS = {
14
- "configuration_file" => "config/ENVIRONMENT.sphinx.conf",
15
- "indices_location" => "db/sphinx/ENVIRONMENT",
16
- "pid_file" => "log/ENVIRONMENT.sphinx.pid",
17
- "log" => "log/ENVIRONMENT.searchd.log",
18
- "query_log" => "log/ENVIRONMENT.searchd.query.log",
19
- "binlog_path" => "tmp/binlog/ENVIRONMENT",
20
- "workers" => "threads",
21
- "mysql_encoding" => "utf8"
14
+ "configuration_file" => "config/ENVIRONMENT.sphinx.conf",
15
+ "indices_location" => "db/sphinx/ENVIRONMENT",
16
+ "pid_file" => "log/ENVIRONMENT.sphinx.pid",
17
+ "log" => "log/ENVIRONMENT.searchd.log",
18
+ "query_log" => "log/ENVIRONMENT.searchd.query.log",
19
+ "binlog_path" => "tmp/binlog/ENVIRONMENT",
20
+ "workers" => "threads",
21
+ "mysql_encoding" => "utf8",
22
+ "maximum_statement_length" => (2 ** 23) - 5,
23
+ "real_time_tidy" => false
22
24
  }.freeze
23
25
 
24
26
  def self.call(configuration)
@@ -62,7 +64,9 @@ class ThinkingSphinx::Settings
62
64
 
63
65
  def defaults
64
66
  DEFAULTS.inject({}) do |hash, (key, value)|
65
- value = value.gsub("ENVIRONMENT", framework.environment)
67
+ if value.is_a?(String)
68
+ value = value.gsub("ENVIRONMENT", framework.environment)
69
+ end
66
70
 
67
71
  if FILE_KEYS.include?(key)
68
72
  hash[key] = absolute value
@@ -3,5 +3,5 @@
3
3
  require 'thinking_sphinx'
4
4
 
5
5
  ActiveSupport.on_load :active_record do
6
- include ThinkingSphinx::ActiveRecord::Base
6
+ require 'thinking_sphinx/active_record'
7
7
  end
@@ -42,7 +42,7 @@ class ThinkingSphinx::Test
42
42
  config.indices_location,
43
43
  config.searchd.binlog_path
44
44
  ].each do |path|
45
- FileUtils.rm_r(path) if File.exists?(path)
45
+ FileUtils.rm_r(path) if File.exist?(path)
46
46
  end
47
47
  end
48
48
 
@@ -17,8 +17,6 @@ require 'active_support/core_ext/module/delegation'
17
17
  require 'active_support/core_ext/module/attribute_accessors'
18
18
 
19
19
  module ThinkingSphinx
20
- MAXIMUM_STATEMENT_LENGTH = (2 ** 23) - 5
21
-
22
20
  def self.count(query = '', options = {})
23
21
  search_for_ids(query, options).total_entries
24
22
  end
@@ -98,7 +96,6 @@ require 'thinking_sphinx/test'
98
96
  require 'thinking_sphinx/utf8'
99
97
  require 'thinking_sphinx/wildcard'
100
98
  # Extended
101
- require 'thinking_sphinx/active_record'
102
99
  require 'thinking_sphinx/deltas'
103
100
  require 'thinking_sphinx/distributed'
104
101
  require 'thinking_sphinx/logger'
@@ -20,7 +20,11 @@ describe 'Accessing attributes directly via search results', :live => true do
20
20
  search = Book.search 'gods', :select => "*, weight()"
21
21
  search.context[:panes] << ThinkingSphinx::Panes::WeightPane
22
22
 
23
- expect(search.first.weight).to eq(2500)
23
+ if ENV["SPHINX_ENGINE"] == "sphinx" && ENV["SPHINX_VERSION"].to_f > 3.3
24
+ expect(search.first.weight).to eq(20_000.0)
25
+ else
26
+ expect(search.first.weight).to eq(2500)
27
+ end
24
28
  end
25
29
 
26
30
  it "provides direct access to the weight with alternative primary keys" do
@@ -39,7 +43,11 @@ describe 'Accessing attributes directly via search results', :live => true do
39
43
  search = Book.search 'gods', :select => "*, weight()"
40
44
  search.masks << ThinkingSphinx::Masks::WeightEnumeratorMask
41
45
 
42
- expectations = [[gods, 2500]]
46
+ if ENV["SPHINX_ENGINE"] == "sphinx" && ENV["SPHINX_VERSION"].to_f > 3.3
47
+ expectations = [[gods, 20_000.0]]
48
+ else
49
+ expectations = [[gods, 2500]]
50
+ end
43
51
  search.each_with_weight do |result, weight|
44
52
  expectation = expectations.shift
45
53
 
@@ -52,7 +52,7 @@ describe '64 bit document ids', :live => true do
52
52
  context 'with Real-Time' do
53
53
  it 'handles large 32 bit integers with an offset multiplier' do
54
54
  product = Product.create! :name => "Widget"
55
- product.update_attributes :id => 980190962
55
+ product.update :id => 980190962
56
56
  expect(
57
57
  Product.search('widget', :indices => ['product_core']).to_a
58
58
  ).to eq([product])
@@ -38,10 +38,20 @@ describe 'Searching by latitude and longitude', :live => true do
38
38
  expected = {:mysql => 250326.906250, :postgresql => 250331.234375}
39
39
  end
40
40
 
41
- if ActiveRecord::Base.configurations['test']['adapter'][/postgres/]
42
- expect(cities.first.geodist).to eq(expected[:postgresql])
41
+ adapter = nil
42
+
43
+ if ActiveRecord::VERSION::STRING.to_f > 6.0
44
+ adapter = ActiveRecord::Base.configurations.configs_for.first.adapter
45
+ elsif ActiveRecord::VERSION::STRING.to_f > 5.2
46
+ adapter = ActiveRecord::Base.configurations.configs_for.first.config["adapter"]
47
+ else
48
+ adapter = ActiveRecord::Base.configurations['test']['adapter']
49
+ end
50
+
51
+ if adapter[/postgres/]
52
+ expect(cities.first.geodist).to be_within(0.01).of(expected[:postgresql])
43
53
  else # mysql
44
- expect(cities.first.geodist).to eq(expected[:mysql])
54
+ expect(cities.first.geodist).to be_within(0.01).of(expected[:mysql])
45
55
  end
46
56
  end
47
57
 
@@ -34,7 +34,7 @@ describe "Merging deltas", :live => true do
34
34
  Book.search("Space", :indices => ["book_core"]).to_a
35
35
  ).to eq([race])
36
36
 
37
- race.reload.update_attributes :title => "The Hate Race"
37
+ race.reload.update :title => "The Hate Race"
38
38
  sleep 0.25
39
39
  expect(
40
40
  Book.search("Race", :indices => ["book_delta"]).to_a
@@ -4,13 +4,22 @@ require 'acceptance/spec_helper'
4
4
 
5
5
  describe 'Paginating search results', :live => true do
6
6
  it "tracks how many results there are in total" do
7
+ expect(Article.search.total_entries).to be_zero
8
+
7
9
  21.times { |number| Article.create :title => "Article #{number}" }
8
10
  index
9
11
 
10
- expect(Article.search.total_entries).to eq(21)
12
+ if ENV["SPHINX_ENGINE"] == "manticore" && ENV["SPHINX_VERSION"].to_f >= 4.0
13
+ # I suspect this is a bug in Manticore?
14
+ expect(Article.search.total_entries).to eq(22)
15
+ else
16
+ expect(Article.search.total_entries).to eq(21)
17
+ end
11
18
  end
12
19
 
13
20
  it "paginates the result set by default" do
21
+ expect(Article.search.total_entries).to be_zero
22
+
14
23
  21.times { |number| Article.create :title => "Article #{number}" }
15
24
  index
16
25
 
@@ -18,9 +27,16 @@ describe 'Paginating search results', :live => true do
18
27
  end
19
28
 
20
29
  it "tracks the number of pages" do
30
+ expect(Article.search.total_entries).to be_zero
31
+
21
32
  21.times { |number| Article.create :title => "Article #{number}" }
22
33
  index
23
34
 
24
- expect(Article.search.total_pages).to eq(2)
35
+ if ENV["SPHINX_ENGINE"] == "manticore" && ENV["SPHINX_VERSION"].to_f >= 4.0
36
+ # I suspect this is a bug in Manticore?
37
+ expect(Article.search.total_pages).to eq(1)
38
+ else
39
+ expect(Article.search.total_pages).to eq(2)
40
+ end
25
41
  end
26
42
  end
@@ -11,7 +11,7 @@ describe 'Updates to records in real-time indices', :live => true do
11
11
 
12
12
  it "handles attributes for sortable fields accordingly" do
13
13
  product = Product.create! :name => 'Red Fish'
14
- product.update_attributes :name => 'Blue Fish'
14
+ product.update :name => 'Blue Fish'
15
15
 
16
16
  expect(Product.search('blue fish', :indices => ['product_core']).to_a).
17
17
  to eq([product])
@@ -22,7 +22,7 @@ describe 'Updates to records in real-time indices', :live => true do
22
22
 
23
23
  expect(Admin::Person.search('Death').to_a).to eq([person])
24
24
 
25
- person.update_attributes :name => 'Mort'
25
+ person.update :name => 'Mort'
26
26
 
27
27
  expect(Admin::Person.search('Death').to_a).to be_empty
28
28
  expect(Admin::Person.search('Mort').to_a).to eq([person])
@@ -17,7 +17,7 @@ describe 'Searching with filters', :live => true do
17
17
  grave = Book.create! :title => 'The Graveyard Book', :year => 2009
18
18
  index
19
19
 
20
- expect(Book.search(:with => {:year => [2001, 2005]}).to_a).to eq([gods, boys])
20
+ expect(Book.search(:with => {:year => [2001, 2005]}).to_a).to match_array([gods, boys])
21
21
  end
22
22
 
23
23
  it "limits results by a ranged filter" do
@@ -31,7 +31,7 @@ describe 'Searching with filters', :live => true do
31
31
  index
32
32
 
33
33
  expect(Book.search(:with => {:created_at => 6.days.ago..2.days.ago}).to_a).
34
- to eq([gods, boys])
34
+ to match_array([gods, boys])
35
35
  end
36
36
 
37
37
  it "limits results by exclusive filters on single values" do
@@ -154,6 +154,6 @@ describe 'Searching with filters', :live => true do
154
154
  expect(products.to_a).to eq([pancakes])
155
155
 
156
156
  products = Product.search :with => {"options.sugar" => 1}
157
- expect(products.to_a).to eq([pancakes, waffles])
157
+ expect(products.to_a).to match_array([pancakes, waffles])
158
158
  end if JSONColumn.call
159
159
  end
@@ -16,7 +16,7 @@ describe 'SQL delta indexing', :live => true do
16
16
  )
17
17
  sleep 0.25
18
18
 
19
- expect(Book.search('Terry Pratchett').to_a).to eq([guards, men])
19
+ expect(Book.search('Terry Pratchett').to_a).to match_array([guards, men])
20
20
  end
21
21
 
22
22
  it "automatically indexes updated records" do
@@ -25,7 +25,7 @@ describe 'SQL delta indexing', :live => true do
25
25
 
26
26
  expect(Book.search('Harry').to_a).to eq([book])
27
27
 
28
- book.reload.update_attributes(:author => 'Terry Pratchett')
28
+ book.reload.update(:author => 'Terry Pratchett')
29
29
  sleep 0.25
30
30
 
31
31
  expect(Book.search('Terry').to_a).to eq([book])
@@ -37,7 +37,7 @@ describe 'SQL delta indexing', :live => true do
37
37
 
38
38
  expect(Book.search('Harry').to_a).to eq([book])
39
39
 
40
- book.reload.update_attributes(:author => 'Terry Pratchett')
40
+ book.reload.update(:author => 'Terry Pratchett')
41
41
  sleep 0.25
42
42
 
43
43
  expect(Book.search('Harry')).to be_empty
@@ -49,7 +49,7 @@ describe 'SQL delta indexing', :live => true do
49
49
 
50
50
  expect(Album.search('Whitloms').to_a).to eq([album])
51
51
 
52
- album.reload.update_attributes(:artist => 'The Whitlams')
52
+ album.reload.update(:artist => 'The Whitlams')
53
53
  sleep 0.25
54
54
 
55
55
  expect(Book.search('Whitloms')).to be_empty
@@ -63,4 +63,16 @@ describe 'SQL delta indexing', :live => true do
63
63
 
64
64
  expect(Book.search('Gaiman').to_a).to eq([book])
65
65
  end
66
+
67
+ it "updates associated models" do
68
+ colour = Colour.create(:name => 'green')
69
+ sleep 0.25
70
+
71
+ expect(Colour.search('green').to_a).to eq([colour])
72
+
73
+ tee = colour.tees.create
74
+ sleep 0.25
75
+
76
+ expect(Colour.search(:with => {:tee_ids => tee.id}).to_a).to eq([colour])
77
+ end
66
78
  end
@@ -12,11 +12,13 @@ class SphinxController
12
12
 
13
13
  ThinkingSphinx::Configuration.reset
14
14
 
15
- ActiveSupport::Dependencies.loaded.each do |path|
16
- $LOADED_FEATURES.delete "#{path}.rb"
17
- end
15
+ if Rails::VERSION::MAJOR < 7
16
+ ActiveSupport::Dependencies.loaded.each do |path|
17
+ $LOADED_FEATURES.delete "#{path}.rb"
18
+ end
18
19
 
19
- ActiveSupport::Dependencies.clear
20
+ ActiveSupport::Dependencies.clear
21
+ end
20
22
 
21
23
  config.searchd.mysql41 = 9307
22
24
  config.settings['quiet_deltas'] = true
@@ -6,22 +6,22 @@ module SphinxHelpers
6
6
  end
7
7
 
8
8
  def index(*indices)
9
- sleep 0.5 if ENV['TRAVIS']
9
+ sleep 0.5 if ENV['CI']
10
10
 
11
11
  yield if block_given?
12
12
 
13
13
  sphinx.index *indices
14
14
  sleep 0.25
15
- sleep 0.5 if ENV['TRAVIS']
15
+ sleep 0.5 if ENV['CI']
16
16
  end
17
17
 
18
18
  def merge
19
- sleep 0.5 if ENV['TRAVIS']
19
+ sleep 0.5 if ENV['CI']
20
20
  sleep 0.5
21
21
 
22
22
  sphinx.merge
23
23
  sleep 1.5
24
- sleep 0.5 if ENV['TRAVIS']
24
+ sleep 0.5 if ENV['CI']
25
25
  end
26
26
  end
27
27
 
@@ -10,7 +10,7 @@ describe 'Suspend deltas for a given action', :live => true do
10
10
  expect(Book.search('Harry').to_a).to eq([book])
11
11
 
12
12
  ThinkingSphinx::Deltas.suspend :book do
13
- book.reload.update_attributes(:author => 'Terry Pratchett')
13
+ book.reload.update(:author => 'Terry Pratchett')
14
14
  sleep 0.25
15
15
 
16
16
  expect(Book.search('Terry').to_a).to eq([])
@@ -27,7 +27,7 @@ describe 'Suspend deltas for a given action', :live => true do
27
27
  expect(Book.search('Harry').to_a).to eq([book])
28
28
 
29
29
  ThinkingSphinx::Deltas.suspend :book do
30
- book.reload.update_attributes(:author => 'Terry Pratchett')
30
+ book.reload.update(:author => 'Terry Pratchett')
31
31
  sleep 0.25
32
32
 
33
33
  expect(Book.search('Terry').to_a).to eq([])
@@ -44,7 +44,7 @@ describe 'Suspend deltas for a given action', :live => true do
44
44
  expect(Book.search('Harry').to_a).to eq([book])
45
45
 
46
46
  ThinkingSphinx::Deltas.suspend_and_update :book do
47
- book.reload.update_attributes(:author => 'Terry Pratchett')
47
+ book.reload.update(:author => 'Terry Pratchett')
48
48
  sleep 0.25
49
49
 
50
50
  expect(Book.search('Terry').to_a).to eq([])
@@ -10,7 +10,6 @@ ThinkingSphinx::Index.define :article, :with => :active_record do
10
10
  has taggings.created_at, :as => :taggings_at, :type => :timestamp
11
11
 
12
12
  set_property :min_infix_len => 4
13
- set_property :enable_star => true
14
13
  end
15
14
 
16
15
  ThinkingSphinx::Index.define :article, :with => :active_record,
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ ThinkingSphinx::Index.define :colour, :with => :active_record, :delta => true do
4
+ indexes name
5
+
6
+ has tees.id, :as => :tee_ids
7
+ end
@@ -3,5 +3,7 @@
3
3
  class Admin::Person < ActiveRecord::Base
4
4
  self.table_name = 'admin_people'
5
5
 
6
- after_save ThinkingSphinx::RealTime.callback_for('admin/person')
6
+ ThinkingSphinx::Callbacks.append(
7
+ self, 'admin/person', :behaviours => [:sql, :real_time]
8
+ )
7
9
  end
@@ -6,7 +6,9 @@ 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)
9
+ ThinkingSphinx::Callbacks.append(
10
+ self, :behaviours => [:sql, :real_time, :deltas]
11
+ )
10
12
 
11
13
  validates :id, :presence => true, :uniqueness => true
12
14
  validates :integer_id, :presence => true, :uniqueness => true
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Animal < ActiveRecord::Base
4
+ ThinkingSphinx::Callbacks.append(self, :behaviours => [:sql])
4
5
  end
@@ -4,4 +4,6 @@ class Article < ActiveRecord::Base
4
4
  belongs_to :user
5
5
  has_many :taggings
6
6
  has_many :tags, :through => :taggings
7
+
8
+ ThinkingSphinx::Callbacks.append(self, :behaviours => [:sql, :updates])
7
9
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Bird < Animal
4
+ ThinkingSphinx::Callbacks.append(self, :behaviours => [:sql])
4
5
  end
@@ -5,6 +5,8 @@ class Book < ActiveRecord::Base
5
5
 
6
6
  has_and_belongs_to_many :genres
7
7
 
8
+ ThinkingSphinx::Callbacks.append(self, :behaviours => [:sql, :deltas])
9
+
8
10
  sphinx_scope(:by_query) { |query| query }
9
11
  sphinx_scope(:by_year) do |year|
10
12
  {:with => {:year => year}}
@@ -3,5 +3,5 @@
3
3
  class Car < ActiveRecord::Base
4
4
  belongs_to :manufacturer
5
5
 
6
- after_save ThinkingSphinx::RealTime.callback_for(:car)
6
+ ThinkingSphinx::Callbacks.append(self, :behaviours => [:real_time])
7
7
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class City < ActiveRecord::Base
4
+ ThinkingSphinx::Callbacks.append(self, :behaviours => [:sql])
5
+
4
6
  scope :ordered, lambda { order(:name) }
5
7
  end
@@ -2,4 +2,6 @@
2
2
 
3
3
  class Colour < ActiveRecord::Base
4
4
  has_many :tees
5
+
6
+ ThinkingSphinx::Callbacks.append(self, behaviours: [:sql, :deltas])
5
7
  end
@@ -4,5 +4,5 @@ class Product < ActiveRecord::Base
4
4
  has_many :categorisations
5
5
  has_many :categories, :through => :categorisations
6
6
 
7
- after_save ThinkingSphinx::RealTime.callback_for(:product)
7
+ ThinkingSphinx::Callbacks.append(self, :behaviours => [:real_time])
8
8
  end
@@ -2,4 +2,9 @@
2
2
 
3
3
  class Tee < ActiveRecord::Base
4
4
  belongs_to :colour
5
+
6
+ ThinkingSphinx::Callbacks.append(self, :behaviours => [:sql])
7
+ ThinkingSphinx::Callbacks.append(
8
+ self, behaviours: [:sql, :deltas], :path => [:colour]
9
+ )
5
10
  end
@@ -3,6 +3,8 @@
3
3
  class User < ActiveRecord::Base
4
4
  has_many :articles
5
5
 
6
+ ThinkingSphinx::Callbacks.append(self, :behaviours => [:sql])
7
+
6
8
  default_scope { order(:id) }
7
9
  scope :recent, lambda { where('created_at > ?', 1.week.ago) }
8
10
  end
@@ -1,6 +1,11 @@
1
1
  test:
2
2
  adapter: <%= ENV['DATABASE'] || 'mysql2' %>
3
3
  database: thinking_sphinx
4
- username: <%= ENV['DATABASE'] == 'postgresql' ? ENV['USER'] : 'root' %>
4
+ username: <%= ENV['DATABASE'] == 'postgresql' ? 'postgres' : 'root' %>
5
+ <% if ENV["CI"] %>
6
+ password: thinking_sphinx
7
+ host: 127.0.0.1
8
+ port: <%= ENV['DATABASE'] == 'postgresql' ? 5432 : 3306 %>
9
+ <% end %>
5
10
  min_messages: warning
6
11
  encoding: utf8
@@ -68,6 +68,7 @@ ActiveRecord::Schema.define do
68
68
 
69
69
  create_table(:colours, :force => true) do |t|
70
70
  t.string :name
71
+ t.boolean :delta, :null => false, :default => true
71
72
  t.timestamps null: false
72
73
  end
73
74
 
@@ -19,12 +19,13 @@ describe ThinkingSphinx::ActiveRecord::Callbacks::UpdateCallbacks do
19
19
  let(:klass) { double(:name => 'Article') }
20
20
  let(:configuration) { double('configuration',
21
21
  :settings => {'attribute_updates' => true},
22
- :indices_for_references => [index]) }
22
+ :indices_for_references => [index], :index_set_class => set_class) }
23
23
  let(:connection) { double('connection', :execute => '') }
24
24
  let(:index) { double 'index', :name => 'article_core',
25
25
  :sources => [source], :document_id_for_key => 3, :distributed? => false,
26
26
  :type => 'plain', :primary_key => :id}
27
27
  let(:source) { double('source', :attributes => []) }
28
+ let(:set_class) { double(:reference_name => :article) }
28
29
 
29
30
  before :each do
30
31
  stub_const 'ThinkingSphinx::Configuration',
@@ -5,7 +5,9 @@ require 'spec_helper'
5
5
  describe ThinkingSphinx::ActiveRecord::Index do
6
6
  let(:index) { ThinkingSphinx::ActiveRecord::Index.new :user }
7
7
  let(:config) { double('config', :settings => {},
8
- :indices_location => 'location', :next_offset => 8) }
8
+ :indices_location => 'location', :next_offset => 8,
9
+ :index_set_class => index_set_class) }
10
+ let(:index_set_class) { double :reference_name => :user }
9
11
 
10
12
  before :each do
11
13
  allow(ThinkingSphinx::Configuration).to receive_messages :instance => config
@@ -94,18 +96,6 @@ describe ThinkingSphinx::ActiveRecord::Index do
94
96
  end
95
97
  end
96
98
 
97
- describe '#docinfo' do
98
- it "defaults to extern" do
99
- expect(index.docinfo).to eq(:extern)
100
- end
101
-
102
- it "can be disabled" do
103
- config.settings["skip_docinfo"] = true
104
-
105
- expect(index.docinfo).to be_nil
106
- end
107
- end
108
-
109
99
  describe '#document_id_for_key' do
110
100
  it "calculates the document id based on offset and number of indices" do
111
101
  allow(config).to receive_message_chain(:indices, :count).and_return(5)
@@ -15,8 +15,13 @@ describe ThinkingSphinx::ActiveRecord::Interpreter do
15
15
  let(:block) { Proc.new { } }
16
16
 
17
17
  before :each do
18
- allow(ThinkingSphinx::ActiveRecord::SQLSource).to receive_messages :new => source
19
- allow(source).to receive_messages :model => model
18
+ allow(ThinkingSphinx::ActiveRecord::SQLSource).to receive_messages(
19
+ :new => source
20
+ )
21
+
22
+ allow(source).to receive_messages(
23
+ :model => model, :add_attribute => nil, :add_field => nil
24
+ )
20
25
  end
21
26
 
22
27
  describe '.translate!' do
@@ -94,17 +99,15 @@ describe ThinkingSphinx::ActiveRecord::Interpreter do
94
99
  end
95
100
 
96
101
  it "adds an attribute to the source" do
97
- instance.has column
102
+ expect(source).to receive(:add_attribute).with(attribute)
98
103
 
99
- expect(source.attributes).to include(attribute)
104
+ instance.has column
100
105
  end
101
106
 
102
107
  it "adds multiple attributes when passed multiple columns" do
103
- instance.has column, column
108
+ expect(source).to receive(:add_attribute).with(attribute).twice
104
109
 
105
- expect(source.attributes.select { |saved_attribute|
106
- saved_attribute == attribute
107
- }.length).to eq(2)
110
+ instance.has column, column
108
111
  end
109
112
  end
110
113
 
@@ -144,17 +147,15 @@ describe ThinkingSphinx::ActiveRecord::Interpreter do
144
147
  end
145
148
 
146
149
  it "adds a field to the source" do
147
- instance.indexes column
150
+ expect(source).to receive(:add_field).with(field)
148
151
 
149
- expect(source.fields).to include(field)
152
+ instance.indexes column
150
153
  end
151
154
 
152
155
  it "adds multiple fields when passed multiple columns" do
153
- instance.indexes column, column
156
+ expect(source).to receive(:add_field).with(field).twice
154
157
 
155
- expect(source.fields.select { |saved_field|
156
- saved_field == field
157
- }.length).to eq(2)
158
+ instance.indexes column, column
158
159
  end
159
160
  end
160
161