thinking-sphinx 4.4.1 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +12 -21
  3. data/Appraisals +1 -16
  4. data/CHANGELOG.markdown +20 -0
  5. data/README.textile +14 -16
  6. data/bin/loadsphinx +5 -0
  7. data/lib/thinking_sphinx/active_record/association_proxy/attribute_finder.rb +1 -1
  8. data/lib/thinking_sphinx/active_record/base.rb +2 -6
  9. data/lib/thinking_sphinx/active_record/callbacks/delete_callbacks.rb +1 -1
  10. data/lib/thinking_sphinx/active_record/callbacks/delta_callbacks.rb +3 -2
  11. data/lib/thinking_sphinx/active_record/callbacks/update_callbacks.rb +1 -1
  12. data/lib/thinking_sphinx/active_record/interpreter.rb +4 -4
  13. data/lib/thinking_sphinx/active_record/sql_source.rb +12 -0
  14. data/lib/thinking_sphinx/active_record/sql_source/template.rb +2 -2
  15. data/lib/thinking_sphinx/callbacks.rb +9 -0
  16. data/lib/thinking_sphinx/callbacks/appender.rb +47 -0
  17. data/lib/thinking_sphinx/core/index.rb +1 -2
  18. data/lib/thinking_sphinx/deletion.rb +18 -17
  19. data/lib/thinking_sphinx/index_set.rb +7 -3
  20. data/lib/thinking_sphinx/middlewares/sphinxql.rb +1 -1
  21. data/lib/thinking_sphinx/railtie.rb +1 -1
  22. data/lib/thinking_sphinx/real_time/index.rb +4 -0
  23. data/lib/thinking_sphinx/real_time/interpreter.rb +8 -6
  24. data/lib/thinking_sphinx/real_time/transcriber.rb +35 -19
  25. data/spec/acceptance/big_integers_spec.rb +1 -1
  26. data/spec/acceptance/merging_spec.rb +1 -1
  27. data/spec/acceptance/real_time_updates_spec.rb +2 -2
  28. data/spec/acceptance/sql_deltas_spec.rb +3 -3
  29. data/spec/acceptance/suspended_deltas_spec.rb +3 -3
  30. data/spec/internal/app/models/admin/person.rb +3 -1
  31. data/spec/internal/app/models/album.rb +3 -1
  32. data/spec/internal/app/models/animal.rb +1 -0
  33. data/spec/internal/app/models/article.rb +2 -0
  34. data/spec/internal/app/models/bird.rb +1 -0
  35. data/spec/internal/app/models/book.rb +2 -0
  36. data/spec/internal/app/models/car.rb +1 -1
  37. data/spec/internal/app/models/city.rb +2 -0
  38. data/spec/internal/app/models/product.rb +1 -1
  39. data/spec/internal/app/models/tee.rb +2 -0
  40. data/spec/internal/app/models/user.rb +2 -0
  41. data/spec/thinking_sphinx/active_record/callbacks/update_callbacks_spec.rb +2 -1
  42. data/spec/thinking_sphinx/active_record/index_spec.rb +0 -12
  43. data/spec/thinking_sphinx/active_record/interpreter_spec.rb +15 -14
  44. data/spec/thinking_sphinx/active_record/sql_source_spec.rb +38 -0
  45. data/spec/thinking_sphinx/deletion_spec.rb +5 -4
  46. data/spec/thinking_sphinx/index_set_spec.rb +28 -12
  47. data/spec/thinking_sphinx/middlewares/sphinxql_spec.rb +2 -1
  48. data/spec/thinking_sphinx/real_time/index_spec.rb +38 -12
  49. data/spec/thinking_sphinx/real_time/interpreter_spec.rb +14 -14
  50. data/spec/thinking_sphinx/real_time/transcriber_spec.rb +9 -1
  51. data/thinking-sphinx.gemspec +3 -3
  52. metadata +8 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c8afa50f4e183cba6d6ce4776b66ab3f274dd538af0ae98e1afd2d73132bc73d
4
- data.tar.gz: b4a17507c4f023936ff6dabf1c8d4ae9cff2e08ba94808299ae7d7e9edc6c38d
3
+ metadata.gz: 7f0e9705ca201e4e4aad6aee89116b150a6dbef077ae949eeddc594d8b3c2c50
4
+ data.tar.gz: 336af45f825119fde255c8bb373094e4d63f2ae6a98d01495410e68165534555
5
5
  SHA512:
6
- metadata.gz: 0cac814c511fc65b6bd477ff5b7861bedc551394d53655c75294d834bdc48ae6fa5b361e5e6b3e7a76c4280bc737c65188f21ed72abf18e352a55d967c354249
7
- data.tar.gz: d79216c06faaa641ea71a30234ad6923fbbb9f2c0b5b0a75a2f7ce62720e6cbf91233965f6d2b0c7133e6e63c81c89db59306c3eb13da194c51fc009bf124041
6
+ metadata.gz: b8d6ec2efdace6c3b214ca488f0b1befdceb61de3b2287d8eb0ce6d6eeb489619bdda92402448b51e7655936b959bfc33d94bc173b171ad542bf02133b6fe394
7
+ data.tar.gz: ca5e3308d74888ec60cbc0144f7972dfc5602552f6e03396f29f2ab010e7bbfebc0a2f8781d2345eeddc97a3cafcaaba24221e3c560e231a5fb51cd4180f6f57
@@ -1,39 +1,30 @@
1
1
  language: ruby
2
2
  dist: xenial
3
3
  rvm:
4
- - 2.3.8
5
- - 2.4.6
6
- - 2.5.5
7
- - 2.6.3
4
+ - 2.4.10
5
+ - 2.5.8
6
+ - 2.6.6
7
+ - 2.7.1
8
8
  before_install:
9
- - pip install --upgrade --user awscli
10
9
  - gem update --system
11
- - gem uninstall -v '>= 2' -i $(rvm gemdir)@global -ax bundler || true
12
- - gem install bundler -v '< 2'
10
+ - gem install bundler -v '1.17.3'
11
+ install: bundle _1.17.3_ install --jobs=3 --retry=3
13
12
  before_script:
14
13
  - mysql -e 'create database thinking_sphinx;' > /dev/null
15
14
  - psql -c 'create database thinking_sphinx;' -U postgres >/dev/null
16
15
  - "./bin/loadsphinx $SPHINX_VERSION $SPHINX_ENGINE"
17
- - bundle exec appraisal install
18
- script: bundle exec appraisal rspec
16
+ - bundle _1.17.3_ exec appraisal install
17
+ script: bundle _1.17.3_ exec appraisal rspec
19
18
  env:
20
- global:
21
- - secure: cUPinkilBafqDSPsTkl/PXYc2aXNKUQKXGK8poBBMqKN9/wjfJx1DWgtowDKalekdZELxDhc85Ye3bL1xlW4nLjOu+U6Tkt8eNw2Nhs1flodHzA/RyENdBLr/tBHt43EjkrDehZx5sBHmWQY4miHs8AJz0oKO9Ae2inTOHx9Iuc=
22
19
  matrix:
23
- - DATABASE=mysql2 SPHINX_VERSION=2.1.9 SPHINX_ENGINE=sphinx
24
- - DATABASE=postgresql SPHINX_VERSION=2.1.9 SPHINX_ENGINE=sphinx
25
20
  - DATABASE=mysql2 SPHINX_VERSION=2.2.11 SPHINX_ENGINE=sphinx
26
21
  - DATABASE=postgresql SPHINX_VERSION=2.2.11 SPHINX_ENGINE=sphinx
27
- - DATABASE=mysql2 SPHINX_VERSION=3.0.3 SPHINX_ENGINE=sphinx
28
- - DATABASE=postgresql SPHINX_VERSION=3.0.3 SPHINX_ENGINE=sphinx
29
- - DATABASE=mysql2 SPHINX_VERSION=3.1.1 SPHINX_ENGINE=sphinx
30
- - DATABASE=mysql2 SPHINX_VERSION=2.6.4 SPHINX_ENGINE=manticore
31
- - DATABASE=postgresql SPHINX_VERSION=2.6.4 SPHINX_ENGINE=manticore
32
- - DATABASE=mysql2 SPHINX_VERSION=2.7.5 SPHINX_ENGINE=manticore
33
- - DATABASE=postgresql SPHINX_VERSION=2.7.5 SPHINX_ENGINE=manticore
22
+ - DATABASE=mysql2 SPHINX_VERSION=3.2.1 SPHINX_ENGINE=sphinx
34
23
  - DATABASE=mysql2 SPHINX_VERSION=2.8.2 SPHINX_ENGINE=manticore
35
24
  - DATABASE=postgresql SPHINX_VERSION=2.8.2 SPHINX_ENGINE=manticore
36
- # - DATABASE=postgresql SPHINX_VERSION=3.1.1 SPHINX_ENGINE=sphinx
25
+ - DATABASE=mysql2 SPHINX_VERSION=3.4.2 SPHINX_ENGINE=manticore
26
+ - DATABASE=postgresql SPHINX_VERSION=3.4.2 SPHINX_ENGINE=manticore
27
+ # - DATABASE=postgresql SPHINX_VERSION=3.2.1 SPHINX_ENGINE=sphinx
37
28
  sudo: false
38
29
  addons:
39
30
  postgresql: '9.4'
data/Appraisals CHANGED
@@ -1,22 +1,7 @@
1
- appraise 'rails_3_2' do
2
- gem 'rails', '~> 3.2.22.2'
3
- gem 'mysql2', '~> 0.3.10', :platform => :ruby
4
- end if RUBY_VERSION.to_f <= 2.3
5
-
6
- appraise 'rails_4_0' do
7
- gem 'rails', '~> 4.0.13'
8
- gem 'mysql2', '~> 0.3.10', :platform => :ruby
9
- end if RUBY_VERSION.to_f <= 2.3
10
-
11
- appraise 'rails_4_1' do
12
- gem 'rails', '~> 4.1.15'
13
- gem 'mysql2', '~> 0.3.13', :platform => :ruby
14
- end if RUBY_VERSION.to_f <= 2.3
15
-
16
1
  appraise 'rails_4_2' do
17
2
  gem 'rails', '~> 4.2.6'
18
3
  gem 'mysql2', '~> 0.4.0', :platform => :ruby
19
- end if RUBY_VERSION.to_f <= 2.3
4
+ end if RUBY_VERSION.to_f <= 2.4
20
5
 
21
6
  appraise 'rails_5_0' do
22
7
  if RUBY_PLATFORM == "java"
@@ -2,6 +2,26 @@
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
+ ## 5.0.0 - 2020-07-20
6
+
7
+ [Release Notes](https://github.com/pat/thinking-sphinx/releases/tag/v5.0.0)
8
+
9
+ ### Added
10
+
11
+ * New interface for adding callbacks to indexed models (which is no longer done automatically). Discussed in [#1173](https://github.com/pat/thinking-sphinx/issues/1173) and committed via [#1175](https://github.com/pat/thinking-sphinx/pull/1175). **This is a breaking change - you will need to add these callbacks. See [the full release notes](https://github.com/pat/thinking-sphinx/releases/tag/v5.0.0) for examples.**
12
+ * Fields and attributes can be overriden - whichever's defined last with a given name is the definition that's used. This is an edge case, but useful if you want to override any of the default fields/indices. (Requested by @kalsan in [#1172](https://github.com/pat/thinking-sphinx/issues/1172).)
13
+ * Custom index_set_class implementations can now expect the `:instances` option to be set alongside `:classes`, which is useful in cases to limit the indices returned if you're splitting index data for given classes/models into shards. (Introduced in PR [#1171](https://github.com/pat/thinking-sphinx/pull/1171) after discussions with @lunaru in [#1166](https://github.com/pat/thinking-sphinx/issues/1166).)
14
+
15
+ ### Changed
16
+
17
+ * Sphinx 2.2.11 or newer is required, or Manticore 2.8.2 or newer.
18
+ * Ruby 2.4 or newer is required.
19
+ * Rails 4.2 or newer is required.
20
+ * Remove internal uses of `send`, replaced with `public_send` as that's available in all supported Ruby versions.
21
+ * Deletion statements are simplified by avoiding the need to calculate document keys/offsets (@njakobsen via [#1134](https://github.com/pat/thinking-sphinx/issues/1134)).
22
+ * 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)).
23
+ * 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).)
24
+
5
25
  ## 4.4.1 - 2019-08-23
6
26
 
7
27
  [Release Notes](https://github.com/pat/thinking-sphinx/releases/tag/v4.4.1)
@@ -1,22 +1,22 @@
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.4.1.
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 v5.0.0.
4
4
 
5
5
  h2. Upgrading
6
6
 
7
7
  Please refer to "the changelog":https://github.com/pat/thinking-sphinx/blob/develop/CHANGELOG.markdown and "release notes":https://github.com/pat/thinking-sphinx/releases for any changes you need to make when upgrading. The release notes in particular are quite good at covering breaking changes and more details for new features.
8
8
 
9
- The documentation also has more details on what's involved for upgrading from "v3 to v4":https://freelancing-gods.com/thinking-sphinx/v4/upgrading.html, and "v1/v2 to v3":https://freelancing-gods.com/thinking-sphinx/v3/upgrading.html.
9
+ The documentation also has more details on what's involved for upgrading from "v4 to v5":https://freelancing-gods.com/thinking-sphinx/v5/upgrading.html, "v3 to v4":https://freelancing-gods.com/thinking-sphinx/v4/upgrading.html, and "v1/v2 to v3":https://freelancing-gods.com/thinking-sphinx/v3/upgrading.html.
10
10
 
11
11
  h2. Installation
12
12
 
13
13
  It's a gem, so install it like you would any other gem. You will also need to specify the mysql2 gem if you're using MRI, or jdbc-mysql if you're using JRuby:
14
14
 
15
- <pre><code>gem 'mysql2', '~> 0.3', :platform => :ruby
15
+ <pre><code>gem 'mysql2', '~> 0.4', :platform => :ruby
16
16
  gem 'jdbc-mysql', '~> 5.1.35', :platform => :jruby
17
- gem 'thinking-sphinx', '~> 4.4'</code></pre>
17
+ gem 'thinking-sphinx', '~> 5.0'</code></pre>
18
18
 
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.
19
+ The MySQL gems mentioned are required for connecting to Sphinx, so please include it even when you're using PostgreSQL for your database.
20
20
 
21
21
  You'll also need to install Sphinx - this is covered in "the extended documentation":https://freelancing-gods.com/thinking-sphinx/installing_sphinx.html.
22
22
 
@@ -29,10 +29,10 @@ 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.3 | v2.3.8, v2.4.5, v2.5.3, v2.6.1 |
33
- | Sphinx | v2.1.2 | v2.1.9, v2.2.11, v3.0.3, v3.1.1 |
34
- | Manticore | v2.6.3 | v2.6.4, v2.7.5, v2.8.1 |
35
- | ActiveRecord | v3.2 | v3.2..v6.0 |
32
+ | Ruby | v2.4 | v2.4, v2.5, v2.6, v2.7 |
33
+ | Sphinx | v2.2.11 | v2.2.11, v3.2.1 |
34
+ | Manticore | v2.8 | v2.8, v3.4 |
35
+ | ActiveRecord | v4.2 | v4.2..v6.0 |
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
 
@@ -40,19 +40,17 @@ It should also work with JRuby, but the test environment on Travis CI has been t
40
40
 
41
41
  h3. Sphinx or Manticore
42
42
 
43
- Thinking Sphinx v3 is currently built for Sphinx 2.1.2 or newer, or Manticore v2.6+.
43
+ Thinking Sphinx is currently built for Sphinx 2.2.11 or newer (though it'll likely work with 2.1.x releases), or Manticore v2.8+.
44
44
 
45
45
  h3. Rails and ActiveRecord
46
46
 
47
- Currently Thinking Sphinx 3 is built to support Rails/ActiveRecord 3.2 or newer. If you're using Sinatra and ActiveRecord instead of Rails, that's fine - just make sure you add the @:require => 'thinking_sphinx/sinatra'@ option when listing @thinking-sphinx@ in your Gemfile.
47
+ Currently Thinking Sphinx is built to support Rails/ActiveRecord 4.2 or newer. If you're using Sinatra and ActiveRecord instead of Rails, that's fine - just make sure you add the @:require => 'thinking_sphinx/sinatra'@ option when listing @thinking-sphinx@ in your Gemfile.
48
48
 
49
- Please note that if you're referring to polymorphic associations in your index definitions, you'll want to be using Rails/ActiveRecord 4.0 or newer. Supporting polymorphic associations and Rails/ActiveRecord 3.2 is problematic, and likely will not be addressed in the future.
50
-
51
- If you want ActiveRecord 3.1 support, then refer to the 3.0.x releases of Thinking Sphinx. Anything older than that, then you're stuck with Thinking Sphinx v2.x (for Rails/ActiveRecord 3.0) or v1.x (Rails 2.3). Please note that these older versions are no longer actively supported.
49
+ If you want ActiveRecord 3.2-4.1 support, then refer to the 4.x releases of Thinking Sphinx. Or, for ActiveRecord 3.1 support, then refer to the 3.0.x releases. Anything older than that, then you're stuck with Thinking Sphinx v2.x (for Rails/ActiveRecord 3.0) or v1.x (Rails 2.3). Please note that these older versions are no longer actively supported.
52
50
 
53
51
  h3. Ruby
54
52
 
55
- You'll need either the standard Ruby (v2.3 or newer) or JRuby (9.1 or newer).
53
+ You'll need either the standard Ruby (v2.4 or newer) or JRuby (9.1 or newer).
56
54
 
57
55
  h3. Database Versions
58
56
 
@@ -81,4 +79,4 @@ You can then run the unit tests with @rake spec:unit@, the acceptance tests with
81
79
 
82
80
  h2. Licence
83
81
 
84
- Copyright (c) 2007-2019, Thinking Sphinx is developed and maintained by Pat Allan, and is released under the open MIT Licence. Many thanks to "all who have contributed patches":https://github.com/pat/thinking-sphinx/contributors.
82
+ Copyright (c) 2007-2020, Thinking Sphinx is developed and maintained by Pat Allan, and is released under the open MIT Licence. Many thanks to "all who have contributed patches":https://github.com/pat/thinking-sphinx/contributors.
@@ -22,6 +22,9 @@ load_sphinx () {
22
22
  3.1.1)
23
23
  url="http://sphinxsearch.com/files/sphinx-3.1.1-612d99f-linux-amd64.tar.gz"
24
24
  format="gz";;
25
+ 3.2.1)
26
+ url="http://www.sphinxsearch.com/files/sphinx-3.2.1-f152e0b-linux-amd64.tar.gz"
27
+ format="gz";;
25
28
  *)
26
29
  echo "No Sphinx version $version available"
27
30
  exit 1;;
@@ -52,6 +55,8 @@ load_manticore () {
52
55
  url="https://github.com/manticoresoftware/manticoresearch/releases/download/2.7.5/manticore_2.7.5-181204-4a31c54-release-stemmer.xenial_amd64-bin.deb";;
53
56
  2.8.2)
54
57
  url="https://github.com/manticoresoftware/manticoresearch/releases/download/2.8.2/manticore_2.8.2-190402-4e81114-release-stemmer.xenial_amd64-bin.deb";;
58
+ 3.4.2)
59
+ url="https://github.com/manticoresoftware/manticoresearch/releases/download/3.4.2/manticore_3.4.2-200410-6903305-release.xenial_amd64-bin.deb";;
55
60
  *)
56
61
  echo "No Manticore version $version available"
57
62
  exit 1;;
@@ -31,7 +31,7 @@ class ThinkingSphinx::ActiveRecord::AssociationProxy::AttributeFinder
31
31
  @indices ||= begin
32
32
  configuration.preload_indices
33
33
  configuration.indices_for_references(
34
- *ThinkingSphinx::IndexSet.reference_name(@association.klass)
34
+ *configuration.index_set_class.reference_name(@association.klass)
35
35
  ).reject &:distributed?
36
36
  end
37
37
  end
@@ -4,11 +4,6 @@ module ThinkingSphinx::ActiveRecord::Base
4
4
  extend ActiveSupport::Concern
5
5
 
6
6
  included do
7
- after_destroy ThinkingSphinx::ActiveRecord::Callbacks::DeleteCallbacks
8
- before_save ThinkingSphinx::ActiveRecord::Callbacks::DeltaCallbacks
9
- after_update ThinkingSphinx::ActiveRecord::Callbacks::UpdateCallbacks
10
- after_commit ThinkingSphinx::ActiveRecord::Callbacks::DeltaCallbacks
11
-
12
7
  if ActiveRecord::VERSION::STRING.to_i >= 5
13
8
  [
14
9
  ::ActiveRecord::Reflection::HasManyReflection,
@@ -17,8 +12,9 @@ module ThinkingSphinx::ActiveRecord::Base
17
12
  reflection_class.include DefaultReflectionAssociations
18
13
  end
19
14
  else
20
- ::ActiveRecord::Associations::CollectionProxy.send :include,
15
+ ::ActiveRecord::Associations::CollectionProxy.include(
21
16
  ThinkingSphinx::ActiveRecord::AssociationProxy
17
+ )
22
18
  end
23
19
  end
24
20
 
@@ -27,7 +27,7 @@ class ThinkingSphinx::ActiveRecord::Callbacks::DeleteCallbacks <
27
27
 
28
28
  def indices
29
29
  ThinkingSphinx::Configuration.instance.index_set_class.new(
30
- :classes => [instance.class]
30
+ :instances => [instance], :classes => [instance.class]
31
31
  ).to_a
32
32
  end
33
33
  end
@@ -43,8 +43,9 @@ class ThinkingSphinx::ActiveRecord::Callbacks::DeltaCallbacks <
43
43
  end
44
44
 
45
45
  def indices
46
- @indices ||= config.index_set_class.new(:classes => [instance.class]).
47
- select { |index| index.type == "plain" }
46
+ @indices ||= config.index_set_class.new(
47
+ :instances => [instance], :classes => [instance.class]
48
+ ).select { |index| index.type == "plain" }
48
49
  end
49
50
 
50
51
  def new_or_changed?
@@ -47,7 +47,7 @@ class ThinkingSphinx::ActiveRecord::Callbacks::UpdateCallbacks <
47
47
  end
48
48
 
49
49
  def reference
50
- ThinkingSphinx::IndexSet.reference_name(instance.class)
50
+ configuration.index_set_class.reference_name(instance.class)
51
51
  end
52
52
 
53
53
  def update(index)
@@ -13,15 +13,15 @@ class ThinkingSphinx::ActiveRecord::Interpreter <
13
13
  end
14
14
 
15
15
  def has(*columns)
16
- __source.attributes += build_properties(
16
+ build_properties(
17
17
  ::ThinkingSphinx::ActiveRecord::Attribute, columns
18
- )
18
+ ).each { |attribute| __source.add_attribute attribute }
19
19
  end
20
20
 
21
21
  def indexes(*columns)
22
- __source.fields += build_properties(
22
+ build_properties(
23
23
  ::ThinkingSphinx::ActiveRecord::Field, columns
24
- )
24
+ ).each { |field| __source.add_field field }
25
25
  end
26
26
 
27
27
  def join(*columns)
@@ -39,6 +39,18 @@ module ThinkingSphinx
39
39
  @adapter ||= DatabaseAdapters.adapter_for(@model)
40
40
  end
41
41
 
42
+ def add_attribute(attribute)
43
+ attributes.delete_if { |existing| existing.name == attribute.name }
44
+
45
+ attributes << attribute
46
+ end
47
+
48
+ def add_field(field)
49
+ fields.delete_if { |existing| existing.name == field.name }
50
+
51
+ fields << field
52
+ end
53
+
42
54
  def delta_processor
43
55
  options[:delta_processor].try(:new, adapter, @options[:delta_options] || {})
44
56
  end
@@ -18,14 +18,14 @@ class ThinkingSphinx::ActiveRecord::SQLSource::Template
18
18
  private
19
19
 
20
20
  def add_attribute(column, name, type, options = {})
21
- source.attributes << ThinkingSphinx::ActiveRecord::Attribute.new(
21
+ source.add_attribute ThinkingSphinx::ActiveRecord::Attribute.new(
22
22
  source.model, ThinkingSphinx::ActiveRecord::Column.new(column),
23
23
  options.merge(:as => name, :type => type)
24
24
  )
25
25
  end
26
26
 
27
27
  def add_field(column, name, options = {})
28
- source.fields << ThinkingSphinx::ActiveRecord::Field.new(
28
+ source.add_field ThinkingSphinx::ActiveRecord::Field.new(
29
29
  source.model, ThinkingSphinx::ActiveRecord::Column.new(column),
30
30
  options.merge(:as => name)
31
31
  )
@@ -3,6 +3,13 @@
3
3
  class ThinkingSphinx::Callbacks
4
4
  attr_reader :instance
5
5
 
6
+ def self.append(model, reference = nil, options, &block)
7
+ reference ||= ThinkingSphinx::Configuration.instance.index_set_class.
8
+ reference_name(model)
9
+
10
+ ThinkingSphinx::Callbacks::Appender.call(model, reference, options, &block)
11
+ end
12
+
6
13
  def self.callbacks(*methods)
7
14
  mod = Module.new
8
15
  methods.each do |method|
@@ -33,3 +40,5 @@ class ThinkingSphinx::Callbacks
33
40
  @instance = instance
34
41
  end
35
42
  end
43
+
44
+ require "thinking_sphinx/callbacks/appender"
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ThinkingSphinx::Callbacks::Appender
4
+ def self.call(model, reference, options, &block)
5
+ new(model, reference, options, &block).call
6
+ end
7
+
8
+ def initialize(model, reference, options, &block)
9
+ @model = model
10
+ @reference = reference
11
+ @options = options
12
+ @block = block
13
+ end
14
+
15
+ def call
16
+ model.after_destroy ThinkingSphinx::ActiveRecord::Callbacks::DeleteCallbacks
17
+
18
+ if behaviours.include?(:deltas)
19
+ model.before_save ThinkingSphinx::ActiveRecord::Callbacks::DeltaCallbacks
20
+ model.after_commit ThinkingSphinx::ActiveRecord::Callbacks::DeltaCallbacks
21
+ end
22
+
23
+ if behaviours.include?(:real_time)
24
+ model.after_save ThinkingSphinx::RealTime.callback_for(
25
+ reference, path, &block
26
+ )
27
+ end
28
+
29
+ if behaviours.include?(:updates)
30
+ model.after_update(
31
+ ThinkingSphinx::ActiveRecord::Callbacks::UpdateCallbacks
32
+ )
33
+ end
34
+ end
35
+
36
+ private
37
+
38
+ attr_reader :model, :reference, :options, :block
39
+
40
+ def behaviours
41
+ options[:behaviours] || []
42
+ end
43
+
44
+ def path
45
+ options[:path] || []
46
+ end
47
+ end
@@ -11,7 +11,6 @@ module ThinkingSphinx::Core::Index
11
11
 
12
12
  def initialize(reference, options = {})
13
13
  @reference = reference.to_sym
14
- @docinfo = :extern unless config.settings["skip_docinfo"]
15
14
  @options = options
16
15
  @offset = config.next_offset(options[:offset_as] || reference)
17
16
  @type = 'plain'
@@ -40,7 +39,7 @@ module ThinkingSphinx::Core::Index
40
39
  def interpret_definition!
41
40
  table_exists = model.table_exists?
42
41
  unless table_exists
43
- Rails.logger.info "No table exists for #{model}. Index can not be created"
42
+ Rails.logger.info "No table exists for #{model}. Index can not be created"
44
43
  return
45
44
  end
46
45
  return if @interpreted_definition
@@ -22,10 +22,6 @@ class ThinkingSphinx::Deletion
22
22
 
23
23
  attr_reader :index, :ids
24
24
 
25
- def document_ids_for_keys
26
- ids.collect { |id| index.document_id_for_key id }
27
- end
28
-
29
25
  def execute(statement)
30
26
  statement = statement.gsub(/\s*\n\s*/, ' ').strip
31
27
 
@@ -36,11 +32,28 @@ class ThinkingSphinx::Deletion
36
32
  end
37
33
  end
38
34
 
35
+ class PlainDeletion < ThinkingSphinx::Deletion
36
+ def perform
37
+ ids.each_slice(1000) do |some_ids|
38
+ execute <<-SQL
39
+ UPDATE #{name}
40
+ SET sphinx_deleted = 1
41
+ WHERE sphinx_internal_id IN (#{some_ids.join(', ')})
42
+ SQL
43
+ end
44
+ end
45
+ end
46
+
39
47
  class RealtimeDeletion < ThinkingSphinx::Deletion
40
48
  def perform
41
49
  return unless callbacks_enabled?
42
50
 
43
- execute Riddle::Query::Delete.new(name, document_ids_for_keys).to_sql
51
+ ids.each_slice(1000) do |some_ids|
52
+ execute <<-SQL
53
+ DELETE FROM #{name}
54
+ WHERE sphinx_internal_id IN (#{some_ids.join(', ')})
55
+ SQL
56
+ end
44
57
  end
45
58
 
46
59
  private
@@ -54,16 +67,4 @@ class ThinkingSphinx::Deletion
54
67
  ThinkingSphinx::Configuration.instance
55
68
  end
56
69
  end
57
-
58
- class PlainDeletion < ThinkingSphinx::Deletion
59
- def perform
60
- document_ids_for_keys.each_slice(1000) do |document_ids|
61
- execute <<-SQL
62
- UPDATE #{name}
63
- SET sphinx_deleted = 1
64
- WHERE id IN (#{document_ids.join(', ')})
65
- SQL
66
- end
67
- end
68
- end
69
70
  end