thinking-sphinx 3.2.0 → 3.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (124) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +6 -2
  3. data/Appraisals +13 -0
  4. data/Gemfile +2 -1
  5. data/HISTORY +19 -0
  6. data/README.textile +3 -2
  7. data/gemfiles/rails_3_2.gemfile +2 -1
  8. data/gemfiles/rails_4_0.gemfile +2 -1
  9. data/gemfiles/rails_4_1.gemfile +2 -1
  10. data/gemfiles/rails_4_2.gemfile +2 -1
  11. data/gemfiles/rails_5_0.gemfile +12 -0
  12. data/lib/thinking_sphinx.rb +2 -0
  13. data/lib/thinking_sphinx/active_record/attribute/type.rb +17 -3
  14. data/lib/thinking_sphinx/active_record/callbacks/delta_callbacks.rb +12 -4
  15. data/lib/thinking_sphinx/active_record/database_adapters.rb +1 -1
  16. data/lib/thinking_sphinx/active_record/sql_builder/query.rb +4 -0
  17. data/lib/thinking_sphinx/active_record/sql_source.rb +1 -1
  18. data/lib/thinking_sphinx/configuration.rb +3 -2
  19. data/lib/thinking_sphinx/connection.rb +23 -10
  20. data/lib/thinking_sphinx/deltas/index_job.rb +6 -2
  21. data/lib/thinking_sphinx/errors.rb +25 -0
  22. data/lib/thinking_sphinx/middlewares/active_record_translator.rb +14 -2
  23. data/lib/thinking_sphinx/railtie.rb +1 -1
  24. data/lib/thinking_sphinx/rake_interface.rb +71 -23
  25. data/lib/thinking_sphinx/real_time/callbacks/real_time_callbacks.rb +15 -7
  26. data/lib/thinking_sphinx/real_time/populator.rb +3 -3
  27. data/lib/thinking_sphinx/tasks.rb +7 -8
  28. data/lib/thinking_sphinx/wildcard.rb +1 -1
  29. data/spec/acceptance/association_scoping_spec.rb +5 -5
  30. data/spec/acceptance/attribute_access_spec.rb +4 -4
  31. data/spec/acceptance/attribute_updates_spec.rb +3 -3
  32. data/spec/acceptance/batch_searching_spec.rb +4 -4
  33. data/spec/acceptance/big_integers_spec.rb +6 -6
  34. data/spec/acceptance/connection_spec.rb +23 -0
  35. data/spec/acceptance/excerpts_spec.rb +8 -8
  36. data/spec/acceptance/facets_spec.rb +13 -13
  37. data/spec/acceptance/geosearching_spec.rb +8 -8
  38. data/spec/acceptance/grouping_by_attributes_spec.rb +10 -10
  39. data/spec/acceptance/index_options_spec.rb +16 -16
  40. data/spec/acceptance/indexing_spec.rb +3 -3
  41. data/spec/acceptance/paginating_search_results_spec.rb +3 -3
  42. data/spec/acceptance/real_time_updates_spec.rb +4 -4
  43. data/spec/acceptance/remove_deleted_records_spec.rb +12 -12
  44. data/spec/acceptance/search_counts_spec.rb +2 -2
  45. data/spec/acceptance/search_for_just_ids_spec.rb +2 -2
  46. data/spec/acceptance/searching_across_models_spec.rb +6 -6
  47. data/spec/acceptance/searching_across_schemas_spec.rb +10 -10
  48. data/spec/acceptance/searching_on_fields_spec.rb +9 -9
  49. data/spec/acceptance/searching_with_filters_spec.rb +16 -16
  50. data/spec/acceptance/searching_with_sti_spec.rb +9 -9
  51. data/spec/acceptance/searching_within_a_model_spec.rb +17 -17
  52. data/spec/acceptance/sorting_search_results_spec.rb +6 -6
  53. data/spec/acceptance/specifying_sql_spec.rb +62 -62
  54. data/spec/acceptance/sphinx_scopes_spec.rb +9 -9
  55. data/spec/acceptance/sql_deltas_spec.rb +7 -7
  56. data/spec/acceptance/support/database_cleaner.rb +1 -1
  57. data/spec/acceptance/support/sphinx_controller.rb +4 -1
  58. data/spec/acceptance/support/sphinx_helpers.rb +4 -0
  59. data/spec/acceptance/suspended_deltas_spec.rb +9 -9
  60. data/spec/internal/app/indices/article_index.rb +2 -2
  61. data/spec/internal/app/indices/book_index.rb +2 -1
  62. data/spec/internal/app/indices/product_index.rb +0 -2
  63. data/spec/internal/app/models/categorisation.rb +8 -1
  64. data/spec/spec_helper.rb +2 -0
  65. data/spec/support/json_column.rb +5 -1
  66. data/spec/support/multi_schema.rb +3 -1
  67. data/spec/support/sphinx_yaml_helpers.rb +1 -1
  68. data/spec/thinking_sphinx/active_record/association_spec.rb +1 -1
  69. data/spec/thinking_sphinx/active_record/attribute/type_spec.rb +41 -38
  70. data/spec/thinking_sphinx/active_record/base_spec.rb +29 -29
  71. data/spec/thinking_sphinx/active_record/callbacks/delete_callbacks_spec.rb +10 -10
  72. data/spec/thinking_sphinx/active_record/callbacks/delta_callbacks_spec.rb +48 -25
  73. data/spec/thinking_sphinx/active_record/callbacks/update_callbacks_spec.rb +8 -8
  74. data/spec/thinking_sphinx/active_record/column_spec.rb +13 -13
  75. data/spec/thinking_sphinx/active_record/column_sql_presenter_spec.rb +5 -5
  76. data/spec/thinking_sphinx/active_record/database_adapters/abstract_adapter_spec.rb +5 -5
  77. data/spec/thinking_sphinx/active_record/database_adapters/mysql_adapter_spec.rb +11 -11
  78. data/spec/thinking_sphinx/active_record/database_adapters/postgresql_adapter_spec.rb +13 -13
  79. data/spec/thinking_sphinx/active_record/database_adapters_spec.rb +48 -48
  80. data/spec/thinking_sphinx/active_record/field_spec.rb +7 -7
  81. data/spec/thinking_sphinx/active_record/filter_reflection_spec.rb +32 -32
  82. data/spec/thinking_sphinx/active_record/index_spec.rb +35 -36
  83. data/spec/thinking_sphinx/active_record/interpreter_spec.rb +51 -51
  84. data/spec/thinking_sphinx/active_record/polymorpher_spec.rb +14 -14
  85. data/spec/thinking_sphinx/active_record/property_sql_presenter_spec.rb +67 -67
  86. data/spec/thinking_sphinx/active_record/sql_builder_spec.rb +140 -140
  87. data/spec/thinking_sphinx/active_record/sql_source_spec.rb +97 -95
  88. data/spec/thinking_sphinx/configuration_spec.rb +81 -81
  89. data/spec/thinking_sphinx/connection_spec.rb +13 -13
  90. data/spec/thinking_sphinx/deletion_spec.rb +11 -11
  91. data/spec/thinking_sphinx/deltas/default_delta_spec.rb +20 -20
  92. data/spec/thinking_sphinx/deltas_spec.rb +12 -12
  93. data/spec/thinking_sphinx/errors_spec.rb +30 -30
  94. data/spec/thinking_sphinx/excerpter_spec.rb +7 -7
  95. data/spec/thinking_sphinx/facet_search_spec.rb +16 -16
  96. data/spec/thinking_sphinx/index_set_spec.rb +7 -7
  97. data/spec/thinking_sphinx/index_spec.rb +24 -24
  98. data/spec/thinking_sphinx/masks/pagination_mask_spec.rb +20 -20
  99. data/spec/thinking_sphinx/masks/scopes_mask_spec.rb +18 -18
  100. data/spec/thinking_sphinx/middlewares/active_record_translator_spec.rb +22 -22
  101. data/spec/thinking_sphinx/middlewares/geographer_spec.rb +9 -9
  102. data/spec/thinking_sphinx/middlewares/glazier_spec.rb +4 -4
  103. data/spec/thinking_sphinx/middlewares/inquirer_spec.rb +7 -7
  104. data/spec/thinking_sphinx/middlewares/sphinxql_spec.rb +53 -53
  105. data/spec/thinking_sphinx/middlewares/stale_id_checker_spec.rb +5 -5
  106. data/spec/thinking_sphinx/middlewares/stale_id_filter_spec.rb +15 -15
  107. data/spec/thinking_sphinx/panes/attributes_pane_spec.rb +1 -1
  108. data/spec/thinking_sphinx/panes/distance_pane_spec.rb +4 -4
  109. data/spec/thinking_sphinx/panes/excerpts_pane_spec.rb +5 -5
  110. data/spec/thinking_sphinx/panes/weight_pane_spec.rb +1 -1
  111. data/spec/thinking_sphinx/rake_interface_spec.rb +66 -53
  112. data/spec/thinking_sphinx/real_time/attribute_spec.rb +13 -13
  113. data/spec/thinking_sphinx/real_time/callbacks/real_time_callbacks_spec.rb +107 -23
  114. data/spec/thinking_sphinx/real_time/field_spec.rb +14 -14
  115. data/spec/thinking_sphinx/real_time/index_spec.rb +29 -30
  116. data/spec/thinking_sphinx/real_time/interpreter_spec.rb +30 -30
  117. data/spec/thinking_sphinx/scopes_spec.rb +5 -5
  118. data/spec/thinking_sphinx/search/glaze_spec.rb +15 -15
  119. data/spec/thinking_sphinx/search/query_spec.rb +10 -10
  120. data/spec/thinking_sphinx/search_spec.rb +28 -28
  121. data/spec/thinking_sphinx/wildcard_spec.rb +16 -11
  122. data/spec/thinking_sphinx_spec.rb +6 -6
  123. data/thinking-sphinx.gemspec +4 -4
  124. metadata +12 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3f8b8aa71063530ab0e184d27cc0fd8afe17da77
4
- data.tar.gz: c54952a5a6aa5a4b84e75ceb57071ddfc2244851
3
+ metadata.gz: d8c3f957070c43b828b3c6756b1d891e3abff4d9
4
+ data.tar.gz: af7a4930372048d0ace812880e262a609cd8ff3f
5
5
  SHA512:
6
- metadata.gz: 5684d082b99b5e6131d3244711316d099df261a9b07a1c1452f47150344e2e5ed32f55bdc0fe69948d62f291ef8fd99aeb71b936aebd845d96a2cee78453bc08
7
- data.tar.gz: 8d6de05c533ff85787d7d248a548e53fdc1c370c7a625a5a6dd717b2c1bb449c16a1a54b643e87f8ea16ad8b0b844c0ac7c31c453da4a23ec6c763b03bf74cbf
6
+ metadata.gz: 825e6672b6a264387ec4da67df3a8df35c429f2b26c6c66fbd17968c0837d5bd8b5a257761d0f69d38ca1284e9a26695a6590842e1fdb967341b4b8abddc68ab
7
+ data.tar.gz: a0dde9c41198468f7ed223f5113341af6ca63c475b655e22b4b9225746f423faa73e5ff303589a5860d40e720ce7efcacabc7a53769ac8fdc0d9068c5e046207
data/.travis.yml CHANGED
@@ -2,8 +2,9 @@ language: ruby
2
2
  rvm:
3
3
  - 2.0.0
4
4
  - 2.1
5
- - 2.2
6
- - jruby-19mode
5
+ - 2.2.2
6
+ - 2.3.1
7
+ - jruby-9.0.5.0
7
8
  before_install:
8
9
  - gem update --system
9
10
  - gem install bundler
@@ -24,3 +25,6 @@ addons:
24
25
  postgresql: "9.4"
25
26
  services:
26
27
  - postgresql
28
+ matrix:
29
+ allow_failures:
30
+ - rvm: jruby-9.0.5.0
data/Appraisals CHANGED
@@ -1,15 +1,28 @@
1
1
  appraise 'rails_3_2' do
2
2
  gem 'rails', '~> 3.2.22.2'
3
+ gem 'rack', '~> 1.0', :platforms => [:ruby_20, :ruby_21]
3
4
  end
4
5
 
5
6
  appraise 'rails_4_0' do
6
7
  gem 'rails', '~> 4.0.13'
8
+ gem 'rack', '~> 1.0', :platforms => [:ruby_20, :ruby_21]
7
9
  end
8
10
 
9
11
  appraise 'rails_4_1' do
10
12
  gem 'rails', '~> 4.1.15'
13
+ gem 'rack', '~> 1.0', :platforms => [:ruby_20, :ruby_21]
11
14
  end
12
15
 
13
16
  appraise 'rails_4_2' do
14
17
  gem 'rails', '~> 4.2.6'
18
+ gem 'rack', '~> 1.0', :platforms => [:ruby_20, :ruby_21]
15
19
  end
20
+
21
+ appraise 'rails_5_0' do
22
+ gem 'rails', '~> 5.0.0'
23
+ # gem 'activerecord-jdbc-adapter',
24
+ # :git => 'git://github.com/jruby/activerecord-jdbc-adapter.git',
25
+ # :branch => 'rails-5',
26
+ # :platform => :jruby,
27
+ # :ref => 'c3570ce730'
28
+ end if RUBY_VERSION.to_f >= 2.2 && RUBY_PLATFORM != 'java'
data/Gemfile CHANGED
@@ -3,9 +3,10 @@ source 'https://rubygems.org'
3
3
  gemspec
4
4
 
5
5
  gem 'mysql2', '~> 0.3.12b4', :platform => :ruby
6
- gem 'pg', '~> 0.16.0', :platform => :ruby
6
+ gem 'pg', '~> 0.18.4', :platform => :ruby
7
7
 
8
8
  gem 'jdbc-mysql', '5.1.35', :platform => :jruby
9
9
  gem 'activerecord-jdbcmysql-adapter', '~> 1.3.4', :platform => :jruby
10
10
  gem 'activerecord-jdbcpostgresql-adapter', '~> 1.3.4', :platform => :jruby
11
11
 
12
+ gem 'rack', '~> 1.0' if RUBY_VERSION.to_f <= 2.1
data/HISTORY CHANGED
@@ -1,3 +1,22 @@
1
+ 2016-12-13: 3.3.0
2
+ * [FEATURE] Real-time callbacks can now be used with after_commit hooks if that's preferred over after_save.
3
+ * [CHANGE] Only toggle the delta value if the record has changed or is new (rather than on every single save call).
4
+ * [CHANGE] Delta indexing is now quiet by default (rather than verbose).
5
+ * [FIX] Explicit source method in the SQLQuery Builder instead of relying on method missing, thus avoiding any global methods named 'source' (Asaf Bartov).
6
+ * [CHANGE] Use Riddle's reworked command interface for interacting with Sphinx's command-line tools.
7
+ * [CHANGE] Respect Rake's quiet and silent flags for the Thinking Sphinx rake tasks.
8
+ * [CHANGE] ts:start and ts:stop tasks default to verbose.
9
+ * [FIX] Load indices before deleting index files, to ensure the files are actually found and deleted.
10
+ * [FIX] Avoid loading ActiveRecord earlier than necessary. This avoids loading Rails out of order, which caused problems with Rails 5.
11
+ * [FEATURE] Allow for custom batch sizes when populating real-time indices.
12
+ * [FIX] Handle queries that are too long for Sphinx.
13
+ * [FIX] Improve Rails 5 / JRuby support.
14
+ * [CHANGE] Sort engine paths for loading indices to ensure they're consistent.
15
+ * [CHANGE] Custom exception class for invalid database adapters.
16
+ * [FIX] Fixed handling of multiple field tokens in wildcarding logic.
17
+ * [CHANGE] Memoize the default primary keys per context.
18
+ * [FIX] Ensure custom primary key columns are handled consistently (Julio Monteiro).
19
+
1
20
  2016-05-13: 3.2.0
2
21
  * [FIX] Ensure SQL table aliases are reliable for SQL-backed index queries.
3
22
  * [FEATURE] Add JSON attribute support for real-time indices.
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.2.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.3.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.3.0":https://github.com/pat/thinking-sphinx/releases/tag/v3.3.0
9
10
  * "v3.2.0":https://github.com/pat/thinking-sphinx/releases/tag/v3.2.0
10
11
  * "v3.1.4":https://github.com/pat/thinking-sphinx/releases/tag/v3.1.4
11
12
  * "v3.1.3":https://github.com/pat/thinking-sphinx/releases/tag/v3.1.3
@@ -22,7 +23,7 @@ It's a gem, so install it like you would any other gem. You will also need to sp
22
23
 
23
24
  <pre><code>gem 'mysql2', '~> 0.3.18', :platform => :ruby
24
25
  gem 'jdbc-mysql', '= 5.1.35', :platform => :jruby
25
- gem 'thinking-sphinx', '~> 3.2.0'</code></pre>
26
+ gem 'thinking-sphinx', '~> 3.3.0'</code></pre>
26
27
 
27
28
  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.
28
29
 
@@ -3,10 +3,11 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "mysql2", "~> 0.3.12b4", :platform => :ruby
6
- gem "pg", "~> 0.16.0", :platform => :ruby
6
+ gem "pg", "~> 0.18.4", :platform => :ruby
7
7
  gem "jdbc-mysql", "5.1.35", :platform => :jruby
8
8
  gem "activerecord-jdbcmysql-adapter", "~> 1.3.4", :platform => :jruby
9
9
  gem "activerecord-jdbcpostgresql-adapter", "~> 1.3.4", :platform => :jruby
10
10
  gem "rails", "~> 3.2.22.2"
11
+ gem "rack", "~> 1.0", :platforms => [:ruby_20, :ruby_21]
11
12
 
12
13
  gemspec :path => "../"
@@ -3,10 +3,11 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "mysql2", "~> 0.3.12b4", :platform => :ruby
6
- gem "pg", "~> 0.16.0", :platform => :ruby
6
+ gem "pg", "~> 0.18.4", :platform => :ruby
7
7
  gem "jdbc-mysql", "5.1.35", :platform => :jruby
8
8
  gem "activerecord-jdbcmysql-adapter", "~> 1.3.4", :platform => :jruby
9
9
  gem "activerecord-jdbcpostgresql-adapter", "~> 1.3.4", :platform => :jruby
10
10
  gem "rails", "~> 4.0.13"
11
+ gem "rack", "~> 1.0", :platforms => [:ruby_20, :ruby_21]
11
12
 
12
13
  gemspec :path => "../"
@@ -3,10 +3,11 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "mysql2", "~> 0.3.12b4", :platform => :ruby
6
- gem "pg", "~> 0.16.0", :platform => :ruby
6
+ gem "pg", "~> 0.18.4", :platform => :ruby
7
7
  gem "jdbc-mysql", "5.1.35", :platform => :jruby
8
8
  gem "activerecord-jdbcmysql-adapter", "~> 1.3.4", :platform => :jruby
9
9
  gem "activerecord-jdbcpostgresql-adapter", "~> 1.3.4", :platform => :jruby
10
10
  gem "rails", "~> 4.1.15"
11
+ gem "rack", "~> 1.0", :platforms => [:ruby_20, :ruby_21]
11
12
 
12
13
  gemspec :path => "../"
@@ -3,10 +3,11 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "mysql2", "~> 0.3.12b4", :platform => :ruby
6
- gem "pg", "~> 0.16.0", :platform => :ruby
6
+ gem "pg", "~> 0.18.4", :platform => :ruby
7
7
  gem "jdbc-mysql", "5.1.35", :platform => :jruby
8
8
  gem "activerecord-jdbcmysql-adapter", "~> 1.3.4", :platform => :jruby
9
9
  gem "activerecord-jdbcpostgresql-adapter", "~> 1.3.4", :platform => :jruby
10
10
  gem "rails", "~> 4.2.6"
11
+ gem "rack", "~> 1.0", :platforms => [:ruby_20, :ruby_21]
11
12
 
12
13
  gemspec :path => "../"
@@ -0,0 +1,12 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "mysql2", "~> 0.3.12b4", :platform => :ruby
6
+ gem "pg", "~> 0.18.4", :platform => :ruby
7
+ gem "jdbc-mysql", "5.1.35", :platform => :jruby
8
+ gem "activerecord-jdbcmysql-adapter", "~> 1.3.4", :platform => :jruby
9
+ gem "activerecord-jdbcpostgresql-adapter", "~> 1.3.4", :platform => :jruby
10
+ gem "rails", "~> 5.0.0"
11
+
12
+ gemspec :path => "../"
@@ -15,6 +15,8 @@ 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
19
+
18
20
  def self.count(query = '', options = {})
19
21
  search_for_ids(query, options).total_entries
20
22
  end
@@ -41,7 +41,7 @@ class ThinkingSphinx::ActiveRecord::Attribute::Type
41
41
  end
42
42
 
43
43
  def big_integer?
44
- database_column.type == :integer && database_column.sql_type[/bigint/i]
44
+ type_symbol == :integer && database_column.sql_type[/bigint/i]
45
45
  end
46
46
 
47
47
  def column_name
@@ -76,15 +76,29 @@ class ThinkingSphinx::ActiveRecord::Attribute::Type
76
76
 
77
77
  return :bigint if big_integer?
78
78
 
79
- case database_column.type
79
+ case type_symbol
80
80
  when :datetime, :date
81
81
  :timestamp
82
82
  when :text
83
83
  :string
84
84
  when :decimal
85
85
  :float
86
+ when :integer, :boolean, :timestamp, :float, :string, :bigint, :json
87
+ type_symbol
86
88
  else
87
- database_column.type
89
+ raise ThinkingSphinx::UnknownAttributeType,
90
+ <<-ERROR
91
+ Unable to determine an equivalent Sphinx attribute type from #{database_column.type.class.name} for attribute #{attribute.name}. You may want to manually set the type.
92
+
93
+ e.g.
94
+ has my_column, :type => :integer
95
+ ERROR
88
96
  end
89
97
  end
98
+
99
+ def type_symbol
100
+ return database_column.type if database_column.type.is_a?(Symbol)
101
+
102
+ database_column.type.class.name.demodulize.downcase.to_sym
103
+ end
90
104
  end
@@ -4,9 +4,7 @@ class ThinkingSphinx::ActiveRecord::Callbacks::DeltaCallbacks <
4
4
  callbacks :after_commit, :before_save
5
5
 
6
6
  def after_commit
7
- return unless !suspended? && delta_indices? && processors.any? { |processor|
8
- processor.toggled?(instance)
9
- }
7
+ return unless !suspended? && delta_indices? && toggled?
10
8
 
11
9
  delta_indices.each do |index|
12
10
  index.delta_processor.index index
@@ -18,7 +16,9 @@ class ThinkingSphinx::ActiveRecord::Callbacks::DeltaCallbacks <
18
16
  end
19
17
 
20
18
  def before_save
21
- return unless !ThinkingSphinx::Callbacks.suspended? && delta_indices?
19
+ return unless new_or_changed? &&
20
+ !ThinkingSphinx::Callbacks.suspended? &&
21
+ delta_indices?
22
22
 
23
23
  processors.each { |processor| processor.toggle instance }
24
24
  end
@@ -45,6 +45,10 @@ class ThinkingSphinx::ActiveRecord::Callbacks::DeltaCallbacks <
45
45
  @indices ||= config.index_set_class.new :classes => [instance.class]
46
46
  end
47
47
 
48
+ def new_or_changed?
49
+ instance.new_record? || instance.changed?
50
+ end
51
+
48
52
  def processors
49
53
  delta_indices.collect &:delta_processor
50
54
  end
@@ -52,4 +56,8 @@ class ThinkingSphinx::ActiveRecord::Callbacks::DeltaCallbacks <
52
56
  def suspended?
53
57
  ThinkingSphinx::Callbacks.suspended? || ThinkingSphinx::Deltas.suspended?
54
58
  end
59
+
60
+ def toggled?
61
+ processors.any? { |processor| processor.toggled?(instance) }
62
+ end
55
63
  end
@@ -12,7 +12,7 @@ module ThinkingSphinx::ActiveRecord::DatabaseAdapters
12
12
  when :postgresql
13
13
  PostgreSQLAdapter
14
14
  else
15
- raise "Invalid Database Adapter '#{adapter}': Thinking Sphinx only supports MySQL and PostgreSQL."
15
+ raise ThinkingSphinx::InvalidDatabaseAdapter, "Invalid adapter '#{adapter}': Thinking Sphinx only supports MySQL and PostgreSQL."
16
16
  end
17
17
 
18
18
  klass.new model
@@ -45,6 +45,10 @@ module ThinkingSphinx
45
45
  self.scope += utf8_query_pre if source.options[:utf8?]
46
46
  end
47
47
 
48
+ def source
49
+ report.source
50
+ end
51
+
48
52
  def method_missing(*args, &block)
49
53
  report.send *args, &block
50
54
  end
@@ -90,7 +90,7 @@ module ThinkingSphinx
90
90
  when DatabaseAdapters::PostgreSQLAdapter
91
91
  'pgsql'
92
92
  else
93
- raise "Unknown Adapter Type: #{adapter.class.name}"
93
+ raise UnknownDatabaseAdapter, "Provided type: #{adapter.class.name}"
94
94
  end
95
95
  end
96
96
 
@@ -1,7 +1,7 @@
1
1
  require 'pathname'
2
2
 
3
3
  class ThinkingSphinx::Configuration < Riddle::Configuration
4
- attr_accessor :configuration_file, :indices_location, :version
4
+ attr_accessor :configuration_file, :indices_location, :version, :batch_size
5
5
  attr_reader :index_paths
6
6
  attr_writer :controller, :index_set_class, :indexing_strategy
7
7
 
@@ -48,7 +48,7 @@ class ThinkingSphinx::Configuration < Riddle::Configuration
48
48
  def engine_index_paths
49
49
  return [] unless defined?(Rails)
50
50
 
51
- engine_indice_paths.flatten.compact
51
+ engine_indice_paths.flatten.compact.sort
52
52
  end
53
53
 
54
54
  def engine_indice_paths
@@ -121,6 +121,7 @@ class ThinkingSphinx::Configuration < Riddle::Configuration
121
121
  'db', 'sphinx', environment
122
122
  ).to_s
123
123
  @version = settings['version'] || '2.1.4'
124
+ @batch_size = settings['batch_size'] || 1000
124
125
 
125
126
  if settings['common_sphinx_configuration']
126
127
  common.common_sphinx_configuration = true
@@ -70,26 +70,39 @@ module ThinkingSphinx::Connection
70
70
  end
71
71
 
72
72
  def execute(statement)
73
- query(statement).first
73
+ check_and_perform(statement).first
74
74
  end
75
75
 
76
76
  def query_all(*statements)
77
- query *statements
77
+ check_and_perform statements.join('; ')
78
78
  end
79
79
 
80
80
  private
81
81
 
82
+ def check(statements)
83
+ if statements.length > ThinkingSphinx::MAXIMUM_STATEMENT_LENGTH
84
+ exception = ThinkingSphinx::QueryLengthError.new
85
+ exception.statement = statements
86
+ raise exception
87
+ end
88
+ end
89
+
90
+ def check_and_perform(statements)
91
+ check statements
92
+ perform statements
93
+ end
94
+
82
95
  def close_and_clear
83
96
  client.close
84
97
  @client = nil
85
98
  end
86
99
 
87
- def query(*statements)
88
- results_for *statements
100
+ def perform(statements)
101
+ results_for statements
89
102
  rescue => error
90
- message = "#{error.message} - #{statements.join('; ')}"
103
+ message = "#{error.message} - #{statements}"
91
104
  wrapper = ThinkingSphinx::QueryExecutionError.new message
92
- wrapper.statement = statements.join('; ')
105
+ wrapper.statement = statements
93
106
  raise wrapper
94
107
  ensure
95
108
  close_and_clear unless ThinkingSphinx::Connection.persistent?
@@ -117,8 +130,8 @@ module ThinkingSphinx::Connection
117
130
  raise ThinkingSphinx::SphinxError.new_from_mysql error
118
131
  end
119
132
 
120
- def results_for(*statements)
121
- results = [client.query(statements.join('; '))]
133
+ def results_for(statements)
134
+ results = [client.query(statements)]
122
135
  results << client.store_result while client.next_result
123
136
  results
124
137
  end
@@ -145,9 +158,9 @@ module ThinkingSphinx::Connection
145
158
  raise ThinkingSphinx::SphinxError.new_from_mysql error
146
159
  end
147
160
 
148
- def results_for(*statements)
161
+ def results_for(statements)
149
162
  statement = client.createStatement
150
- statement.execute statements.join('; ')
163
+ statement.execute statements
151
164
 
152
165
  results = [set_to_array(statement.getResultSet)]
153
166
  results << set_to_array(statement.getResultSet) while statement.getMoreResults
@@ -4,8 +4,7 @@ class ThinkingSphinx::Deltas::IndexJob
4
4
  end
5
5
 
6
6
  def perform
7
- configuration.controller.index @index_name,
8
- :verbose => !configuration.settings['quiet_deltas']
7
+ configuration.controller.index @index_name, :verbose => !quiet_deltas?
9
8
  end
10
9
 
11
10
  private
@@ -13,4 +12,9 @@ class ThinkingSphinx::Deltas::IndexJob
13
12
  def configuration
14
13
  @configuration ||= ThinkingSphinx::Configuration.instance
15
14
  end
15
+
16
+ def quiet_deltas?
17
+ configuration.settings['quiet_deltas'].nil? ||
18
+ configuration.settings['quiet_deltas']
19
+ end
16
20
  end
@@ -31,6 +31,19 @@ end
31
31
  class ThinkingSphinx::QueryError < ThinkingSphinx::SphinxError
32
32
  end
33
33
 
34
+ class ThinkingSphinx::QueryLengthError < ThinkingSphinx::SphinxError
35
+ def message
36
+ <<-MESSAGE
37
+ The supplied SphinxQL statement is #{statement.length} characters long. The maximum allowed length is #{ThinkingSphinx::MAXIMUM_STATEMENT_LENGTH}.
38
+
39
+ If this error has been raised during real-time index population, it's probably due to overly large batches of records being processed at once. The default is 1000, but you can lower it on a per-environment basis in config/thinking_sphinx.yml:
40
+
41
+ development:
42
+ batch_size: 500
43
+ MESSAGE
44
+ end
45
+ end
46
+
34
47
  class ThinkingSphinx::SyntaxError < ThinkingSphinx::QueryError
35
48
  end
36
49
 
@@ -58,3 +71,15 @@ end
58
71
 
59
72
  class ThinkingSphinx::DuplicateNameError < StandardError
60
73
  end
74
+
75
+ class ThinkingSphinx::InvalidDatabaseAdapter < StandardError
76
+ end
77
+
78
+ class ThinkingSphinx::SphinxAlreadyRunning < StandardError
79
+ end
80
+
81
+ class ThinkingSphinx::UnknownDatabaseAdapter < StandardError
82
+ end
83
+
84
+ class ThinkingSphinx::UnknownAttributeType < StandardError
85
+ end