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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OWFjNTMyOTc0ZTJjYWEwNzVlNGVjMGM4YjA4MDhhNzAyNjU0ZTcyMA==
4
+ MTFlN2QzODFjMWM3NTNkZGQxOTczNGYxYWY5MDMyMjVmOWM1YTZmMQ==
5
5
  data.tar.gz: !binary |-
6
- NmYyODgwOGU4NTIzYWUxY2U3ZjQ4M2Y0Mzc1NWIwNjA3M2QwYTA5Yw==
6
+ NDhmN2I1ZWEzYmE1M2QxYjY2M2VmMTVhYzVjZWM3NjQ5ZTQyNGU0Mg==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ZTRiNzcxNWI2Y2MyZGZlZmZlZjQ0NWZiYzUzZDQ5ZWM0OWQ4NTYzNzExZTBk
10
- YzExNjM2Mjk2NWFlNDliNGQ0ZTk1YzY3Yzg0ZTc3NmRjZWE2ZTRiY2U3MzU2
11
- MjFlNzQzNzk0NWJiM2Q3ZTU3NjY3ZTU0MWUxMWVmMGI2NTQzNmE=
9
+ ZGIzYjQyYmUzMTNjNjZlZDliY2ViNGFkNzJiN2M2YjkzZTYyMzI3YzFiMTE3
10
+ YWYzYzU5ODQyYTJhYThjZGU3MjJiMDFkZWNhNmE5OTU5ZjA2MWE5NjA5ZTRj
11
+ MDlkNjJiY2RmOWQ3NTgzYTk4ZDlmMWM4OTA0Y2E2Njg5Y2QxOTM=
12
12
  data.tar.gz: !binary |-
13
- MjViNjZjZjVmMmRhODNjMjU3Njc2YmExYWQ4ZjdlZjZlMDZkMTcwYmI1MWZm
14
- NjA1MGU5YWZiMmExNzZhMzk5YjExMTg0ZDkzYjdjMDVlYTdiZTdjZDk5MWUx
15
- NzMzZGJlMzg4MDZkZWQ2ZTg2N2MwN2EwOTc3ZWViMTk5MTg4YTM=
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 eleven
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 eleven
34
+ And I search for eighteen
35
35
  Then I should get 1 result
36
36
 
37
- When I destroy beta eleven
37
+ When I destroy beta eighteen
38
38
  And I wait for Sphinx to catch up
39
- And I search for eleven
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
@@ -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 { Rails.logger.debug '>>> CONNECTING <<<'; ThinkingSphinx::Connection.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
@@ -1,4 +1,6 @@
1
1
  require 'thinking_sphinx/deltas/default_delta'
2
+ require 'thinking_sphinx/deltas/delete_job'
3
+ require 'thinking_sphinx/deltas/index_job'
2
4
 
3
5
  module ThinkingSphinx
4
6
  module Deltas
@@ -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
- config = ThinkingSphinx::Configuration.instance
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
- model.core_index_names.each do |index_name|
53
- model.delete_in_index index_name, instance.sphinx_document_id
54
- end
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
- "@#{key} #{options[:conditions][key]}"
674
+ search_key = key.is_a?(::Array) ? "(#{key.join(',')})" : key
675
+ "@#{search_key} #{options[:conditions][key]}"
675
676
  }.join(' ')
676
677
  end
677
678
 
@@ -89,6 +89,7 @@ namespace :thinking_sphinx do
89
89
  end
90
90
 
91
91
  FileUtils.mkdir_p config.searchd_file_path
92
+ ThinkingSphinx.before_index_hooks.each { |hook| hook.call }
92
93
  config.controller.index :verbose => true
93
94
  end
94
95
 
@@ -1,3 +1,3 @@
1
1
  module ThinkingSphinx
2
- Version = '2.0.14.1'
2
+ Version = '2.0.14.2'
3
3
  end
@@ -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 call indexer for the delta index" do
108
- Person.sphinx_indexes.first.delta_object.should_receive(:`).with(
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.1
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-03-17 00:00:00.000000000 Z
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