thinking-sphinx 3.0.6 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +11 -6
  3. data/Appraisals +5 -5
  4. data/Gemfile +3 -3
  5. data/HISTORY +32 -0
  6. data/README.textile +16 -5
  7. data/gemfiles/rails_3_2.gemfile +2 -1
  8. data/gemfiles/rails_4_0.gemfile +3 -2
  9. data/gemfiles/{rails_3_1.gemfile → rails_4_1.gemfile} +3 -2
  10. data/lib/thinking_sphinx.rb +5 -0
  11. data/lib/thinking_sphinx/active_record.rb +2 -1
  12. data/lib/thinking_sphinx/active_record/association_proxy/attribute_finder.rb +1 -1
  13. data/lib/thinking_sphinx/active_record/callbacks/delete_callbacks.rb +6 -7
  14. data/lib/thinking_sphinx/active_record/callbacks/delta_callbacks.rb +2 -2
  15. data/lib/thinking_sphinx/active_record/callbacks/update_callbacks.rb +1 -1
  16. data/lib/thinking_sphinx/active_record/column_sql_presenter.rb +34 -0
  17. data/lib/thinking_sphinx/active_record/database_adapters/mysql_adapter.rb +4 -0
  18. data/lib/thinking_sphinx/active_record/database_adapters/postgresql_adapter.rb +4 -0
  19. data/lib/thinking_sphinx/active_record/index.rb +2 -1
  20. data/lib/thinking_sphinx/active_record/interpreter.rb +7 -0
  21. data/lib/thinking_sphinx/active_record/property.rb +1 -1
  22. data/lib/thinking_sphinx/active_record/property_sql_presenter.rb +10 -16
  23. data/lib/thinking_sphinx/active_record/sql_builder.rb +7 -1
  24. data/lib/thinking_sphinx/active_record/sql_builder/query.rb +0 -7
  25. data/lib/thinking_sphinx/active_record/sql_source.rb +20 -20
  26. data/lib/thinking_sphinx/active_record/sql_source/template.rb +1 -1
  27. data/lib/thinking_sphinx/capistrano.rb +6 -65
  28. data/lib/thinking_sphinx/capistrano/v2.rb +58 -0
  29. data/lib/thinking_sphinx/capistrano/v3.rb +101 -0
  30. data/lib/thinking_sphinx/configuration.rb +8 -3
  31. data/lib/thinking_sphinx/configuration/distributed_indices.rb +29 -0
  32. data/lib/thinking_sphinx/connection.rb +90 -34
  33. data/lib/thinking_sphinx/controller.rb +20 -0
  34. data/lib/thinking_sphinx/core/index.rb +4 -0
  35. data/lib/thinking_sphinx/deletion.rb +15 -11
  36. data/lib/thinking_sphinx/deltas.rb +9 -0
  37. data/lib/thinking_sphinx/deltas/default_delta.rb +2 -0
  38. data/lib/thinking_sphinx/distributed.rb +5 -0
  39. data/lib/thinking_sphinx/distributed/index.rb +24 -0
  40. data/lib/thinking_sphinx/excerpter.rb +7 -3
  41. data/lib/thinking_sphinx/facet_search.rb +1 -1
  42. data/lib/thinking_sphinx/index.rb +2 -6
  43. data/lib/thinking_sphinx/index_set.rb +10 -8
  44. data/lib/thinking_sphinx/middlewares.rb +0 -2
  45. data/lib/thinking_sphinx/middlewares/active_record_translator.rb +1 -0
  46. data/lib/thinking_sphinx/middlewares/geographer.rb +1 -1
  47. data/lib/thinking_sphinx/middlewares/sphinxql.rb +8 -6
  48. data/lib/thinking_sphinx/middlewares/utf8.rb +6 -1
  49. data/lib/thinking_sphinx/query.rb +9 -0
  50. data/lib/thinking_sphinx/railtie.rb +0 -13
  51. data/lib/thinking_sphinx/search/query.rb +3 -21
  52. data/lib/thinking_sphinx/sphinxql.rb +1 -1
  53. data/lib/thinking_sphinx/wildcard.rb +34 -0
  54. data/spec/acceptance/geosearching_spec.rb +13 -0
  55. data/spec/acceptance/indexing_spec.rb +27 -0
  56. data/spec/acceptance/remove_deleted_records_spec.rb +8 -0
  57. data/spec/acceptance/searching_with_sti_spec.rb +7 -0
  58. data/spec/acceptance/searching_within_a_model_spec.rb +8 -0
  59. data/spec/acceptance/sorting_search_results_spec.rb +1 -1
  60. data/spec/acceptance/spec_helper.rb +13 -0
  61. data/spec/acceptance/specifying_sql_spec.rb +2 -2
  62. data/spec/acceptance/support/sphinx_controller.rb +5 -5
  63. data/spec/acceptance/support/sphinx_helpers.rb +3 -0
  64. data/spec/acceptance/suspended_deltas_spec.rb +34 -0
  65. data/spec/internal/config/database.yml +1 -0
  66. data/spec/thinking_sphinx/active_record/callbacks/delete_callbacks_spec.rb +13 -6
  67. data/spec/thinking_sphinx/active_record/callbacks/update_callbacks_spec.rb +2 -2
  68. data/spec/thinking_sphinx/active_record/database_adapters/mysql_adapter_spec.rb +7 -0
  69. data/spec/thinking_sphinx/active_record/database_adapters/postgresql_adapter_spec.rb +6 -0
  70. data/spec/thinking_sphinx/active_record/interpreter_spec.rb +27 -0
  71. data/spec/thinking_sphinx/active_record/property_sql_presenter_spec.rb +18 -7
  72. data/spec/thinking_sphinx/active_record/sql_builder_spec.rb +17 -7
  73. data/spec/thinking_sphinx/active_record/sql_source_spec.rb +84 -82
  74. data/spec/thinking_sphinx/configuration_spec.rb +5 -4
  75. data/spec/thinking_sphinx/connection_spec.rb +1 -1
  76. data/spec/thinking_sphinx/deletion_spec.rb +10 -28
  77. data/spec/thinking_sphinx/excerpter_spec.rb +3 -3
  78. data/spec/thinking_sphinx/facet_search_spec.rb +13 -4
  79. data/spec/thinking_sphinx/index_set_spec.rb +9 -4
  80. data/spec/thinking_sphinx/middlewares/active_record_translator_spec.rb +8 -0
  81. data/spec/thinking_sphinx/middlewares/geographer_spec.rb +7 -7
  82. data/spec/thinking_sphinx/middlewares/sphinxql_spec.rb +17 -1
  83. data/spec/thinking_sphinx/search/query_spec.rb +10 -53
  84. data/spec/thinking_sphinx/wildcard_spec.rb +41 -0
  85. data/thinking-sphinx.gemspec +6 -5
  86. metadata +38 -14
  87. data/lib/thinking_sphinx/active_record/associations.rb +0 -98
  88. data/spec/thinking_sphinx/active_record/associations_spec.rb +0 -230
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7e8abde6121afcf9bad7eb33647ed1083d0f8bea
4
- data.tar.gz: 2a372d2529cb95c232a5fc2d500aa9a5798eebd8
3
+ metadata.gz: a5defbd88cf59aea7a90ef3256c80d41e0c1b351
4
+ data.tar.gz: 6a355963b4d9b2e22e47167c5075b592e5e1aef3
5
5
  SHA512:
6
- metadata.gz: 2c22cc575eb577957271f00a0b04034871051634ddf7324132587be852ea35b995ad3e4f220dca5765d93766f69864c6d1df1a8379520fd9bc3637c239f04e28
7
- data.tar.gz: c253ba339cf5dfc7903d6b98ebf63e77726194ab481d79ec009d3830f072598d6a65fee1efbc07dfa4ed6f6e561cef424883cbf834dbb76d0bf12dd5322f6214
6
+ metadata.gz: 2ed23c4b83609fa9a19ef8d7f2330cd172041d9f193c0fd67bda4abbd1542a90658b6ebcda4942130be414da4ce6037702362a1aa934c5e0768024fcbb331b45
7
+ data.tar.gz: dfd43067513b2993a545e15bfc41945d36c84c8b598866818cbff5d348794ab04a4957c4fd44f4fd6c3ef883b1c1af088a21411be929ea73e44f6eba1307a9a5
@@ -1,19 +1,24 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.2
4
3
  - 1.9.3
5
4
  - 2.0.0
5
+ - 2.1.0
6
+ - jruby-19mode
6
7
  before_install:
7
8
  - gem update --system
8
- - curl -O http://fs-packages.s3.amazonaws.com/fs-sphinx-2.0.6_x86_64_12.04.deb
9
- - sudo dpkg -i fs-sphinx-2.0.6_x86_64_12.04.deb
9
+ - sudo apt-get install postgresql-server-dev-9.1 libmysql++-dev -y
10
+ - curl -O http://fs-packages.s3.amazonaws.com/fs-sphinx-2.0.9_x86_64_12.04.deb
11
+ - sudo dpkg -i fs-sphinx-2.0.9_x86_64_12.04.deb
12
+ - curl -O http://fs-packages.s3.amazonaws.com/fs-sphinx-2.1.4_x86_64_12.04.deb
13
+ - sudo dpkg -i fs-sphinx-2.1.4_x86_64_12.04.deb
10
14
  before_script:
11
15
  - "mysql -e 'create database thinking_sphinx;' > /dev/null"
12
16
  - "psql -c 'create database thinking_sphinx;' -U postgres >/dev/null"
13
17
  env:
14
- - DATABASE=mysql2 SPHINX_BIN=/usr/local/sphinx-2.0.6/bin/ SPHINX_VERSION=2.0.6
15
- - DATABASE=postgresql SPHINX_BIN=/usr/local/sphinx-2.0.6/bin/ SPHINX_VERSION=2.0.6
18
+ - DATABASE=mysql2 SPHINX_BIN=/usr/local/sphinx-2.0.9/bin/ SPHINX_VERSION=2.0.9
19
+ - DATABASE=postgresql SPHINX_BIN=/usr/local/sphinx-2.0.9/bin/ SPHINX_VERSION=2.0.9
20
+ - DATABASE=mysql2 SPHINX_BIN=/usr/local/sphinx-2.1.4/bin/ SPHINX_VERSION=2.1.4
21
+ - DATABASE=postgresql SPHINX_BIN=/usr/local/sphinx-2.1.4/bin/ SPHINX_VERSION=2.1.4
16
22
  gemfile:
17
- - gemfiles/rails_3_1.gemfile
18
23
  - gemfiles/rails_3_2.gemfile
19
24
  - gemfiles/rails_4_0.gemfile
data/Appraisals CHANGED
@@ -1,11 +1,11 @@
1
- appraise 'rails_3_1' do
2
- gem 'rails', '~> 3.1.0'
3
- end
4
-
5
1
  appraise 'rails_3_2' do
6
2
  gem 'rails', '~> 3.2.0'
7
3
  end
8
4
 
9
5
  appraise 'rails_4_0' do
10
- gem 'rails', '~> 4.0.0.rc1'
6
+ gem 'rails', '~> 4.0.2'
7
+ end
8
+
9
+ appraise 'rails_4_1' do
10
+ gem 'rails', '~> 4.1.0.beta1'
11
11
  end
data/Gemfile CHANGED
@@ -3,7 +3,7 @@ source 'https://rubygems.org'
3
3
  gemspec
4
4
 
5
5
  gem 'mysql2', '~> 0.3.12b4', :platform => :ruby
6
- gem 'pg', '~> 0.11.0', :platform => :ruby
6
+ gem 'pg', '~> 0.16.0', :platform => :ruby
7
7
 
8
- gem 'activerecord-jdbcmysql-adapter', '~> 1.1.3', :platform => :jruby
9
- gem 'activerecord-jdbcpostgresql-adapter', '~> 1.1.3', :platform => :jruby
8
+ gem 'activerecord-jdbcmysql-adapter', '~> 1.3.4', :platform => :jruby
9
+ gem 'activerecord-jdbcpostgresql-adapter', '~> 1.3.4', :platform => :jruby
data/HISTORY CHANGED
@@ -1,3 +1,35 @@
1
+ 2014-01-11: 3.1.0
2
+ * [CHANGE] Updating Riddle requirement to >= 1.5.10.
3
+ * [CHANGE] Extracting join generation into its own gem: Joiner.
4
+ * [FEATURE] Support for Capistrano v3 (Alexander Tipugin).
5
+ * [FEATURE] JRuby support (with Sphinx 2.1 or newer).
6
+ * [CHANGE] Geodist calculation is now prepended to the SELECT statement, so it can be referred to by other dynamic attributes.
7
+ * [FIX] Indices will be detected in Rails engines upon configuration.
8
+ * [FEATURE] Support for Sphinx 2.2.x's HAVING and GROUP N BY SphinxQL options.
9
+ * [FEATURE] Adding max_predicted_time search option (Sphinx 2.2.x).
10
+ * [FEATURE] Wildcard/starring can be applied directly to strings using ThinkingSphinx::Query.wildcard('pancakes'), and escaping via ThinkingSphinx::Query.escape('pancakes').
11
+ * [CHANGE] Auto-wildcard/starring (via :star => true) now treats escaped characters as word separators.
12
+ * [FEATURE] Capistrano recipe now includes tasks for realtime indices.
13
+ * [CHANGE] Capistrano recipe no longer automatically adds thinking_sphinx:index and thinking_sphinx:start to be run after deploy:cold.
14
+ * [CHANGE] UTF-8 forced encoding is now disabled by default (in line with Sphinx 2.1.x).
15
+ * [CHANGE] Sphinx functions are now the default, instead of the legacy special variables (in line with Sphinx 2.1.x).
16
+ * [CHANGE] Rails 3.1 is no longer supported.
17
+ * [CHANGE] MRI 1.9.2 is no longer supported.
18
+ * [FIX] Destroy callbacks are ignored for non-persisted objects.
19
+ * [FEATURE] :group option within :sql options in a search call is passed through to the underlying ActiveRecord relation (Siarhei Hanchuk).
20
+ * [FIX] Blank STI values are converted to the parent class in Sphinx index data (Jonathan Greenberg).
21
+ * [CHANGE] Insist on at least * for SphinxQL SELECT statements.
22
+ * [FIX] Track indices on parent STI models when marking documents as deleted.
23
+ * [FEATURE] Persistent connections can be disabled if you wish.
24
+ * [FIX] Separate per_page/max_matches values are respected in facet searches (Timo Virkkala).
25
+ * [FIX] Don't split function calls when casting timestamps (Timo Virkalla).
26
+ * [FEATURE] Track what's being indexed, and don't double-up while indexing is running. Single indices (e.g. deltas) can be processed while a full index is happening, though.
27
+ * [FEATURE] Pass through :delta_options to delta processors (Timo Virkalla).
28
+ * [FEATURE] All delta records can have their core pairs marked as deleted after a suspended delta (use ThinkingSphinx::Deltas.suspend_and_update instead of ThinkingSphinx::Deltas.suspend).
29
+ * [CHANGE] Reset the delta column to true after core indexing is completed, instead of before, and don't filter out delta records from the core source.
30
+ * [FEATURE] Set custom database settings within the index definition, using the set_database method. A more sane approach with multiple databases.
31
+ * [CHANGE] Provide a distributed index per model that covers both core and delta indices.
32
+
1
33
  2013-10-20: 3.0.6
2
34
  * [FEATURE] Raise an error if no indices match the search criteria (Bryan Ricker).
3
35
  * [FEATURE] skip_time_zone setting is now available per environment via config/thinking_sphinx.yml to avoid the sql_query_pre time zone command.
@@ -1,15 +1,16 @@
1
1
  h1. Thinking Sphinx
2
2
 
3
- Welcome to Thinking Sphinx version 3 - a complete rewrite from past versions, built for Rails 3.1 or newer only.
3
+ Welcome to Thinking Sphinx version 3 - a complete rewrite from past versions. TS v3.0.x will work with Rails 3.1-4.0, and TS v3.1.x will work with Rails 3.2 and newer.
4
4
 
5
5
  h2. Installation
6
6
 
7
- It's a gem, so install it like you would any other gem. You will also need to specify the Mysql2 gem as well (this is not an inbuilt dependency because JRuby, when supported, will need something different):
7
+ 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:
8
8
 
9
- <pre><code>gem 'mysql2', '0.3.13'
10
- gem 'thinking-sphinx', '3.0.6'</code></pre>
9
+ <pre><code>gem 'mysql2', '0.3.13', :platform => :ruby
10
+ gem 'jdbc-mysql', '5.1.28', :platform => :jruby
11
+ gem 'thinking-sphinx', '3.1.0'</code></pre>
11
12
 
12
- The mysql2 gem is required for connecting to Sphinx, so please include it even when you're using PostgreSQL for your database.
13
+ The MySQL gems mentioned are required for connecting to Sphinx, so please include it even when you're using PostgreSQL for your database.
13
14
 
14
15
  As for Sphinx itself, you need to make sure it's compiled with MySQL support, even if you're using PostgreSQL as your database - which is normally the default, but Homebrew can be too smart sometimes. If that's your compiling tool of choice, make sure you install with the @--mysql@ flag:
15
16
 
@@ -238,6 +239,16 @@ h2. Contributing
238
239
 
239
240
  You're brave! To contribute, clone this repository and have a good look through the specs - you'll notice the distinction between acceptance tests that actually use Sphinx and go through the full stack, and unit tests (everything else) which use liberal test doubles to ensure they're only testing the behaviour of the class in question. I've found this leads to far better code design.
240
241
 
242
+ In order to run the specs, you'll need to create a MySQL database named @thinking_sphinx@:
243
+ <pre><code># Fire up a MySQL console connection:
244
+ mysql -u root
245
+ # In that console, create the database:
246
+ CREATE DATABASE thinking_sphinx;</code></pre>
247
+
248
+ You can then run the unit tests with @rake spec:unit@, the acceptance tests with @rake spec:acceptance@, or all of the tests with just @rake@.
249
+
250
+ All development is done on the @develop@ branch; please base any pull requests off of that branch.
251
+
241
252
  If you're still interested in helping evolve this, then write the tests and then the code to get them passing, and send through a pull request. No promises on merging anything, but we shall see!
242
253
 
243
254
  For some ideas behind my current approach, have a look through @sketchpad.rb@ in the root of this project. If you can make sense of that, you're doing very well indeed.
@@ -3,9 +3,10 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "mysql2", "~> 0.3.12b4", :platform=>:ruby
6
- gem "pg", "~> 0.11.0", :platform=>:ruby
6
+ gem "pg", "~> 0.16.0", :platform=>:ruby
7
7
  gem "activerecord-jdbcmysql-adapter", "~> 1.1.3", :platform=>:jruby
8
8
  gem "activerecord-jdbcpostgresql-adapter", "~> 1.1.3", :platform=>:jruby
9
+ gem "riddle", :git=>"git://github.com/pat/riddle.git", :branch=>"develop"
9
10
  gem "rails", "~> 3.2.0"
10
11
 
11
12
  gemspec :path=>"../"
@@ -3,9 +3,10 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "mysql2", "~> 0.3.12b4", :platform=>:ruby
6
- gem "pg", "~> 0.11.0", :platform=>:ruby
6
+ gem "pg", "~> 0.16.0", :platform=>:ruby
7
7
  gem "activerecord-jdbcmysql-adapter", "~> 1.1.3", :platform=>:jruby
8
8
  gem "activerecord-jdbcpostgresql-adapter", "~> 1.1.3", :platform=>:jruby
9
- gem "rails", "~> 4.0.0.rc1"
9
+ gem "riddle", :git=>"git://github.com/pat/riddle.git", :branch=>"develop"
10
+ gem "rails", "~> 4.0.2"
10
11
 
11
12
  gemspec :path=>"../"
@@ -3,9 +3,10 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "mysql2", "~> 0.3.12b4", :platform=>:ruby
6
- gem "pg", "~> 0.11.0", :platform=>:ruby
6
+ gem "pg", "~> 0.16.0", :platform=>:ruby
7
7
  gem "activerecord-jdbcmysql-adapter", "~> 1.1.3", :platform=>:jruby
8
8
  gem "activerecord-jdbcpostgresql-adapter", "~> 1.1.3", :platform=>:jruby
9
- gem "rails", "~> 3.1.0"
9
+ gem "riddle", :git=>"git://github.com/pat/riddle.git", :branch=>"develop"
10
+ gem "rails", "~> 4.1.0.beta1"
10
11
 
11
12
  gemspec :path=>"../"
@@ -1,6 +1,7 @@
1
1
  if RUBY_PLATFORM == 'java'
2
2
  require 'java'
3
3
  require 'jdbc/mysql'
4
+ Jdbc::MySQL.load_driver
4
5
  else
5
6
  require 'mysql2'
6
7
  end
@@ -46,6 +47,7 @@ require 'thinking_sphinx/callbacks'
46
47
  require 'thinking_sphinx/core'
47
48
  require 'thinking_sphinx/configuration'
48
49
  require 'thinking_sphinx/connection'
50
+ require 'thinking_sphinx/controller'
49
51
  require 'thinking_sphinx/deletion'
50
52
  require 'thinking_sphinx/errors'
51
53
  require 'thinking_sphinx/excerpter'
@@ -58,6 +60,7 @@ require 'thinking_sphinx/index_set'
58
60
  require 'thinking_sphinx/masks'
59
61
  require 'thinking_sphinx/middlewares'
60
62
  require 'thinking_sphinx/panes'
63
+ require 'thinking_sphinx/query'
61
64
  require 'thinking_sphinx/rake_interface'
62
65
  require 'thinking_sphinx/scopes'
63
66
  require 'thinking_sphinx/search'
@@ -65,9 +68,11 @@ require 'thinking_sphinx/sphinxql'
65
68
  require 'thinking_sphinx/subscribers/populator_subscriber'
66
69
  require 'thinking_sphinx/test'
67
70
  require 'thinking_sphinx/utf8'
71
+ require 'thinking_sphinx/wildcard'
68
72
  # Extended
69
73
  require 'thinking_sphinx/active_record'
70
74
  require 'thinking_sphinx/deltas'
75
+ require 'thinking_sphinx/distributed'
71
76
  require 'thinking_sphinx/real_time'
72
77
 
73
78
  require 'thinking_sphinx/railtie' if defined?(Rails)
@@ -1,4 +1,5 @@
1
1
  require 'active_record'
2
+ require 'joiner'
2
3
 
3
4
  module ThinkingSphinx::ActiveRecord
4
5
  module Callbacks; end
@@ -7,10 +8,10 @@ end
7
8
  require 'thinking_sphinx/active_record/property'
8
9
  require 'thinking_sphinx/active_record/association'
9
10
  require 'thinking_sphinx/active_record/association_proxy'
10
- require 'thinking_sphinx/active_record/associations'
11
11
  require 'thinking_sphinx/active_record/attribute'
12
12
  require 'thinking_sphinx/active_record/base'
13
13
  require 'thinking_sphinx/active_record/column'
14
+ require 'thinking_sphinx/active_record/column_sql_presenter'
14
15
  require 'thinking_sphinx/active_record/database_adapters'
15
16
  require 'thinking_sphinx/active_record/field'
16
17
  require 'thinking_sphinx/active_record/filtered_reflection'
@@ -31,7 +31,7 @@ class ThinkingSphinx::ActiveRecord::AssociationProxy::AttributeFinder
31
31
  configuration.preload_indices
32
32
  configuration.indices_for_references(
33
33
  *@association.klass.name.underscore.to_sym
34
- )
34
+ ).reject &:distributed?
35
35
  end
36
36
  end
37
37
 
@@ -4,17 +4,16 @@ class ThinkingSphinx::ActiveRecord::Callbacks::DeleteCallbacks <
4
4
  callbacks :after_destroy
5
5
 
6
6
  def after_destroy
7
- indices.each { |index| ThinkingSphinx::Deletion.perform index, instance }
7
+ return if instance.new_record?
8
+
9
+ indices.each { |index|
10
+ ThinkingSphinx::Deletion.perform index, instance.id
11
+ }
8
12
  end
9
13
 
10
14
  private
11
15
 
12
- def config
13
- ThinkingSphinx::Configuration.instance
14
- end
15
-
16
16
  def indices
17
- config.preload_indices
18
- config.indices_for_references instance.class.name.underscore.to_sym
17
+ ThinkingSphinx::IndexSet.new([instance.class], []).to_a
19
18
  end
20
19
  end
@@ -30,11 +30,11 @@ class ThinkingSphinx::ActiveRecord::Callbacks::DeltaCallbacks <
30
30
  end
31
31
 
32
32
  def core_indices
33
- @core_indices ||= indices.reject { |index| index.delta? }
33
+ @core_indices ||= indices.reject &:delta?
34
34
  end
35
35
 
36
36
  def delta_indices
37
- @delta_indices ||= indices.select { |index| index.delta? }
37
+ @delta_indices ||= indices.select &:delta?
38
38
  end
39
39
 
40
40
  def delta_indices?
@@ -7,7 +7,7 @@ class ThinkingSphinx::ActiveRecord::Callbacks::UpdateCallbacks <
7
7
  return unless updates_enabled?
8
8
 
9
9
  indices.each do |index|
10
- update index
10
+ update index unless index.distributed?
11
11
  end
12
12
  end
13
13
 
@@ -0,0 +1,34 @@
1
+ class ThinkingSphinx::ActiveRecord::ColumnSQLPresenter
2
+ def initialize(model, column, adapter, associations)
3
+ @model, @column, @adapter, @associations = model, column, adapter, associations
4
+ end
5
+
6
+ def aggregate?
7
+ path.aggregate?
8
+ rescue Joiner::AssociationNotFound
9
+ false
10
+ end
11
+
12
+ def with_table
13
+ return __name if string?
14
+ return nil unless exists?
15
+
16
+ "#{associations.alias_for(__stack)}.#{adapter.quote __name}"
17
+ end
18
+
19
+ private
20
+
21
+ attr_reader :model, :column, :adapter, :associations
22
+
23
+ delegate :__stack, :__name, :string?, :to => :column
24
+
25
+ def exists?
26
+ path.model.column_names.include?(column.__name.to_s)
27
+ rescue Joiner::AssociationNotFound
28
+ false
29
+ end
30
+
31
+ def path
32
+ Joiner::Path.new model, column.__stack
33
+ end
34
+ end
@@ -21,6 +21,10 @@ class ThinkingSphinx::ActiveRecord::DatabaseAdapters::MySQLAdapter <
21
21
  "IFNULL(#{clause}, #{default})"
22
22
  end
23
23
 
24
+ def convert_blank(clause, default = '')
25
+ "COALESCE(NULLIF(#{clause}, ''), #{default})"
26
+ end
27
+
24
28
  def group_concatenate(clause, separator = ' ')
25
29
  "GROUP_CONCAT(DISTINCT #{clause} SEPARATOR '#{separator}')"
26
30
  end
@@ -27,6 +27,10 @@ class ThinkingSphinx::ActiveRecord::DatabaseAdapters::PostgreSQLAdapter <
27
27
  "COALESCE(#{clause}, #{default})"
28
28
  end
29
29
 
30
+ def convert_blank(clause, default = '')
31
+ "COALESCE(NULLIF(#{clause}, ''), #{default})"
32
+ end
33
+
30
34
  def group_concatenate(clause, separator = ' ')
31
35
  "array_to_string(array_agg(DISTINCT #{clause}), '#{separator}')"
32
36
  end
@@ -17,7 +17,7 @@ class ThinkingSphinx::ActiveRecord::Index < Riddle::Configuration::Index
17
17
  end
18
18
 
19
19
  def delta_processor
20
- @options[:delta_processor].try(:new, adapter)
20
+ @options[:delta_processor].try(:new, adapter, @options[:delta_options] || {})
21
21
  end
22
22
 
23
23
  def facets
@@ -62,6 +62,7 @@ class ThinkingSphinx::ActiveRecord::Index < Riddle::Configuration::Index
62
62
  :offset => offset,
63
63
  :delta? => @options[:delta?],
64
64
  :delta_processor => @options[:delta_processor],
65
+ :delta_options => @options[:delta_options],
65
66
  :primary_key => @options[:primary_key] || model.primary_key || :id
66
67
  }
67
68
  end
@@ -38,6 +38,13 @@ class ThinkingSphinx::ActiveRecord::Interpreter <
38
38
  __source.model.send :sanitize_sql, *arguments
39
39
  end
40
40
 
41
+ def set_database(hash_or_key)
42
+ configuration = hash_or_key.is_a?(::Hash) ? hash_or_key :
43
+ ::ActiveRecord::Base.configurations[hash_or_key.to_s]
44
+
45
+ __source.set_database_settings configuration
46
+ end
47
+
41
48
  def set_property(properties)
42
49
  properties.each do |key, value|
43
50
  @index.send("#{key}=", value) if @index.class.settings.include?(key)
@@ -1,7 +1,7 @@
1
1
  class ThinkingSphinx::ActiveRecord::Property
2
2
  include ThinkingSphinx::Core::Property
3
3
 
4
- attr_reader :columns, :options
4
+ attr_reader :model, :columns, :options
5
5
 
6
6
  def initialize(model, columns, options = {})
7
7
  @model, @options = model, options
@@ -22,9 +22,7 @@ class ThinkingSphinx::ActiveRecord::PropertySQLPresenter
22
22
  delegate :multi?, :to => :property
23
23
 
24
24
  def aggregate?
25
- property.columns.any? { |column|
26
- associations.aggregate_for?(column.__stack)
27
- }
25
+ column_presenters.any? &:aggregate?
28
26
  end
29
27
 
30
28
  def aggregate_separator
@@ -32,6 +30,8 @@ class ThinkingSphinx::ActiveRecord::PropertySQLPresenter
32
30
  end
33
31
 
34
32
  def cast_to_timestamp(clause)
33
+ return adapter.cast_to_timestamp clause if property.columns.any?(&:string?)
34
+
35
35
  clause.split(', ').collect { |part|
36
36
  adapter.cast_to_timestamp part
37
37
  }.join(', ')
@@ -48,22 +48,16 @@ class ThinkingSphinx::ActiveRecord::PropertySQLPresenter
48
48
  clause
49
49
  end
50
50
 
51
- def column_exists?(column)
52
- model = associations.model_for(column.__stack)
53
- model && model.column_names.include?(column.__name.to_s)
54
- end
55
-
56
- def column_with_table(column)
57
- return column.__name if column.string?
58
- return nil unless column_exists?(column)
59
-
60
- "#{associations.alias_for(column.__stack)}.#{adapter.quote column.__name}"
51
+ def column_presenters
52
+ @column_presenters ||= property.columns.collect { |column|
53
+ ThinkingSphinx::ActiveRecord::ColumnSQLPresenter.new(
54
+ property.model, column, adapter, associations
55
+ )
56
+ }
61
57
  end
62
58
 
63
59
  def columns_with_table
64
- property.columns.collect { |column|
65
- column_with_table(column)
66
- }.compact.join(', ')
60
+ column_presenters.collect(&:with_table).compact.join(', ')
67
61
  end
68
62
 
69
63
  def concatenating?