friendlyfashion-thinking-sphinx 2.0.14.1 → 2.0.14.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/features/deleting_instances.feature +4 -4
- data/lib/thinking_sphinx.rb +6 -0
- data/lib/thinking_sphinx/connection.rb +2 -2
- data/lib/thinking_sphinx/deltas.rb +2 -0
- data/lib/thinking_sphinx/deltas/default_delta.rb +14 -18
- data/lib/thinking_sphinx/deltas/delete_job.rb +16 -0
- data/lib/thinking_sphinx/deltas/index_job.rb +20 -0
- data/lib/thinking_sphinx/search.rb +2 -1
- data/lib/thinking_sphinx/tasks.rb +1 -0
- data/lib/thinking_sphinx/version.rb +1 -1
- data/spec/thinking_sphinx/active_record/delta_spec.rb +5 -4
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MTFlN2QzODFjMWM3NTNkZGQxOTczNGYxYWY5MDMyMjVmOWM1YTZmMQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NDhmN2I1ZWEzYmE1M2QxYjY2M2VmMTVhYzVjZWM3NjQ5ZTQyNGU0Mg==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZGIzYjQyYmUzMTNjNjZlZDliY2ViNGFkNzJiN2M2YjkzZTYyMzI3YzFiMTE3
|
10
|
+
YWYzYzU5ODQyYTJhYThjZGU3MjJiMDFkZWNhNmE5OTU5ZjA2MWE5NjA5ZTRj
|
11
|
+
MDlkNjJiY2RmOWQ3NTgzYTk4ZDlmMWM4OTA0Y2E2Njg5Y2QxOTM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
Njk5NmY2MmQ2N2JkNDk4NTM2MTZmZmIwZTc5ZDI3ZDNhZGJjNjgwYzkxNjg3
|
14
|
+
OTM3ZThkMDgyZTYwYmI1NTFmNGNjMDM5MmRmZmYxZTAyOWJiMGU0YWNhY2Fk
|
15
|
+
ZjIyYzJiZmM4ZTJmMDg1N2RhNmM4ZmIwMDBlMjMwYWU2ODhjZDI=
|
@@ -28,15 +28,15 @@ Feature: Keeping Sphinx in line with deleted model instances
|
|
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
|
31
|
+
When I create a new beta named eighteen
|
32
32
|
And I wait for Sphinx to catch up
|
33
33
|
And I clear the connection pool
|
34
|
-
And I search for
|
34
|
+
And I search for eighteen
|
35
35
|
Then I should get 1 result
|
36
36
|
|
37
|
-
When I destroy beta
|
37
|
+
When I destroy beta eighteen
|
38
38
|
And I wait for Sphinx to catch up
|
39
|
-
And I search for
|
39
|
+
And I search for eighteen
|
40
40
|
Then I should get 0 results
|
41
41
|
|
42
42
|
Scenario: Deleting edited instances from the delta index
|
data/lib/thinking_sphinx.rb
CHANGED
@@ -295,5 +295,11 @@ module ThinkingSphinx
|
|
295
295
|
!!defined?(::ActiveRecord::Associations::CollectionProxy)
|
296
296
|
end
|
297
297
|
|
298
|
+
def self.before_index_hooks
|
299
|
+
@before_index_hooks
|
300
|
+
end
|
301
|
+
|
302
|
+
@before_index_hooks = []
|
303
|
+
|
298
304
|
extend ThinkingSphinx::SearchMethods::ClassMethods
|
299
305
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
class ThinkingSphinx::Connection
|
2
2
|
def self.pool
|
3
3
|
@pool ||= Innertube::Pool.new(
|
4
|
-
Proc.new {
|
4
|
+
Proc.new { ThinkingSphinx::Connection.new },
|
5
5
|
Proc.new { |connection| connection.close }
|
6
6
|
)
|
7
7
|
end
|
@@ -14,7 +14,7 @@ class ThinkingSphinx::Connection
|
|
14
14
|
connection.reset
|
15
15
|
begin
|
16
16
|
yield connection
|
17
|
-
rescue Riddle::ConnectionError, Riddle::ResponseError => error
|
17
|
+
rescue Riddle::ConnectionError, Riddle::ResponseError, SystemCallError => error
|
18
18
|
original = error
|
19
19
|
raise Innertube::Pool::BadResource
|
20
20
|
end
|
@@ -2,23 +2,23 @@ module ThinkingSphinx
|
|
2
2
|
module Deltas
|
3
3
|
class DefaultDelta
|
4
4
|
attr_accessor :column
|
5
|
-
|
5
|
+
|
6
6
|
def initialize(index, options)
|
7
7
|
@index = index
|
8
8
|
@column = options.delete(:delta_column) || :delta
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
def index(model, instance = nil)
|
12
12
|
return true unless ThinkingSphinx.updates_enabled? &&
|
13
13
|
ThinkingSphinx.deltas_enabled?
|
14
14
|
return true if instance && !toggled(instance)
|
15
|
-
|
15
|
+
|
16
16
|
update_delta_indexes model
|
17
17
|
delete_from_core model, instance if instance
|
18
|
-
|
18
|
+
|
19
19
|
true
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
def toggle(instance)
|
23
23
|
instance.send "#{@column}=", true
|
24
24
|
end
|
@@ -32,28 +32,24 @@ module ThinkingSphinx
|
|
32
32
|
"#{model.connection.quote_column_name(@column.to_s)} = #{adapter.boolean(false)} " +
|
33
33
|
"WHERE #{model.connection.quote_column_name(@column.to_s)} = #{adapter.boolean(true)}"
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
def clause(model, toggled)
|
37
37
|
"#{model.quoted_table_name}.#{model.connection.quote_column_name(@column.to_s)}" +
|
38
38
|
" = #{adapter.boolean(toggled)}"
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
private
|
42
|
-
|
42
|
+
|
43
43
|
def update_delta_indexes(model)
|
44
|
-
|
45
|
-
rotate = ThinkingSphinx.sphinx_running? ? "--rotate" : ""
|
46
|
-
|
47
|
-
output = `#{config.bin_path}#{config.indexer_binary_name} --config "#{config.config_file}" #{rotate} #{model.delta_index_names.join(' ')}`
|
48
|
-
puts(output) unless ThinkingSphinx.suppress_delta_output?
|
44
|
+
ThinkingSphinx::Deltas::IndexJob.new(model.delta_index_names).perform
|
49
45
|
end
|
50
|
-
|
46
|
+
|
51
47
|
def delete_from_core(model, instance)
|
52
|
-
|
53
|
-
model.
|
54
|
-
|
48
|
+
ThinkingSphinx::Deltas::DeleteJob.new(
|
49
|
+
model.core_index_names, instance.sphinx_document_id
|
50
|
+
).perform
|
55
51
|
end
|
56
|
-
|
52
|
+
|
57
53
|
def adapter
|
58
54
|
@adapter = @index.model.sphinx_database_adapter
|
59
55
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class ThinkingSphinx::Deltas::DeleteJob
|
2
|
+
def initialize(indices, document_id)
|
3
|
+
@indices, @document_id = indices, document_id
|
4
|
+
end
|
5
|
+
|
6
|
+
def perform
|
7
|
+
ThinkingSphinx::Connection.take do |client|
|
8
|
+
@indices.each do |index|
|
9
|
+
client.update(index, ['sphinx_deleted'], {@document_id => [1]})
|
10
|
+
end
|
11
|
+
end
|
12
|
+
rescue Riddle::ConnectionError, Riddle::ResponseError,
|
13
|
+
ThinkingSphinx::SphinxError, Errno::ETIMEDOUT, Timeout::Error
|
14
|
+
# Not the end of the world if Sphinx isn't running.
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class ThinkingSphinx::Deltas::IndexJob
|
2
|
+
def initialize(indices)
|
3
|
+
@indices = indices
|
4
|
+
end
|
5
|
+
|
6
|
+
def perform
|
7
|
+
rotate = ThinkingSphinx.sphinx_running? ? "--rotate" : ""
|
8
|
+
|
9
|
+
output = `#{configuration.bin_path}#{configuration.indexer_binary_name} --config "#{configuration.config_file}" #{rotate} #{@indices.join(' ')}`
|
10
|
+
puts(output) unless ThinkingSphinx.suppress_delta_output?
|
11
|
+
|
12
|
+
ThinkingSphinx::Connection.pool.clear
|
13
|
+
|
14
|
+
true
|
15
|
+
end
|
16
|
+
|
17
|
+
def configuration
|
18
|
+
ThinkingSphinx::Configuration.instance
|
19
|
+
end
|
20
|
+
end
|
@@ -671,7 +671,8 @@ module ThinkingSphinx
|
|
671
671
|
return '' if @options[:conditions].blank?
|
672
672
|
|
673
673
|
' ' + @options[:conditions].keys.collect { |key|
|
674
|
-
"
|
674
|
+
search_key = key.is_a?(::Array) ? "(#{key.join(',')})" : key
|
675
|
+
"@#{search_key} #{options[:conditions][key]}"
|
675
676
|
}.join(' ')
|
676
677
|
end
|
677
678
|
|
@@ -65,12 +65,15 @@ describe "ThinkingSphinx::ActiveRecord::Delta" do
|
|
65
65
|
end
|
66
66
|
|
67
67
|
describe "index_delta method" do
|
68
|
+
let(:index_job) { double :perform => true }
|
69
|
+
|
68
70
|
before :each do
|
69
71
|
ThinkingSphinx::Configuration.stub!(:environment => "spec")
|
70
72
|
ThinkingSphinx.deltas_enabled = true
|
71
73
|
ThinkingSphinx.updates_enabled = true
|
72
74
|
ThinkingSphinx.stub!(:sphinx_running? => true)
|
73
75
|
Person.delta_objects.first.stub!(:` => "", :toggled => true)
|
76
|
+
ThinkingSphinx::Deltas::IndexJob.stub :new => index_job
|
74
77
|
|
75
78
|
@person = Person.new
|
76
79
|
Person.stub!(:search_for_id => false)
|
@@ -104,10 +107,8 @@ describe "ThinkingSphinx::ActiveRecord::Delta" do
|
|
104
107
|
@person.send(:index_delta)
|
105
108
|
end
|
106
109
|
|
107
|
-
it "should
|
108
|
-
|
109
|
-
"#{ThinkingSphinx::Configuration.instance.bin_path}indexer --config \"#{ThinkingSphinx::Configuration.instance.config_file}\" --rotate person_delta"
|
110
|
-
)
|
110
|
+
it "should run the index job" do
|
111
|
+
index_job.should_receive(:perform)
|
111
112
|
|
112
113
|
@person.send(:index_delta)
|
113
114
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: friendlyfashion-thinking-sphinx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.14.
|
4
|
+
version: 2.0.14.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justas Janauskas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-04-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -215,6 +215,8 @@ files:
|
|
215
215
|
- lib/thinking_sphinx/core/string.rb
|
216
216
|
- lib/thinking_sphinx/deltas.rb
|
217
217
|
- lib/thinking_sphinx/deltas/default_delta.rb
|
218
|
+
- lib/thinking_sphinx/deltas/delete_job.rb
|
219
|
+
- lib/thinking_sphinx/deltas/index_job.rb
|
218
220
|
- lib/thinking_sphinx/deploy/capistrano.rb
|
219
221
|
- lib/thinking_sphinx/excerpter.rb
|
220
222
|
- lib/thinking_sphinx/facet.rb
|