thinking-sphinx 3.3.0 → 3.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +29 -20
  4. data/Appraisals +9 -5
  5. data/Gemfile +8 -3
  6. data/HISTORY +24 -0
  7. data/README.textile +5 -4
  8. data/bin/console +14 -0
  9. data/bin/literals +9 -0
  10. data/bin/loadsphinx +38 -0
  11. data/lib/thinking_sphinx.rb +15 -2
  12. data/lib/thinking_sphinx/active_record/callbacks/delta_callbacks.rb +2 -3
  13. data/lib/thinking_sphinx/active_record/callbacks/update_callbacks.rb +11 -1
  14. data/lib/thinking_sphinx/active_record/index.rb +1 -1
  15. data/lib/thinking_sphinx/active_record/join_association.rb +3 -1
  16. data/lib/thinking_sphinx/active_record/log_subscriber.rb +5 -0
  17. data/lib/thinking_sphinx/active_record/sql_source.rb +1 -1
  18. data/lib/thinking_sphinx/attribute_types.rb +70 -0
  19. data/lib/thinking_sphinx/commands/base.rb +41 -0
  20. data/lib/thinking_sphinx/commands/configure.rb +13 -0
  21. data/lib/thinking_sphinx/commands/index.rb +11 -0
  22. data/lib/thinking_sphinx/commands/start_attached.rb +20 -0
  23. data/lib/thinking_sphinx/commands/start_detached.rb +19 -0
  24. data/lib/thinking_sphinx/commands/stop.rb +22 -0
  25. data/lib/thinking_sphinx/configuration.rb +36 -28
  26. data/lib/thinking_sphinx/configuration/minimum_fields.rb +11 -8
  27. data/lib/thinking_sphinx/connection.rb +5 -122
  28. data/lib/thinking_sphinx/connection/client.rb +48 -0
  29. data/lib/thinking_sphinx/connection/jruby.rb +53 -0
  30. data/lib/thinking_sphinx/connection/mri.rb +28 -0
  31. data/lib/thinking_sphinx/core/index.rb +11 -0
  32. data/lib/thinking_sphinx/deletion.rb +6 -2
  33. data/lib/thinking_sphinx/deltas/default_delta.rb +1 -1
  34. data/lib/thinking_sphinx/deltas/delete_job.rb +14 -4
  35. data/lib/thinking_sphinx/distributed/index.rb +10 -0
  36. data/lib/thinking_sphinx/errors.rb +1 -1
  37. data/lib/thinking_sphinx/index_set.rb +14 -2
  38. data/lib/thinking_sphinx/interfaces/daemon.rb +32 -0
  39. data/lib/thinking_sphinx/interfaces/real_time.rb +41 -0
  40. data/lib/thinking_sphinx/interfaces/sql.rb +41 -0
  41. data/lib/thinking_sphinx/middlewares.rb +5 -3
  42. data/lib/thinking_sphinx/middlewares/active_record_translator.rb +13 -6
  43. data/lib/thinking_sphinx/middlewares/attribute_typer.rb +48 -0
  44. data/lib/thinking_sphinx/middlewares/valid_options.rb +23 -0
  45. data/lib/thinking_sphinx/rake_interface.rb +10 -124
  46. data/lib/thinking_sphinx/search.rb +11 -0
  47. data/lib/thinking_sphinx/search/query.rb +7 -1
  48. data/lib/thinking_sphinx/tasks.rb +80 -21
  49. data/lib/thinking_sphinx/with_output.rb +11 -0
  50. data/spec/acceptance/connection_spec.rb +4 -4
  51. data/spec/acceptance/searching_within_a_model_spec.rb +7 -0
  52. data/spec/acceptance/specifying_sql_spec.rb +26 -8
  53. data/spec/acceptance/sql_deltas_spec.rb +12 -0
  54. data/spec/internal/app/indices/album_index.rb +3 -0
  55. data/spec/internal/app/models/album.rb +19 -0
  56. data/spec/internal/db/schema.rb +8 -0
  57. data/spec/spec_helper.rb +4 -0
  58. data/spec/support/json_column.rb +5 -1
  59. data/spec/thinking_sphinx/active_record/callbacks/update_callbacks_spec.rb +5 -1
  60. data/spec/thinking_sphinx/active_record/sql_source_spec.rb +6 -0
  61. data/spec/thinking_sphinx/attribute_types_spec.rb +50 -0
  62. data/spec/thinking_sphinx/commands/configure_spec.rb +29 -0
  63. data/spec/thinking_sphinx/commands/index_spec.rb +26 -0
  64. data/spec/thinking_sphinx/commands/start_detached_spec.rb +55 -0
  65. data/spec/thinking_sphinx/commands/stop_spec.rb +54 -0
  66. data/spec/thinking_sphinx/configuration/minimum_fields_spec.rb +36 -0
  67. data/spec/thinking_sphinx/deletion_spec.rb +2 -5
  68. data/spec/thinking_sphinx/deltas/default_delta_spec.rb +1 -1
  69. data/spec/thinking_sphinx/errors_spec.rb +7 -0
  70. data/spec/thinking_sphinx/index_set_spec.rb +30 -7
  71. data/spec/thinking_sphinx/interfaces/daemon_spec.rb +52 -0
  72. data/spec/thinking_sphinx/interfaces/real_time_spec.rb +109 -0
  73. data/spec/thinking_sphinx/interfaces/sql_spec.rb +98 -0
  74. data/spec/thinking_sphinx/middlewares/attribute_typer_spec.rb +42 -0
  75. data/spec/thinking_sphinx/middlewares/valid_options_spec.rb +49 -0
  76. data/spec/thinking_sphinx/rake_interface_spec.rb +13 -246
  77. data/spec/thinking_sphinx/search/query_spec.rb +7 -0
  78. data/thinking-sphinx.gemspec +5 -4
  79. metadata +72 -16
  80. data/gemfiles/.gitignore +0 -1
  81. data/gemfiles/rails_3_2.gemfile +0 -13
  82. data/gemfiles/rails_4_0.gemfile +0 -13
  83. data/gemfiles/rails_4_1.gemfile +0 -13
  84. data/gemfiles/rails_4_2.gemfile +0 -13
  85. data/gemfiles/rails_5_0.gemfile +0 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d8c3f957070c43b828b3c6756b1d891e3abff4d9
4
- data.tar.gz: af7a4930372048d0ace812880e262a609cd8ff3f
3
+ metadata.gz: b763d739981ac8436e92fa07b67bae1e01912014
4
+ data.tar.gz: e11258a8602e0005be61a97da389365524bac728
5
5
  SHA512:
6
- metadata.gz: 825e6672b6a264387ec4da67df3a8df35c429f2b26c6c66fbd17968c0837d5bd8b5a257761d0f69d38ca1284e9a26695a6590842e1fdb967341b4b8abddc68ab
7
- data.tar.gz: a0dde9c41198468f7ed223f5113341af6ca63c475b655e22b4b9225746f423faa73e5ff303589a5860d40e720ce7efcacabc7a53769ac8fdc0d9068c5e046207
6
+ metadata.gz: 7c66d2e95dc7af7b45f4291e5c28e88b400442087add27c2fe43a55e5f4384781adf0c34326ae5e80d22882821f136b8f100b85e5337c335f6612a0fa12b9f40
7
+ data.tar.gz: 28909c68df0089f551a0fc2d5026b5259d7dfe4b1f8132ef0aea7fa191d9848a46f2d8e3ca08b8282eb1529bc670304aca2c850fde4a4fa561234369c6beb36d
data/.gitignore CHANGED
@@ -1,6 +1,7 @@
1
1
  *.gem
2
2
  .bundle
3
3
  .rbx
4
+ gemfiles
4
5
  Gemfile.lock
5
6
  *.sublime-*
6
7
  pkg/*
data/.travis.yml CHANGED
@@ -1,30 +1,39 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.0.0
4
- - 2.1
5
- - 2.2.2
6
- - 2.3.1
7
- - jruby-9.0.5.0
3
+ - 2.2.2
4
+ - 2.3.4
5
+ - 2.4.1
6
+ - jruby-9.1.10.0
8
7
  before_install:
9
- - gem update --system
10
- - gem install bundler
8
+ - pip install --upgrade --user awscli
9
+ - gem update --system
10
+ - gem install bundler
11
11
  before_script:
12
- - "mysql -e 'create database thinking_sphinx;' > /dev/null"
13
- - "psql -c 'create database thinking_sphinx;' -U postgres >/dev/null"
14
- - bundle exec appraisal install
12
+ - mysql -e 'create database thinking_sphinx;' > /dev/null
13
+ - psql -c 'create database thinking_sphinx;' -U postgres >/dev/null
14
+ - "./bin/loadsphinx $SPHINX_VERSION"
15
+ - "./bin/literals"
16
+ - bundle exec appraisal install
15
17
  script: bundle exec appraisal rspec
16
18
  env:
17
- - DATABASE=mysql2 SPHINX_BIN=/usr/local/sphinx-2.0.10/bin/ SPHINX_VERSION=2.0.10
18
- - DATABASE=postgresql SPHINX_BIN=/usr/local/sphinx-2.0.10/bin/ SPHINX_VERSION=2.0.10
19
- - DATABASE=mysql2 SPHINX_BIN=/usr/local/sphinx-2.1.9/bin/ SPHINX_VERSION=2.1.9
20
- - DATABASE=postgresql SPHINX_BIN=/usr/local/sphinx-2.1.9/bin/ SPHINX_VERSION=2.1.9
21
- - DATABASE=mysql2 SPHINX_BIN=/usr/local/sphinx-2.2.6/bin/ SPHINX_VERSION=2.2.6
22
- - DATABASE=postgresql SPHINX_BIN=/usr/local/sphinx-2.2.6/bin/ SPHINX_VERSION=2.2.6
19
+ global:
20
+ - SPHINX_BIN=ext/sphinx/bin/
21
+ - secure: cUPinkilBafqDSPsTkl/PXYc2aXNKUQKXGK8poBBMqKN9/wjfJx1DWgtowDKalekdZELxDhc85Ye3bL1xlW4nLjOu+U6Tkt8eNw2Nhs1flodHzA/RyENdBLr/tBHt43EjkrDehZx5sBHmWQY4miHs8AJz0oKO9Ae2inTOHx9Iuc=
22
+ matrix:
23
+ - DATABASE=mysql2 SPHINX_VERSION=2.0.10
24
+ - DATABASE=postgresql SPHINX_VERSION=2.0.10
25
+ - DATABASE=mysql2 SPHINX_VERSION=2.1.9
26
+ - DATABASE=postgresql SPHINX_VERSION=2.1.9
27
+ - DATABASE=mysql2 SPHINX_VERSION=2.2.6
28
+ - DATABASE=postgresql SPHINX_VERSION=2.2.6
23
29
  sudo: false
24
30
  addons:
25
- postgresql: "9.4"
31
+ postgresql: '9.4'
26
32
  services:
27
- - postgresql
33
+ - postgresql
28
34
  matrix:
29
- allow_failures:
30
- - rvm: jruby-9.0.5.0
35
+ exclude:
36
+ - rvm: jruby-9.1.10.0
37
+ env: DATABASE=mysql2 SPHINX_VERSION=2.0.10
38
+ - rvm: jruby-9.1.10.0
39
+ env: DATABASE=postgresql SPHINX_VERSION=2.0.10
data/Appraisals CHANGED
@@ -1,28 +1,32 @@
1
1
  appraise 'rails_3_2' do
2
2
  gem 'rails', '~> 3.2.22.2'
3
3
  gem 'rack', '~> 1.0', :platforms => [:ruby_20, :ruby_21]
4
- end
4
+ end if RUBY_VERSION.to_f <= 2.3
5
5
 
6
6
  appraise 'rails_4_0' do
7
7
  gem 'rails', '~> 4.0.13'
8
8
  gem 'rack', '~> 1.0', :platforms => [:ruby_20, :ruby_21]
9
- end
9
+ end if RUBY_VERSION.to_f <= 2.3
10
10
 
11
11
  appraise 'rails_4_1' do
12
12
  gem 'rails', '~> 4.1.15'
13
13
  gem 'rack', '~> 1.0', :platforms => [:ruby_20, :ruby_21]
14
- end
14
+ end if RUBY_VERSION.to_f <= 2.3
15
15
 
16
16
  appraise 'rails_4_2' do
17
17
  gem 'rails', '~> 4.2.6'
18
18
  gem 'rack', '~> 1.0', :platforms => [:ruby_20, :ruby_21]
19
- end
19
+ end if RUBY_VERSION.to_f <= 2.3
20
20
 
21
21
  appraise 'rails_5_0' do
22
- gem 'rails', '~> 5.0.0'
22
+ gem 'rails', '~> 5.0.2'
23
23
  # gem 'activerecord-jdbc-adapter',
24
24
  # :git => 'git://github.com/jruby/activerecord-jdbc-adapter.git',
25
25
  # :branch => 'rails-5',
26
26
  # :platform => :jruby,
27
27
  # :ref => 'c3570ce730'
28
28
  end if RUBY_VERSION.to_f >= 2.2 && RUBY_PLATFORM != 'java'
29
+
30
+ appraise 'rails_5_1' do
31
+ gem 'rails', '~> 5.1.0'
32
+ end if RUBY_VERSION.to_f >= 2.2 && RUBY_PLATFORM != 'java'
data/Gemfile CHANGED
@@ -6,7 +6,12 @@ gem 'mysql2', '~> 0.3.12b4', :platform => :ruby
6
6
  gem 'pg', '~> 0.18.4', :platform => :ruby
7
7
 
8
8
  gem 'jdbc-mysql', '5.1.35', :platform => :jruby
9
- gem 'activerecord-jdbcmysql-adapter', '~> 1.3.4', :platform => :jruby
10
- gem 'activerecord-jdbcpostgresql-adapter', '~> 1.3.4', :platform => :jruby
9
+ gem 'activerecord-jdbcmysql-adapter', '~> 1.3.23', :platform => :jruby
10
+ gem 'activerecord-jdbcpostgresql-adapter', '~> 1.3.23', :platform => :jruby
11
11
 
12
- gem 'rack', '~> 1.0' if RUBY_VERSION.to_f <= 2.1
12
+ if RUBY_VERSION.to_f <= 2.1
13
+ gem 'rack', '~> 1.0'
14
+ gem 'nokogiri', '1.6.8'
15
+ end
16
+
17
+ gem 'activerecord', '>= 3.2.22' if RUBY_PLATFORM == 'java'
data/HISTORY CHANGED
@@ -1,3 +1,27 @@
1
+ 2017-08-28: 3.4.0
2
+ * [CHANGE] Delta callback logic now prioritises checking for high level settings rather than model changes.
3
+ * [FIX] Index normalisation now occurs consistently, and removes unneccesary sphinx_internal_class_name fields from real-time indices.
4
+ * [FEATURE] Rake tasks are now unified, so the original tasks will operate on real-time indices as well.
5
+ * [FEATURE] Output warnings when unknown options are used in search calls.
6
+ * [CHANGE] Allow for unsaved records when calculating document ids (and return nil).
7
+ * [CHANGE] Display SphinxQL deletion statements in the log.
8
+ * [CHANGE] Add support for Ruby's frozen string literals feature.
9
+ * [FIX] Fix Sphinx connections in JRuby.
10
+ * [FIX] Fix long SphinxQL query handling in JRuby.
11
+ * [FEATURE] Allow generation of a single real-time index (Tim Brown).
12
+ * [FIX] Always close the SphinxQL connection if Innertube's asking (@cmaion).
13
+ * [CHANGE] Use saved_changes if it's available (in Rails 5.1+).
14
+ * [FEATURE] Automatically use UTF8 in Sphinx for encodings that are extensions of UTF8.
15
+ * [FIX] Get bigint primary keys working in Rails 5.1.
16
+ * [CHANGE] Set a default connection timeout of 5 seconds.
17
+ * [FIX] Fix handling of attached starts of Sphinx (via Henne Vogelsang).
18
+ * [FIX] Fix multi-field conditions.
19
+ * [FEATURE] Basic type checking for attribute filters.
20
+ * [CHANGE] Don't search multi-table inheritance ancestors.
21
+ * [FIX] Use the base class of STI models for polymorphic join generation (via Andrés Cirugeda).
22
+ * [CHANGE] Handle non-computable queries as parse errors.
23
+ * [FIX] Ensure ts:index now respects rake silent/quiet flags.
24
+
1
25
  2016-12-13: 3.3.0
2
26
  * [FEATURE] Real-time callbacks can now be used with after_commit hooks if that's preferred over after_save.
3
27
  * [CHANGE] Only toggle the delta value if the record has changed or is new (rather than on every single save call).
data/README.textile CHANGED
@@ -1,11 +1,12 @@
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 v3.3.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 v3.4.0.
4
4
 
5
5
  h2. Upgrading
6
6
 
7
7
  Please refer to the release notes for any changes you need to make when upgrading:
8
8
 
9
+ * "v3.4.0":https://github.com/pat/thinking-sphinx/releases/tag/v3.4.0
9
10
  * "v3.3.0":https://github.com/pat/thinking-sphinx/releases/tag/v3.3.0
10
11
  * "v3.2.0":https://github.com/pat/thinking-sphinx/releases/tag/v3.2.0
11
12
  * "v3.1.4":https://github.com/pat/thinking-sphinx/releases/tag/v3.1.4
@@ -21,9 +22,9 @@ h2. Installation
21
22
 
22
23
  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:
23
24
 
24
- <pre><code>gem 'mysql2', '~> 0.3.18', :platform => :ruby
25
+ <pre><code>gem 'mysql2', '~> 0.3', :platform => :ruby
25
26
  gem 'jdbc-mysql', '= 5.1.35', :platform => :jruby
26
- gem 'thinking-sphinx', '~> 3.3.0'</code></pre>
27
+ gem 'thinking-sphinx', '~> 3.4.0'</code></pre>
27
28
 
28
29
  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, 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.
29
30
 
@@ -84,4 +85,4 @@ You can then run the unit tests with @rake spec:unit@, the acceptance tests with
84
85
 
85
86
  h2. Licence
86
87
 
87
- Copyright (c) 2007-2015, 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.
88
+ Copyright (c) 2007-2017, 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.
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "thinking_sphinx"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/literals ADDED
@@ -0,0 +1,9 @@
1
+ if (ruby -e "exit RUBY_VERSION.to_f >= 2.4")
2
+ then
3
+ echo "Automatic frozen string literals are supported"
4
+ gem install pragmater -v 4.0.0
5
+ pragmater --add lib --comments "# frozen_string_literal: true" --whitelist "**/*.rb"
6
+ pragmater --add spec --comments "# frozen_string_literal: true" --whitelist "**/*.rb"
7
+ else
8
+ echo "Automatic frozen string literals are not supported."
9
+ fi
data/bin/loadsphinx ADDED
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env bash
2
+
3
+ version=$1
4
+ name="sphinx-$version"
5
+ url="http://sphinxsearch.com/files/$name-release.tar.gz"
6
+ bucket="thinking-sphinx"
7
+ directory="ext/sphinx"
8
+ prefix="`pwd`/$directory"
9
+ file="ext/$name.tar.gz"
10
+
11
+ download_and_compile_source () {
12
+ curl -O $url
13
+ tar -zxf $name-release.tar.gz
14
+ cd $name-release
15
+ ./configure --with-mysql --with-pgsql --enable-id64 --prefix=$prefix
16
+ make
17
+ make install
18
+ cd ..
19
+ rm -rf $name-release.tar.gz $name-release
20
+ }
21
+
22
+ load_cache () {
23
+ aws s3 cp s3://$bucket/bincaches/$name.tar.gz $file
24
+ tar -zxf $file
25
+ }
26
+
27
+ push_cache () {
28
+ tar -czf $file $directory
29
+ aws s3 cp $file s3://$bucket/bincaches/$name.tar.gz --acl public-read
30
+ }
31
+
32
+ if aws s3api head-object --bucket $bucket --key bincaches/$name.tar.gz
33
+ then
34
+ load_cache
35
+ else
36
+ download_and_compile_source
37
+ push_cache
38
+ fi
@@ -15,7 +15,7 @@ require 'active_support/core_ext/module/delegation'
15
15
  require 'active_support/core_ext/module/attribute_accessors'
16
16
 
17
17
  module ThinkingSphinx
18
- MAXIMUM_STATEMENT_LENGTH = (2 ** 23) - 1
18
+ MAXIMUM_STATEMENT_LENGTH = (2 ** 23) - 5
19
19
 
20
20
  def self.count(query = '', options = {})
21
21
  search_for_ids(query, options).total_entries
@@ -40,14 +40,24 @@ module ThinkingSphinx
40
40
 
41
41
  @before_index_hooks = []
42
42
 
43
- module Subscribers; end
43
+ module Commands; end
44
44
  module IndexingStrategies; end
45
+ module Interfaces; end
46
+ module Subscribers; end
45
47
  end
46
48
 
47
49
  # Core
50
+ require 'thinking_sphinx/attribute_types'
48
51
  require 'thinking_sphinx/batched_search'
49
52
  require 'thinking_sphinx/callbacks'
50
53
  require 'thinking_sphinx/core'
54
+ require 'thinking_sphinx/with_output'
55
+ require 'thinking_sphinx/commands/base'
56
+ require 'thinking_sphinx/commands/configure'
57
+ require 'thinking_sphinx/commands/index'
58
+ require 'thinking_sphinx/commands/start_attached'
59
+ require 'thinking_sphinx/commands/start_detached'
60
+ require 'thinking_sphinx/commands/stop'
51
61
  require 'thinking_sphinx/configuration'
52
62
  require 'thinking_sphinx/connection'
53
63
  require 'thinking_sphinx/controller'
@@ -63,6 +73,9 @@ require 'thinking_sphinx/index'
63
73
  require 'thinking_sphinx/indexing_strategies/all_at_once'
64
74
  require 'thinking_sphinx/indexing_strategies/one_at_a_time'
65
75
  require 'thinking_sphinx/index_set'
76
+ require 'thinking_sphinx/interfaces/daemon'
77
+ require 'thinking_sphinx/interfaces/real_time'
78
+ require 'thinking_sphinx/interfaces/sql'
66
79
  require 'thinking_sphinx/masks'
67
80
  require 'thinking_sphinx/middlewares'
68
81
  require 'thinking_sphinx/panes'
@@ -16,9 +16,8 @@ class ThinkingSphinx::ActiveRecord::Callbacks::DeltaCallbacks <
16
16
  end
17
17
 
18
18
  def before_save
19
- return unless new_or_changed? &&
20
- !ThinkingSphinx::Callbacks.suspended? &&
21
- delta_indices?
19
+ return unless !ThinkingSphinx::Callbacks.suspended? && delta_indices? &&
20
+ new_or_changed?
22
21
 
23
22
  processors.each { |processor| processor.toggle instance }
24
23
  end
@@ -1,6 +1,12 @@
1
1
  class ThinkingSphinx::ActiveRecord::Callbacks::UpdateCallbacks <
2
2
  ThinkingSphinx::Callbacks
3
3
 
4
+ if ActiveRecord::Base.instance_methods.grep(/saved_changes/).any?
5
+ CHANGED_ATTRIBUTES = lambda { |instance| instance.saved_changes.keys }
6
+ else
7
+ CHANGED_ATTRIBUTES = lambda { |instance| instance.changed }
8
+ end
9
+
4
10
  callbacks :after_update
5
11
 
6
12
  def after_update
@@ -15,7 +21,7 @@ class ThinkingSphinx::ActiveRecord::Callbacks::UpdateCallbacks <
15
21
 
16
22
  def attributes_hash_for(index)
17
23
  updateable_attributes_for(index).inject({}) do |hash, attribute|
18
- if instance.changed.include?(attribute.columns.first.__name.to_s)
24
+ if changed_attributes.include?(attribute.columns.first.__name.to_s)
19
25
  hash[attribute.name] = attribute.value_for(instance)
20
26
  end
21
27
 
@@ -23,6 +29,10 @@ class ThinkingSphinx::ActiveRecord::Callbacks::UpdateCallbacks <
23
29
  end
24
30
  end
25
31
 
32
+ def changed_attributes
33
+ @changed_attributes ||= CHANGED_ATTRIBUTES.call instance
34
+ end
35
+
26
36
  def configuration
27
37
  ThinkingSphinx::Configuration.instance
28
38
  end
@@ -63,7 +63,7 @@ class ThinkingSphinx::ActiveRecord::Index < Riddle::Configuration::Index
63
63
  :delta? => @options[:delta?],
64
64
  :delta_processor => @options[:delta_processor],
65
65
  :delta_options => @options[:delta_options],
66
- :primary_key => @options[:primary_key] || model.primary_key || :id
66
+ :primary_key => primary_key
67
67
  }
68
68
  end
69
69
  end
@@ -5,7 +5,9 @@ class ThinkingSphinx::ActiveRecord::JoinAssociation <
5
5
  constraint = super
6
6
 
7
7
  constraint = constraint.and(
8
- foreign_table[reflection.options[:foreign_type]].eq(base_klass.name)
8
+ foreign_table[reflection.options[:foreign_type]].eq(
9
+ base_klass.base_class.name
10
+ )
9
11
  ) if reflection.options[:sphinx_internal_filtered]
10
12
 
11
13
  constraint
@@ -13,6 +13,11 @@ class ThinkingSphinx::ActiveRecord::LogSubscriber < ActiveSupport::LogSubscriber
13
13
  identifier = color('Sphinx Query (%.1fms)' % event.duration, GREEN, true)
14
14
  debug " #{identifier} #{event.payload[:query]}"
15
15
  end
16
+
17
+ def warn(event)
18
+ identifier = color 'Sphinx', GREEN, true
19
+ warn " #{identifier} #{event.payload[:guard]}"
20
+ end
16
21
  end
17
22
 
18
23
  ThinkingSphinx::ActiveRecord::LogSubscriber.attach_to :thinking_sphinx
@@ -14,7 +14,7 @@ module ThinkingSphinx
14
14
  @model = model
15
15
  @database_settings = model.connection.instance_variable_get(:@config).clone
16
16
  @options = {
17
- :utf8? => (@database_settings[:encoding] == 'utf8')
17
+ :utf8? => (@database_settings[:encoding].to_s[/^utf8/])
18
18
  }.merge options
19
19
 
20
20
  @fields = []
@@ -0,0 +1,70 @@
1
+ class ThinkingSphinx::AttributeTypes
2
+ def self.call
3
+ @call ||= new.call
4
+ end
5
+
6
+ def self.reset
7
+ @call = nil
8
+ end
9
+
10
+ def call
11
+ return {} unless File.exist?(configuration_file)
12
+
13
+ realtime_indices.each { |index|
14
+ map_types_with_prefix index, :rt,
15
+ [:uint, :bigint, :float, :timestamp, :string, :bool, :json]
16
+
17
+ index.rt_attr_multi.each { |name| attributes[name] << :uint }
18
+ index.rt_attr_multi_64.each { |name| attributes[name] << :bigint }
19
+ }
20
+
21
+ plain_sources.each { |source|
22
+ map_types_with_prefix source, :sql,
23
+ [:uint, :bigint, :float, :timestamp, :string, :bool, :json]
24
+
25
+ source.sql_attr_str2ordinal { |name| attributes[name] << :uint }
26
+ source.sql_attr_str2wordcount { |name| attributes[name] << :uint }
27
+ source.sql_attr_multi.each { |setting|
28
+ type, name, *ignored = setting.split(/\s+/)
29
+ attributes[name] << type.to_sym
30
+ }
31
+ }
32
+
33
+ attributes.values.each &:uniq!
34
+ attributes
35
+ end
36
+
37
+ private
38
+
39
+ def attributes
40
+ @attributes ||= Hash.new { |hash, key| hash[key] = [] }
41
+ end
42
+
43
+ def configuration
44
+ @configuration ||= Riddle::Configuration.parse!(
45
+ File.read(configuration_file)
46
+ )
47
+ end
48
+
49
+ def configuration_file
50
+ ThinkingSphinx::Configuration.instance.configuration_file
51
+ end
52
+
53
+ def map_types_with_prefix(object, prefix, types)
54
+ types.each do |type|
55
+ object.public_send("#{prefix}_attr_#{type}").each do |name|
56
+ attributes[name] << type
57
+ end
58
+ end
59
+ end
60
+
61
+ def plain_sources
62
+ configuration.indices.select { |index|
63
+ index.type == 'plain' || index.type.nil?
64
+ }.collect(&:sources).flatten
65
+ end
66
+
67
+ def realtime_indices
68
+ configuration.indices.select { |index| index.type == 'rt' }
69
+ end
70
+ end