flying-sphinx 0.8.2 → 0.8.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/HISTORY CHANGED
@@ -1,3 +1,8 @@
1
+ 0.8.3 - 17th September 2012
2
+ * Requires Rails 3 or better (if you're using Rails).
3
+ * Load Rails when configuring.
4
+ * Don't check whether a document exists before marking it as deleted - Sphinx handles this gracefully anyway.
5
+
1
6
  0.8.2 - 28th August 2012
2
7
  * Don't presume there is a Time.zone method (for Rails 2.3).
3
8
  * Set client key as part of the configuration generation process (for Rails 2.3).
@@ -28,7 +28,7 @@ class FlyingSphinx::CLI
28
28
 
29
29
  def configure
30
30
  if @arguments.empty?
31
- require 'thinking_sphinx'
31
+ load_rails
32
32
  FlyingSphinx::SphinxConfiguration.new.upload_to configuration.api
33
33
  FlyingSphinx::SettingFiles.new.upload_to configuration.api
34
34
  else
@@ -50,6 +50,14 @@ class FlyingSphinx::CLI
50
50
  true
51
51
  end
52
52
 
53
+ def load_rails
54
+ return unless ENV['RAILS_ENV']
55
+
56
+ require File.expand_path('config/boot', Dir.pwd)
57
+ require File.expand_path('config/application', Dir.pwd)
58
+ Rails.application.require_environment!
59
+ end
60
+
53
61
  def start
54
62
  if configuration.start_sphinx
55
63
  puts "Started Sphinx"
@@ -1,44 +1,40 @@
1
1
  # A simple job for flagging a specified Sphinx document in a given index as
2
2
  # 'deleted'.
3
- #
3
+ #
4
4
  class FlyingSphinx::FlagAsDeletedJob
5
5
  attr_accessor :indices, :document_id
6
-
6
+
7
7
  # Initialises the object with an index name and document id. Please note that
8
8
  # the document id is Sphinx's unique identifier, and will almost certainly not
9
9
  # be the model instance's primary key value.
10
- #
10
+ #
11
11
  # @param [String] index The index name
12
12
  # @param [Integer] document_id The document id
13
- #
13
+ #
14
14
  def initialize(indices, document_id)
15
15
  @indices, @document_id = indices, document_id
16
16
  end
17
-
17
+
18
18
  # Updates the sphinx_deleted attribute for the given document, setting the
19
19
  # value to 1 (true). This is not a special attribute in Sphinx, but is used
20
20
  # by Thinking Sphinx to ignore deleted values between full re-indexing. It's
21
21
  # particularly useful in this situation to avoid old values in the core index
22
22
  # and just use the new values in the delta index as a reference point.
23
- #
23
+ #
24
24
  # @return [Boolean] true
25
- #
25
+ #
26
26
  def perform
27
27
  indices.each do |index|
28
- client.update(
29
- index,
30
- ['sphinx_deleted'],
31
- {@document_id => [1]}
32
- ) if ThinkingSphinx.search_for_id(@document_id, index)
28
+ client.update index, ['sphinx_deleted'], {@document_id => [1]}
33
29
  end
34
30
  rescue Riddle::ConnectionError
35
31
  # If it fails here, so be it.
36
32
  ensure
37
33
  true
38
34
  end
39
-
35
+
40
36
  private
41
-
37
+
42
38
  def client
43
39
  @client ||= ThinkingSphinx::Configuration.instance.client
44
40
  end
@@ -1,3 +1,3 @@
1
1
  module FlyingSphinx
2
- Version = '0.8.2'
2
+ Version = '0.8.3'
3
3
  end
@@ -5,64 +5,40 @@ describe FlyingSphinx::FlagAsDeletedJob do
5
5
  let(:config) { ThinkingSphinx::Configuration.instance }
6
6
  let(:client) { stub('client', :update => true) }
7
7
  let(:job) { FlyingSphinx::FlagAsDeletedJob.new(['foo_core'], 12) }
8
-
8
+
9
9
  before :each do
10
10
  config.stub!(:client => client)
11
- ThinkingSphinx.stub!(:search_for_id => true)
12
- end
13
-
14
- it "should not update if the document isn't in the index" do
15
- ThinkingSphinx.stub!(:search_for_id => false)
16
- client.should_not_receive(:update)
17
-
18
- job.perform
19
11
  end
20
-
12
+
21
13
  it "should update the specified index" do
22
14
  client.should_receive(:update) do |index, attributes, values|
23
15
  index.should == 'foo_core'
24
16
  end
25
-
17
+
26
18
  job.perform
27
19
  end
28
-
20
+
29
21
  it "should update all specified indexes" do
30
22
  job.indices = ['foo_core', 'bar_core']
31
23
  client.should_receive(:update).with('foo_core', anything, anything)
32
24
  client.should_receive(:update).with('bar_core', anything, anything)
33
-
25
+
34
26
  job.perform
35
27
  end
36
-
28
+
37
29
  it "should update the sphinx_deleted attribute" do
38
30
  client.should_receive(:update) do |index, attributes, values|
39
31
  attributes.should == ['sphinx_deleted']
40
32
  end
41
-
33
+
42
34
  job.perform
43
35
  end
44
-
36
+
45
37
  it "should set sphinx_deleted for the given document to true" do
46
38
  client.should_receive(:update) do |index, attributes, values|
47
39
  values[12].should == [1]
48
40
  end
49
-
50
- job.perform
51
- end
52
-
53
- it "should check for the existence of the document in the specified index" do
54
- ThinkingSphinx.should_receive(:search_for_id) do |id, index|
55
- index.should == 'foo_core'
56
- end
57
-
58
- job.perform
59
- end
60
-
61
- it "should check for the existence of the given document id" do
62
- ThinkingSphinx.should_receive(:search_for_id) do |id, index|
63
- id.should == 12
64
- end
65
-
41
+
66
42
  job.perform
67
43
  end
68
44
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flying-sphinx
3
3
  version: !ruby/object:Gem::Version
4
- hash: 59
4
+ hash: 57
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 8
9
- - 2
10
- version: 0.8.2
9
+ - 3
10
+ version: 0.8.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Pat Allan
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-08-28 00:00:00 Z
18
+ date: 2012-09-17 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: thinking-sphinx