thinking-sphinx 1.4.14 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. data/features/attribute_updates.feature +15 -13
  2. data/features/deleting_instances.feature +16 -13
  3. data/features/handling_edits.feature +20 -17
  4. data/features/searching_by_index.feature +6 -5
  5. data/features/step_definitions/common_steps.rb +8 -4
  6. data/features/support/env.rb +0 -3
  7. data/lib/thinking_sphinx.rb +8 -1
  8. data/lib/thinking_sphinx/active_record.rb +3 -3
  9. data/lib/thinking_sphinx/active_record/attribute_updates.rb +5 -4
  10. data/lib/thinking_sphinx/adapters/abstract_adapter.rb +7 -0
  11. data/lib/thinking_sphinx/auto_version.rb +1 -1
  12. data/lib/thinking_sphinx/bundled_search.rb +6 -10
  13. data/lib/thinking_sphinx/configuration.rb +19 -33
  14. data/lib/thinking_sphinx/connection.rb +71 -0
  15. data/lib/thinking_sphinx/deltas.rb +2 -0
  16. data/lib/thinking_sphinx/deltas/default_delta.rb +14 -18
  17. data/lib/thinking_sphinx/deltas/delete_job.rb +16 -0
  18. data/lib/thinking_sphinx/deltas/index_job.rb +17 -0
  19. data/lib/thinking_sphinx/search.rb +26 -14
  20. data/lib/thinking_sphinx/tasks.rb +1 -5
  21. data/spec/spec_helper.rb +0 -3
  22. data/spec/thinking_sphinx/active_record/delta_spec.rb +6 -5
  23. data/spec/thinking_sphinx/active_record/scopes_spec.rb +2 -1
  24. data/spec/thinking_sphinx/active_record_spec.rb +2 -2
  25. data/spec/thinking_sphinx/adapters/abstract_adapter_spec.rb +18 -0
  26. data/spec/thinking_sphinx/configuration_spec.rb +0 -68
  27. data/spec/thinking_sphinx/connection_spec.rb +77 -0
  28. data/spec/thinking_sphinx/facet_search_spec.rb +25 -25
  29. data/spec/thinking_sphinx/search_methods_spec.rb +34 -34
  30. data/spec/thinking_sphinx/search_spec.rb +4 -16
  31. metadata +48 -39
  32. data/lib/thinking_sphinx/version.rb +0 -3
  33. data/rails/init.rb +0 -16
  34. data/tasks/rails.rake +0 -1
@@ -2,13 +2,13 @@ Feature: Update attributes directly to Sphinx
2
2
  In order for updates to be more seamless
3
3
  The plugin
4
4
  Should update Sphinx's attributes where possible
5
-
5
+
6
6
  Scenario: Updating attributes in Sphinx without delta indexes
7
7
  Given Sphinx is running
8
8
  And I am searching on alphas
9
9
  When I filter by 3 on value
10
10
  Then I should get 1 result
11
-
11
+
12
12
  When I change the value of alpha four to 13
13
13
  And I wait for Sphinx to catch up
14
14
  And I filter by 13 on value
@@ -16,7 +16,7 @@ Feature: Update attributes directly to Sphinx
16
16
  Then I should get 1 result
17
17
  When I use index alternative_core
18
18
  Then I should get 1 result
19
-
19
+
20
20
  When I change the value of alpha four to 4
21
21
  And I wait for Sphinx to catch up
22
22
  And I filter by 13 on value
@@ -30,47 +30,49 @@ Feature: Update attributes directly to Sphinx
30
30
  And I am searching on betas
31
31
  When I filter by 8 on value
32
32
  Then I should get 1 result
33
-
33
+
34
34
  When I change the value of beta eight to 18
35
35
  And I wait for Sphinx to catch up
36
36
  And I filter by 18 on value
37
37
  Then I should get 1 result
38
-
38
+
39
39
  When I search for the document id of beta eight in the secondary_beta_delta index
40
40
  Then it should not exist
41
-
41
+
42
42
  Scenario: Updating attributes in a delta index
43
43
  Given Sphinx is running
44
44
  And I am searching on betas
45
-
45
+
46
46
  When I change the name of beta nine to nineteen
47
47
  And I change the value of beta nineteen to 19
48
48
  And I wait for Sphinx to catch up
49
-
49
+
50
50
  When I filter by 19 on value
51
51
  And I use index secondary_beta_delta
52
+ And I clear the connection pool
52
53
  Then I should get 1 result
53
-
54
+
54
55
  Scenario: Updating attributes in a delta index with deltas disabled
55
56
  Given Sphinx is running
56
57
  And I am searching on betas
57
-
58
+
58
59
  When I change the name of beta eleven to twentyone
59
60
  And I disable delta updates
60
61
  And I change the value of beta twentyone to 21
61
62
  And I wait for Sphinx to catch up
62
-
63
+ And I clear the connection pool
64
+
63
65
  When I filter by 21 on value
64
66
  And I use index secondary_beta_delta
65
67
  Then I should get 1 result
66
68
  And I enable delta updates
67
-
69
+
68
70
  Scenario: Updating boolean attribute in Sphinx
69
71
  Given Sphinx is running
70
72
  And I am searching on alphas
71
73
  When I filter by active alphas
72
74
  Then I should get 10 results
73
-
75
+
74
76
  When I flag alpha five as inactive
75
77
  And I wait for Sphinx to catch up
76
78
  And I filter by active alphas
@@ -2,50 +2,52 @@ Feature: Keeping Sphinx in line with deleted model instances
2
2
  In order to avoid deleted items being returned by Sphinx
3
3
  Thinking Sphinx
4
4
  Should keep deleted items out of search results
5
-
5
+
6
6
  Scenario: Deleting instances from the core index
7
7
  Given Sphinx is running
8
8
  And I am searching on betas
9
9
  When I search for three
10
10
  Then I should get 1 result
11
-
11
+
12
12
  When I destroy beta three
13
13
  And I wait for Sphinx to catch up
14
14
  And I search for three
15
15
  Then I should get 0 results
16
-
16
+
17
17
  Scenario: Deleting subclasses when the parent class is indexed
18
18
  Given Sphinx is running
19
19
  And I am searching on cats
20
20
  When I search for moggy
21
21
  Then I should get 1 result
22
-
22
+
23
23
  When I destroy cat moggy
24
24
  And I wait for Sphinx to catch up
25
25
  And I search for moggy
26
26
  Then I should get 0 results
27
-
27
+
28
28
  Scenario: Deleting created instances from the delta index
29
29
  Given Sphinx is running
30
30
  And I am searching on betas
31
- When I create a new beta named eleven
31
+ When I create a new beta named eighteen
32
32
  And I wait for Sphinx to catch up
33
- And I search for eleven
33
+ And I clear the connection pool
34
+ And I search for eighteen
34
35
  Then I should get 1 result
35
-
36
- When I destroy beta eleven
36
+
37
+ When I destroy beta eighteen
37
38
  And I wait for Sphinx to catch up
38
- And I search for eleven
39
+ And I search for eighteen
39
40
  Then I should get 0 results
40
-
41
+
41
42
  Scenario: Deleting edited instances from the delta index
42
43
  Given Sphinx is running
43
44
  And I am searching on betas
44
45
  When I change the name of beta four to fourteen
45
46
  And I wait for Sphinx to catch up
47
+ And I clear the connection pool
46
48
  And I search for fourteen
47
49
  Then I should get 1 result
48
-
50
+
49
51
  When I destroy beta fourteen
50
52
  And I wait for Sphinx to catch up
51
53
  And I search for fourteen
@@ -56,9 +58,10 @@ Feature: Keeping Sphinx in line with deleted model instances
56
58
  And I am searching on betas
57
59
  When I create a new beta named thirteen
58
60
  And I wait for Sphinx to catch up
61
+ And I clear the connection pool
59
62
  And I search for thirteen
60
63
  Then I should get 1 result
61
-
64
+
62
65
  And I disable delta updates
63
66
  And I destroy beta thirteen
64
67
  And I wait for Sphinx to catch up
@@ -2,72 +2,75 @@ Feature: Keeping Sphinx in line with model changes when requested
2
2
  In order to keep indexes as up to date as possible
3
3
  Thinking Sphinx
4
4
  Should return the expected results depending on whether delta indexes are used
5
-
5
+
6
6
  Scenario: Returning instance from old data if there is no delta
7
7
  Given Sphinx is running
8
8
  And I am searching on alphas
9
9
  When I search for two
10
10
  Then I should get 1 result
11
-
11
+
12
12
  When I change the name of alpha two to twelve
13
13
  And I wait for Sphinx to catch up
14
14
  And I search for two
15
15
  Then I should get 1 result
16
-
16
+
17
17
  Scenario: Not returning an instance from old data if there is a delta
18
18
  Given Sphinx is running
19
19
  And I am searching on betas
20
20
  When I search for two
21
21
  Then I should get 1 result
22
-
22
+
23
23
  When I change the name of beta two to twelve
24
24
  And I wait for Sphinx to catch up
25
+ And I clear the connection pool
25
26
  And I search for two
26
27
  Then I should get 0 results
27
-
28
+
28
29
  Scenario: Returning instance from new data if there is a delta
29
30
  Given Sphinx is running
30
31
  And I am searching on betas
31
32
  When I search for one
32
33
  Then I should get 1 result
33
-
34
+
34
35
  When I change the name of beta one to eleventeen
35
36
  And I wait for Sphinx to catch up
37
+ And I clear the connection pool
36
38
  And I search for one
37
39
  Then I should get 0 results
38
-
40
+
39
41
  When I search for eleventeen
40
42
  Then I should get 1 result
41
-
43
+
42
44
  Scenario: Returning new records if there's a delta
43
45
  Given Sphinx is running
44
46
  And I am searching on betas
45
47
  When I search for fifteen
46
48
  Then I should get 0 results
47
-
49
+
48
50
  When I create a new beta named fifteen
49
51
  And I wait for Sphinx to catch up
52
+ And I clear the connection pool
50
53
  And I search for fifteen
51
54
  Then I should get 1 result
52
-
55
+
53
56
  Scenario: Avoiding delta updates if there hasn't been changes
54
57
  Given Sphinx is running
55
58
  And I am searching on betas
56
59
  When I search for five
57
60
  Then I should get 1 result
58
-
61
+
59
62
  When I change the name of beta five to five
60
63
  And I wait for Sphinx to catch up
61
64
  And I search for five
62
65
  Then I should get 1 result
63
-
66
+
64
67
  When I search for the document id of beta five in the beta_core index
65
68
  Then it should exist if using Rails 2.1 or newer
66
69
  When I search for the document id of beta five in the secondary_beta_core index
67
70
  Then it should exist if using Rails 2.1 or newer
68
71
  When I search for the document id of beta five in the secondary_beta_delta index
69
72
  Then it should not exist if using Rails 2.1 or newer
70
-
73
+
71
74
  Scenario: Handling edits with a delta when Sphinx isn't running
72
75
  Given Sphinx is running
73
76
  And I am searching on betas
@@ -76,19 +79,19 @@ Feature: Keeping Sphinx in line with model changes when requested
76
79
  And I start Sphinx
77
80
  And I search for sixteen
78
81
  Then I should get 1 result
79
-
82
+
80
83
  Scenario: Handling edits when updates are disabled
81
84
  Given Sphinx is running
82
85
  And updates are disabled
83
86
  And I am searching on betas
84
-
87
+
85
88
  When I search for seven
86
89
  Then I should get 1 result
87
-
90
+
88
91
  When I change the name of beta seven to seventeen
89
92
  And I wait for Sphinx to catch up
90
93
  And I search for seven
91
94
  Then I should get 1 result
92
-
95
+
93
96
  When I search for seventeen
94
97
  Then I should get 0 results
@@ -2,21 +2,21 @@ Feature: Searching within a single index
2
2
  In order to use Thinking Sphinx's core functionality
3
3
  A developer
4
4
  Should be able to search on a single index
5
-
5
+
6
6
  Scenario: Searching with alternative index
7
7
  Given Sphinx is running
8
8
  And I am searching on alphas
9
9
  When I order by value
10
10
  And I use index alternative_core
11
11
  Then I should get 7 results
12
-
12
+
13
13
  Scenario: Searching with default index
14
14
  Given Sphinx is running
15
15
  And I am searching on alphas
16
16
  When I order by value
17
17
  And I use index alpha_core
18
18
  Then I should get 10 results
19
-
19
+
20
20
  Scenario: Searching without specified index
21
21
  Given Sphinx is running
22
22
  And I am searching on alphas
@@ -26,14 +26,15 @@ Feature: Searching within a single index
26
26
  Scenario: Deleting instances from the core index
27
27
  Given Sphinx is running
28
28
  And I am searching on alphas
29
-
29
+
30
30
  When I create a new alpha named eleven
31
31
  And I process the alpha_core index
32
32
  And I process the alternative_core index
33
33
  And I wait for Sphinx to catch up
34
+ And I clear the connection pool
34
35
  And I search for eleven
35
36
  Then I should get 1 result
36
-
37
+
37
38
  When I destroy alpha eleven
38
39
  And I wait for Sphinx to catch up
39
40
  And I search for eleven
@@ -1,6 +1,6 @@
1
1
  Before do
2
2
  $queries_executed = []
3
-
3
+
4
4
  @model = nil
5
5
  @method = :search
6
6
  @query = ""
@@ -10,7 +10,7 @@ Before do
10
10
  @with_all = {}
11
11
  @options = {}
12
12
  @results = nil
13
-
13
+
14
14
  Given "updates are enabled"
15
15
  end
16
16
 
@@ -46,6 +46,10 @@ When /^I search for (\w+)$/ do |query|
46
46
  @query = query
47
47
  end
48
48
 
49
+ When /^I clear the connection pool$/ do
50
+ ThinkingSphinx::Connection.pool.clear
51
+ end
52
+
49
53
  When /^I search for "([^\"]*)"$/ do |query|
50
54
  @results = nil
51
55
  @query = query
@@ -154,7 +158,7 @@ Then /^the (\w+) of each result should indicate order$/ do |attribute|
154
158
  unless prev.nil?
155
159
  current.send(attribute.to_sym).should >= prev.send(attribute.to_sym)
156
160
  end
157
-
161
+
158
162
  current
159
163
  end
160
164
  end
@@ -170,7 +174,7 @@ Then /^I can iterate by result and (\w+)$/ do |attribute|
170
174
  attr_value.should be_kind_of(Integer)
171
175
  end
172
176
  }
173
-
177
+
174
178
  results.send("each_with_#{attribute}", &iteration)
175
179
  end
176
180
 
@@ -5,9 +5,6 @@ require 'bundler'
5
5
  Bundler.require :default, :development
6
6
 
7
7
  $:.unshift File.dirname(__FILE__) + '/../../lib'
8
- Dir[File.join(File.dirname(__FILE__), '../../vendor/*/lib')].each do |path|
9
- $:.unshift path
10
- end
11
8
 
12
9
  require 'cucumber/thinking_sphinx/internal_world'
13
10
 
@@ -1,6 +1,7 @@
1
1
  require 'thread'
2
2
  require 'active_record'
3
3
  require 'after_commit'
4
+ require 'innertube'
4
5
  require 'yaml'
5
6
  require 'riddle'
6
7
 
@@ -12,6 +13,7 @@ require 'thinking_sphinx/association'
12
13
  require 'thinking_sphinx/attribute'
13
14
  require 'thinking_sphinx/bundled_search'
14
15
  require 'thinking_sphinx/configuration'
16
+ require 'thinking_sphinx/connection'
15
17
  require 'thinking_sphinx/context'
16
18
  require 'thinking_sphinx/excerpter'
17
19
  require 'thinking_sphinx/facet'
@@ -25,7 +27,6 @@ require 'thinking_sphinx/rails_additions'
25
27
  require 'thinking_sphinx/search'
26
28
  require 'thinking_sphinx/search_methods'
27
29
  require 'thinking_sphinx/deltas'
28
- require 'thinking_sphinx/version'
29
30
 
30
31
  require 'thinking_sphinx/adapters/abstract_adapter'
31
32
  require 'thinking_sphinx/adapters/mysql_adapter'
@@ -295,6 +296,12 @@ module ThinkingSphinx
295
296
  )
296
297
  end
297
298
 
299
+ def self.before_index_hooks
300
+ @before_index_hooks
301
+ end
302
+
303
+ @before_index_hooks = []
304
+
298
305
  extend ThinkingSphinx::SearchMethods::ClassMethods
299
306
  end
300
307
 
@@ -276,9 +276,9 @@ module ThinkingSphinx
276
276
  def delete_in_index(index, document_id)
277
277
  return unless ThinkingSphinx.sphinx_running?
278
278
 
279
- ThinkingSphinx::Configuration.instance.client.update(
280
- index, ['sphinx_deleted'], {document_id => [1]}
281
- )
279
+ ThinkingSphinx::Connection.take do |client|
280
+ client.update index, ['sphinx_deleted'], {document_id => [1]}
281
+ end
282
282
  rescue Riddle::ConnectionError, Riddle::ResponseError,
283
283
  ThinkingSphinx::SphinxError, Errno::ETIMEDOUT, Timeout::Error
284
284
  # Not the end of the world if Sphinx isn't running.
@@ -40,10 +40,11 @@ module ThinkingSphinx
40
40
  end
41
41
 
42
42
  def update_index(index_name, attribute_names, attribute_values)
43
- config = ThinkingSphinx::Configuration.instance
44
- config.client.update index_name, attribute_names, {
45
- sphinx_document_id => attribute_values
46
- }
43
+ ThinkingSphinx::Connection.take do |client|
44
+ client.update index_name, attribute_names, {
45
+ sphinx_document_id => attribute_values
46
+ }
47
+ end
47
48
  rescue Riddle::ConnectionError, Riddle::ResponseError,
48
49
  ThinkingSphinx::SphinxError, Errno::ETIMEDOUT
49
50
  # Not the end of the world if Sphinx isn't running.
@@ -51,6 +51,13 @@ module ThinkingSphinx
51
51
  :mysql
52
52
  when "jdbcpostgresql"
53
53
  :postgresql
54
+ when "jdbc"
55
+ match = /^jdbc:(mysql|postgresql):\/\//.match(model.connection.config[:url])
56
+ if match
57
+ match[1].to_sym
58
+ else
59
+ model.connection.config[:adapter]
60
+ end
54
61
  else
55
62
  model.connection.config[:adapter].to_sym
56
63
  end