Skip to content

Commit

Permalink
Changing indexes to indices when referring to the plural of index.
Browse files Browse the repository at this point in the history
  • Loading branch information
pat committed Nov 9, 2011
1 parent 05396bf commit 8a3da35
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 99 deletions.
4 changes: 2 additions & 2 deletions README.textile
Expand Up @@ -21,15 +21,15 @@ If this is your first time running Delayed Job, then you're going to need the jo

<pre><code>script/generate delayed_job</code></pre>

For the indexes you want to use this delta approach, make sure you set that up in their @define_index@ blocks.
For the indices you want to use this delta approach, make sure you set that up in their @define_index@ blocks.

<pre><code>define_index do
# ...

set_property :delta => :delayed
end</code></pre>

If you've never used delta indexes before, you'll want to add the boolean column named delta to each model that is using the approach.
If you've never used delta indices before, you'll want to add the boolean column named delta to each model that is using the approach.

<pre><code>def self.up
add_column :articles, :delta, :boolean, :default => true, :null => false
Expand Down
32 changes: 16 additions & 16 deletions lib/thinking_sphinx/deltas/delayed_delta/delta_job.rb
@@ -1,33 +1,33 @@
# A simple job class that processes a given index.
#
#
class ThinkingSphinx::Deltas::DeltaJob
attr_accessor :indexes
attr_accessor :indices

# Initialises the object with an index name.
#
#
# @param [String] index the name of the Sphinx index
#
def initialize(indexes)
@indexes = indexes
#
def initialize(indices)
@indices = indices
end

# Shows index name in Delayed::Job#name.
#
#
def display_name
"#{self.class.name} for #{indexes.join(', ')}"
"#{self.class.name} for #{indices.join(', ')}"
end

# Runs Sphinx's indexer tool to process the index. Currently assumes Sphinx is
# running.
#
#
# @return [Boolean] true
#
#
def perform
config = ThinkingSphinx::Configuration.instance
output = `#{config.bin_path}#{config.indexer_binary_name} --config #{config.config_file} --rotate #{indexes.join(' ')}`

output = `#{config.bin_path}#{config.indexer_binary_name} --config #{config.config_file} --rotate #{indices.join(' ')}`
puts output unless ThinkingSphinx.suppress_delta_output?

true
end
end
26 changes: 13 additions & 13 deletions lib/thinking_sphinx/deltas/delayed_delta/flag_as_deleted_job.rb
@@ -1,40 +1,40 @@
# A simple job for flagging a specified Sphinx document in a given index as
# 'deleted'.
#
#
class ThinkingSphinx::Deltas::FlagAsDeletedJob
attr_accessor :indexes, :document_id
attr_accessor :indices, :document_id

# Initialises the object with an index name and document id. Please note that
# the document id is Sphinx's unique identifier, and will almost certainly not
# be the model instance's primary key value.
#
#
# @param [String] index The index name
# @param [Integer] document_id The document id
#
def initialize(indexes, document_id)
@indexes, @document_id = indexes, document_id
#
def initialize(indices, document_id)
@indices, @document_id = indices, document_id
end

# Updates the sphinx_deleted attribute for the given document, setting the
# value to 1 (true). This is not a special attribute in Sphinx, but is used
# by Thinking Sphinx to ignore deleted values between full re-indexing. It's
# particularly useful in this situation to avoid old values in the core index
# and just use the new values in the delta index as a reference point.
#
#
# @return [Boolean] true
#
#
def perform
config = ThinkingSphinx::Configuration.instance
indexes.each do |index|

indices.each do |index|
config.client.update(
index,
['sphinx_deleted'],
{@document_id => [1]}
) if ThinkingSphinx.sphinx_running? &&
ThinkingSphinx.search_for_id(@document_id, index)
end

true
end
end
26 changes: 13 additions & 13 deletions spec/thinking_sphinx/deltas/delayed_delta/delta_job_spec.rb
Expand Up @@ -4,37 +4,37 @@
describe '#perform' do
before :each do
ThinkingSphinx.suppress_delta_output = false

@delta_job = ThinkingSphinx::Deltas::DeltaJob.new(['foo_core'])
@delta_job.stub! :` => true
@delta_job.stub! :puts => nil
end

it "should output the delta indexing by default" do
@delta_job.should_receive(:puts)

@delta_job.perform
end

it "should not output the delta indexing if requested" do
ThinkingSphinx.suppress_delta_output = true
@delta_job.should_not_receive(:puts)

@delta_job.perform
end
it "should process just the requested indexes" do

it "should process just the requested indices" do
@delta_job.should_receive(:`) do |command|
command.should match(/foo_core/)
command.should_not match(/--all/)
end

@delta_job.perform
end
context 'multiple indexes' do
it "should process all requested indexes" do
@delta_job.indexes = ['foo_core', 'bar_core']

context 'multiple indices' do
it "should process all requested indices" do
@delta_job.indices = ['foo_core', 'bar_core']
@delta_job.should_receive(:`) do |command|
command.should match(/foo_core bar_core/)
end
Expand All @@ -45,7 +45,7 @@
end

describe "#display_name" do
it "should display class name with all indexes" do
it "should display class name with all indices" do
@delta_job = ThinkingSphinx::Deltas::DeltaJob.new(['foo_core', 'bar_core'])
@delta_job.display_name.should == "ThinkingSphinx::Deltas::DeltaJob for foo_core, bar_core"
end
Expand Down
Expand Up @@ -5,73 +5,73 @@
before :each do
ThinkingSphinx.updates_enabled = true
@client = stub('client', :update => true)

ThinkingSphinx::Configuration.instance.stub!(:client => @client)
ThinkingSphinx.stub!(:search_for_id => true)
ThinkingSphinx.stub!(:sphinx_running? => true)

@job = ThinkingSphinx::Deltas::FlagAsDeletedJob.new(['foo_core'], 12)
end

it "should not update if Sphinx isn't running" do
ThinkingSphinx.stub!(:sphinx_running? => false)
@client.should_not_receive(:update)

@job.perform
end

it "should not update if the document isn't in the index" do
ThinkingSphinx.stub!(:search_for_id => false)
@client.should_not_receive(:update)

@job.perform
end

it "should update the specified index" do
@client.should_receive(:update) do |index, attributes, values|
index.should == 'foo_core'
end

@job.perform
end
it "should update all specified indexes" do
@job.indexes = ['foo_core', 'bar_core']

it "should update all specified indices" do
@job.indices = ['foo_core', 'bar_core']
@client.should_receive(:update).with('foo_core', anything, anything)
@client.should_receive(:update).with('bar_core', anything, anything)

@job.perform
end

it "should update the sphinx_deleted attribute" do
@client.should_receive(:update) do |index, attributes, values|
attributes.should == ['sphinx_deleted']
end

@job.perform
end

it "should set sphinx_deleted for the given document to true" do
@client.should_receive(:update) do |index, attributes, values|
values[12].should == [1]
end

@job.perform
end

it "should check for the existence of the document in the specified index" do
ThinkingSphinx.should_receive(:search_for_id) do |id, index|
index.should == 'foo_core'
end

@job.perform
end

it "should check for the existence of the given document id" do
ThinkingSphinx.should_receive(:search_for_id) do |id, index|
id.should == 12
end

@job.perform
end
end
Expand Down

0 comments on commit 8a3da35

Please sign in to comment.