sunspot_index_queue 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1 +1,4 @@
1
1
  pkg
2
+ rdoc
3
+ tmp
4
+ *.rbc
data/CHANGE_LOG.txt ADDED
@@ -0,0 +1,3 @@
1
+ 1.1.0
2
+
3
+ - Change column type for ActiveRecord and DataMapper implementation queue table for record_id from String to Integer. This makes it far more efficient in the normal case at the expense of being less flexible. If you do end up needing String record id's, just create the table definition yourself. To upgrade, you should clear the queue and then rerun the migration.
data/MIT_LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010 Brian Durand
1
+ Copyright (c) 2011 Brian Durand
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.rdoc CHANGED
@@ -59,6 +59,14 @@ The queue component is designed to be modular so that you can plugin a datastore
59
59
 
60
60
  # You can also provide your own queue implementation
61
61
  Sunspot::IndexQueue::Entry.implementation = MyQueueImplementation
62
+
63
+ You'll need to make sure you have the data structures set up properly for the implementation you choose. See the documentation for the implementations for more details
64
+
65
+ * Sunspot::IndexQueue::Entry::ActiveRecordImpl
66
+ * Sunspot::IndexQueue::Entry::DataMapperImpl
67
+ * Sunspot::IndexQueue::Entry::MongoImpl
68
+
69
+ Note that as of version 1.1.0 the data structure for the ActiveRecord and the DataMapper implementations assumes the primary key on the indexed records is an integer. This is done since it is the usual case and far more efficient that using a string index. If your records use a primary key that is not an integer, you'll need to add an additional migration to change the +record_id+ column type.
62
70
 
63
71
  === Process The Queue
64
72
 
data/Rakefile CHANGED
@@ -12,7 +12,7 @@ begin
12
12
  t.spec_files = FileList.new('spec/**/*_spec.rb')
13
13
  end
14
14
  rescue LoadError
15
- tast :test do
15
+ task :test do
16
16
  STDERR.puts "You must have rspec >= 1.3.0 to run the tests"
17
17
  end
18
18
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.1.0
@@ -14,6 +14,10 @@ module Sunspot
14
14
  # self.down
15
15
  # drop_table Sunspot::IndexQueue::Entry::ActiveRecordImpl.table_name
16
16
  # end
17
+ #
18
+ # The default set up is to use an integer for the +record_id+ column type since it
19
+ # is the most efficient and works with most data models. If you need to use a string
20
+ # as the primary key, you can add additional statements to the migration to do so.
17
21
  class ActiveRecordImpl < ActiveRecord::Base
18
22
  include Entry
19
23
 
@@ -96,7 +100,7 @@ module Sunspot
96
100
  def create_table
97
101
  connection.create_table table_name do |t|
98
102
  t.string :record_class_name, :null => false
99
- t.string :record_id, :null => false
103
+ t.integer :record_id, :null => false
100
104
  t.boolean :is_delete, :null => false, :default => false
101
105
  t.datetime :run_at, :null => false
102
106
  t.integer :priority, :null => false, :default => 0
@@ -105,7 +109,7 @@ module Sunspot
105
109
  t.integer :attempts, :null => false, :default => 0
106
110
  end
107
111
 
108
- connection.add_index table_name, [:record_class_name, :record_id], :name => "#{table_name}_record"
112
+ connection.add_index table_name, :record_id
109
113
  connection.add_index table_name, [:run_at, :record_class_name, :priority], :name => "#{table_name}_run_at"
110
114
  end
111
115
  end
@@ -4,17 +4,13 @@ require 'dm-aggregates'
4
4
  module Sunspot
5
5
  class IndexQueue
6
6
  module Entry
7
- # Implementation of an indexing queue backed by ActiveRecord.
7
+ # Implementation of an indexing queue backed by Datamapper.
8
8
  #
9
- # To create the table, you should have a migration containing the following:
9
+ # To create the table, you can use +dm-migrations+ and run +auto_migrate!+ on this class.
10
10
  #
11
- # self.up
12
- # Sunspot::IndexQueue::Entry::ActiveRecordImpl.create_table
13
- # end
14
- #
15
- # self.down
16
- # drop_table Sunspot::IndexQueue::Entry::ActiveRecordImpl.table_name
17
- # end
11
+ # This implementation assumes the primary key of the records being indexed in an integer
12
+ # since that works with most data models and is very efficient. If this is not the case,
13
+ # you can subclass this class and change the data type of the +record_id+ property.
18
14
  class DataMapperImpl
19
15
  include DataMapper::Resource
20
16
  include Entry
@@ -22,8 +18,8 @@ module Sunspot
22
18
  storage_names[:default] = "sunspot_index_queue_entries"
23
19
  property :id, Serial
24
20
  property :run_at, Time, :index => :run_at
25
- property :record_class_name, String, :index => [:record, :run_at]
26
- property :record_id, String, :index => [:record]
21
+ property :record_class_name, String, :index => :run_at
22
+ property :record_id, Integer, :index => :record_id
27
23
  property :priority, Integer, :default => 0, :index => :run_at
28
24
  property :is_delete, Boolean
29
25
  property :lock, Integer
@@ -5,20 +5,14 @@ require File.expand_path('../entry_impl_examples', __FILE__)
5
5
  describe Sunspot::IndexQueue::Entry::ActiveRecordImpl do
6
6
 
7
7
  before :all do
8
- db_dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'tmp'))
9
- Dir.mkdir(db_dir) unless File.exist?(db_dir)
10
- db = File.join(db_dir, 'sunspot_index_queue_test.sqlite3')
11
- ActiveRecord::Base.establish_connection("adapter" => "sqlite3", "database" => db)
8
+ ActiveRecord::Base.establish_connection("adapter" => "sqlite3", "database" => ":memory:")
12
9
  Sunspot::IndexQueue::Entry.implementation = :active_record
13
10
  Sunspot::IndexQueue::Entry::ActiveRecordImpl.create_table
14
11
  end
15
12
 
16
13
  after :all do
17
- db_dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'tmp'))
18
- db = File.join(db_dir, 'sunspot_index_queue_test.sqlite3')
14
+ Sunspot::IndexQueue::Entry::ActiveRecordImpl.connection.drop_table(Sunspot::IndexQueue::Entry::ActiveRecordImpl.table_name)
19
15
  ActiveRecord::Base.connection.disconnect!
20
- File.delete(db) if File.exist?(db)
21
- Dir.delete(db_dir) if File.exist?(db_dir) and Dir.entries(db_dir).reject{|f| f.match(/^\.+$/)}.empty?
22
16
  Sunspot::IndexQueue::Entry.implementation = nil
23
17
  end
24
18
 
@@ -11,13 +11,13 @@ shared_examples_for "Entry implementation" do
11
11
  context "class methods" do
12
12
  before :each do
13
13
  test_class = "Sunspot::IndexQueue::Test::Searchable"
14
- @entry_1 = factory.create('record_class_name' => test_class, 'record_id' => '1', 'is_delete' => false, 'priority' => 0, 'run_at' => Time.now.utc)
15
- @entry_2 = factory.create('record_class_name' => test_class, 'record_id' => '2', 'is_delete' => false, 'priority' => 10, 'run_at' => Time.now.utc, 'error' => "boom!", 'attempts' => 1)
16
- @entry_3 = factory.create('record_class_name' => "Object", 'record_id' => '3', 'is_delete' => false, 'priority' => 5, 'run_at' => Time.now.utc, 'error' => "boom!", 'attempts' => 1)
17
- @entry_4 = factory.create('record_class_name' => test_class, 'record_id' => '4', 'is_delete' => true, 'priority' => 0, 'run_at' => Time.now.utc + 60)
18
- @entry_5 = factory.create('record_class_name' => test_class, 'record_id' => '5', 'is_delete' => false, 'priority' => -10, 'run_at' => Time.now.utc - 60)
19
- @entry_6 = factory.create('record_class_name' => test_class, 'record_id' => '6', 'is_delete' => false, 'priority' => 0, 'run_at' => Time.now.utc - 3600)
20
- @entry_7 = factory.create('record_class_name' => test_class, 'record_id' => '7', 'is_delete' => true, 'priority' => 10, 'run_at' => Time.now.utc - 60)
14
+ @entry_1 = factory.create('record_class_name' => test_class, 'record_id' => 1, 'is_delete' => false, 'priority' => 0, 'run_at' => Time.now.utc)
15
+ @entry_2 = factory.create('record_class_name' => test_class, 'record_id' => 2, 'is_delete' => false, 'priority' => 10, 'run_at' => Time.now.utc, 'error' => "boom!", 'attempts' => 1)
16
+ @entry_3 = factory.create('record_class_name' => "Object", 'record_id' => 3, 'is_delete' => false, 'priority' => 5, 'run_at' => Time.now.utc, 'error' => "boom!", 'attempts' => 1)
17
+ @entry_4 = factory.create('record_class_name' => test_class, 'record_id' => 4, 'is_delete' => true, 'priority' => 0, 'run_at' => Time.now.utc + 60)
18
+ @entry_5 = factory.create('record_class_name' => test_class, 'record_id' => 5, 'is_delete' => false, 'priority' => -10, 'run_at' => Time.now.utc - 60)
19
+ @entry_6 = factory.create('record_class_name' => test_class, 'record_id' => 6, 'is_delete' => false, 'priority' => 0, 'run_at' => Time.now.utc - 3600)
20
+ @entry_7 = factory.create('record_class_name' => test_class, 'record_id' => 7, 'is_delete' => true, 'priority' => 10, 'run_at' => Time.now.utc - 60)
21
21
  end
22
22
 
23
23
  context "without class_names filter" do
@@ -40,7 +40,7 @@ shared_examples_for "Entry implementation" do
40
40
  errors.collect{|e| e.record_id}.sort.should == [@entry_2.record_id, @entry_3.record_id]
41
41
 
42
42
  errors = Sunspot::IndexQueue::Entry.implementation.errors(queue, 1, 1)
43
- errors.collect{|e| e.record_id}.sort.should == [@entry_3.record_id]
43
+ ([@entry_2.record_id, @entry_3.record_id] - errors.collect{|e| e.record_id}).size.should == 1
44
44
  end
45
45
 
46
46
  it "should reset all entries" do
@@ -107,10 +107,10 @@ shared_examples_for "Entry implementation" do
107
107
 
108
108
  context "add and remove" do
109
109
  it "should add an entry" do
110
- Sunspot::IndexQueue::Entry.implementation.add(Sunspot::IndexQueue::Test::Searchable, "10", false, 100)
110
+ Sunspot::IndexQueue::Entry.implementation.add(Sunspot::IndexQueue::Test::Searchable, 10, false, 100)
111
111
  entry = Sunspot::IndexQueue::Entry.implementation.next_batch!(Sunspot::IndexQueue.new).detect{|e| e.priority == 100}
112
112
  entry.record_class_name.should == "Sunspot::IndexQueue::Test::Searchable"
113
- entry.record_id.should == "10"
113
+ entry.record_id.should == 10
114
114
  entry.is_delete?.should == false
115
115
  entry.priority.should == 100
116
116
  end
@@ -123,14 +123,14 @@ shared_examples_for "Entry implementation" do
123
123
  end
124
124
 
125
125
  it "should not add multiple entries unless a row is being processed" do
126
- Sunspot::IndexQueue::Entry.implementation.add(Sunspot::IndexQueue::Test::Searchable, "10", false, 80)
126
+ Sunspot::IndexQueue::Entry.implementation.add(Sunspot::IndexQueue::Test::Searchable, 10, false, 80)
127
127
  Sunspot::IndexQueue::Entry.implementation.next_batch!(Sunspot::IndexQueue.new)
128
- Sunspot::IndexQueue::Entry.implementation.add(Sunspot::IndexQueue::Test::Searchable, "10", false, 100)
129
- Sunspot::IndexQueue::Entry.implementation.add(Sunspot::IndexQueue::Test::Searchable, "10", false, 110)
130
- Sunspot::IndexQueue::Entry.implementation.add(Sunspot::IndexQueue::Test::Searchable, "10", true, 90)
128
+ Sunspot::IndexQueue::Entry.implementation.add(Sunspot::IndexQueue::Test::Searchable, 10, false, 100)
129
+ Sunspot::IndexQueue::Entry.implementation.add(Sunspot::IndexQueue::Test::Searchable, 10, false, 110)
130
+ Sunspot::IndexQueue::Entry.implementation.add(Sunspot::IndexQueue::Test::Searchable, 10, true, 90)
131
131
  Sunspot::IndexQueue::Entry.implementation.reset!(Sunspot::IndexQueue.new)
132
132
  entries = Sunspot::IndexQueue::Entry.implementation.next_batch!(Sunspot::IndexQueue.new)
133
- entries.detect{|e| e.priority == 80}.record_id.should == "10"
133
+ entries.detect{|e| e.priority == 80}.record_id.should == 10
134
134
  entries.detect{|e| e.priority == 100}.should == nil
135
135
  entries.detect{|e| e.priority == 90}.should == nil
136
136
  entry = entries.detect{|e| e.priority == 110}
@@ -147,8 +147,8 @@ shared_examples_for "Entry implementation" do
147
147
  end
148
148
 
149
149
  it "should get the record_id" do
150
- entry = Sunspot::IndexQueue::Entry.implementation.new('record_id' => "1")
151
- entry.record_id.should == "1"
150
+ entry = Sunspot::IndexQueue::Entry.implementation.new('record_id' => 1)
151
+ entry.record_id.should == 1
152
152
  end
153
153
 
154
154
  it "should determine if the entry is an delete" do
data/spec/entry_spec.rb CHANGED
@@ -117,26 +117,26 @@ describe Sunspot::IndexQueue::Entry do
117
117
  entry_3 = Sunspot::IndexQueue::Entry.implementation.new(:record_class_name => "Sunspot::IndexQueue::Test::Searchable::Subclass", :record_id => 3)
118
118
  Sunspot::IndexQueue::Entry.load_all_records([entry_1, entry_2, entry_3])
119
119
  record_1 = entry_1.instance_variable_get(:@record)
120
- record_1.should == Sunspot::IndexQueue::Test::Searchable.new("1")
120
+ record_1.should == Sunspot::IndexQueue::Test::Searchable.new(1)
121
121
  entry_1.record.object_id.should == record_1.object_id
122
122
  record_2 = entry_2.instance_variable_get(:@record)
123
- record_2.should == Sunspot::IndexQueue::Test::Searchable.new("2")
123
+ record_2.should == Sunspot::IndexQueue::Test::Searchable.new(2)
124
124
  entry_2.record.object_id.should == record_2.object_id
125
125
  record_3 = entry_3.instance_variable_get(:@record)
126
- record_3.should == Sunspot::IndexQueue::Test::Searchable::Subclass.new("3")
126
+ record_3.should == Sunspot::IndexQueue::Test::Searchable::Subclass.new(3)
127
127
  entry_3.record.object_id.should == record_3.object_id
128
128
  end
129
129
  end
130
130
 
131
131
  context "instance methods" do
132
132
  it "should get a record for the entry using the Sunspot DataAccessor" do
133
- entry = Sunspot::IndexQueue::Entry::MockImpl.new(:record_class_name => "Sunspot::IndexQueue::Test::Searchable", :record_id => "1")
133
+ entry = Sunspot::IndexQueue::Entry::MockImpl.new(:record_class_name => "Sunspot::IndexQueue::Test::Searchable", :record_id => 1)
134
134
  entry.record.class.should == Sunspot::IndexQueue::Test::Searchable
135
- entry.record.id.should == "1"
135
+ entry.record.id.should == 1
136
136
  end
137
137
 
138
138
  it "should set if an entry has been processed" do
139
- entry = Sunspot::IndexQueue::Entry::MockImpl.new(:record_class_name => "Sunspot::IndexQueue::Test::Searchable", :record_id => "1")
139
+ entry = Sunspot::IndexQueue::Entry::MockImpl.new(:record_class_name => "Sunspot::IndexQueue::Test::Searchable", :record_id => 1)
140
140
  entry.processed?.should == false
141
141
  entry.processed = true
142
142
  entry.processed?.should == true
@@ -92,14 +92,14 @@ describe Sunspot::IndexQueue do
92
92
  let(:record_1) { Sunspot::IndexQueue::Test::Searchable.new(1) }
93
93
  let(:record_2) { Sunspot::IndexQueue::Test::Searchable.new(2) }
94
94
  let(:record_3) { Sunspot::IndexQueue::Test::Searchable.new(3) }
95
-
95
+
96
96
  it "should process all entries in the queue in batch of batch_size" do
97
97
  Sunspot::IndexQueue::Entry.should_receive(:next_batch!).with(queue).and_return([entry_1, entry_2], [entry_3], [])
98
98
  Sunspot::IndexQueue::Entry::MockImpl.should_receive(:ready_count).with(queue).and_return(0)
99
99
  queue.session.should_receive(:batch).twice.and_yield
100
- queue.session.should_receive(:remove_by_id).with("Sunspot::IndexQueue::Test::Searchable", "1")
101
- queue.session.should_receive(:remove_by_id).with("Sunspot::IndexQueue::Test::Searchable", "2")
102
- queue.session.should_receive(:remove_by_id).with("Sunspot::IndexQueue::Test::Searchable", "3")
100
+ queue.session.should_receive(:remove_by_id).with("Sunspot::IndexQueue::Test::Searchable", 1)
101
+ queue.session.should_receive(:remove_by_id).with("Sunspot::IndexQueue::Test::Searchable", 2)
102
+ queue.session.should_receive(:remove_by_id).with("Sunspot::IndexQueue::Test::Searchable", 3)
103
103
  queue.session.should_receive(:commit).twice
104
104
  Sunspot::IndexQueue::Entry::MockImpl.should_receive(:delete_entries).with([entry_1, entry_2])
105
105
  Sunspot::IndexQueue::Entry::MockImpl.should_receive(:delete_entries).with([entry_3])
@@ -110,9 +110,9 @@ describe Sunspot::IndexQueue do
110
110
  Sunspot::IndexQueue::Entry.should_receive(:next_batch!).with(queue).and_return([entry_1, entry_2], [entry_3], [])
111
111
  Sunspot::IndexQueue::Entry::MockImpl.should_receive(:ready_count).with(queue).and_return(0)
112
112
  queue.session.should_receive(:batch).twice.and_yield
113
- queue.session.should_receive(:remove_by_id).with("Sunspot::IndexQueue::Test::Searchable", "1")
114
- queue.session.should_receive(:remove_by_id).with("Sunspot::IndexQueue::Test::Searchable", "2")
115
- queue.session.should_receive(:remove_by_id).with("Sunspot::IndexQueue::Test::Searchable", "3")
113
+ queue.session.should_receive(:remove_by_id).with("Sunspot::IndexQueue::Test::Searchable", 1)
114
+ queue.session.should_receive(:remove_by_id).with("Sunspot::IndexQueue::Test::Searchable", 2)
115
+ queue.session.should_receive(:remove_by_id).with("Sunspot::IndexQueue::Test::Searchable", 3)
116
116
  queue.session.should_receive(:commit).twice
117
117
  Sunspot::IndexQueue::Entry::MockImpl.should_receive(:delete_entries).with([entry_1, entry_2])
118
118
  Sunspot::IndexQueue::Entry::MockImpl.should_receive(:delete_entries).with([entry_3])
@@ -3,12 +3,11 @@ require 'active_record'
3
3
 
4
4
  describe "Sunspot::IndexQueue integration tests" do
5
5
  before :all do
6
- db_dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'tmp'))
7
- Dir.mkdir(db_dir) unless File.exist?(db_dir)
8
- Dir.chdir(db_dir) do
9
- FileUtils.rm_rf('data') if File.exist?('data')
10
- Dir.mkdir('data')
11
- `sunspot-solr start --port=18983 --data-directory=data --pid-dir=data --log-file=data/solr.log --max-memory=64m`
6
+ data_dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'tmp'))
7
+ FileUtils.rm_rf(data_dir) if File.exist?(data_dir)
8
+ Dir.mkdir(data_dir)
9
+ Dir.chdir(data_dir) do
10
+ `sunspot-solr start --port=18983 --data-directory=. --pid-dir=. --log-file=./solr.log --max-memory=64m`
12
11
  raise "Failed to start Solr on port 18983" unless $? == 0
13
12
  # Wait until the server is responding
14
13
  ping_uri = URI.parse("http://127.0.0.1:18983/solr/ping")
@@ -24,10 +23,7 @@ describe "Sunspot::IndexQueue integration tests" do
24
23
  end
25
24
  raise "Solr failed to start after 10 seconds" unless solr_started
26
25
  end
27
-
28
- db = File.join(db_dir, 'sunspot_index_queue_test.sqlite3')
29
- File.delete(db) if File.exist?(db)
30
- ActiveRecord::Base.establish_connection("adapter" => "sqlite3", "database" => db)
26
+ ActiveRecord::Base.establish_connection("adapter" => "sqlite3", "database" => ":memory:")
31
27
  Sunspot::IndexQueue::Entry.implementation = :active_record
32
28
  Sunspot::IndexQueue::Entry::ActiveRecordImpl.create_table
33
29
 
@@ -37,16 +33,15 @@ describe "Sunspot::IndexQueue integration tests" do
37
33
  end
38
34
 
39
35
  after :all do
40
- db_dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'tmp'))
41
- Dir.chdir(db_dir) do
42
- `sunspot-solr stop --pid-dir=data`
36
+ data_dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'tmp'))
37
+ if File.exist?(data_dir)
38
+ Dir.chdir(data_dir) do
39
+ `sunspot-solr stop --pid-dir=.`
40
+ end
41
+ FileUtils.rm_rf(data_dir)
43
42
  end
44
- db = File.join(db_dir, 'sunspot_index_queue_test.sqlite3')
45
- data = File.join(db_dir, 'data')
46
- FileUtils.rm_rf(data) if File.exist?(data)
43
+ Sunspot::IndexQueue::Entry::ActiveRecordImpl.connection.drop_table(Sunspot::IndexQueue::Entry::ActiveRecordImpl.table_name)
47
44
  ActiveRecord::Base.connection.disconnect!
48
- File.delete(db) if File.exist?(db)
49
- Dir.delete(db_dir) if File.exist?(db_dir) and Dir.entries(db_dir).reject{|f| f.match(/^\.+$/)}.empty?
50
45
  Sunspot::IndexQueue::Entry.implementation = nil
51
46
  end
52
47
 
@@ -55,9 +50,9 @@ describe "Sunspot::IndexQueue integration tests" do
55
50
 
56
51
  it "should actually work" do
57
52
  Sunspot::IndexQueue::Test::Searchable.mock_db do
58
- record_1 = Sunspot::IndexQueue::Test::Searchable.new("1", "one")
59
- record_2 = Sunspot::IndexQueue::Test::Searchable.new("2", "two")
60
- record_3 = Sunspot::IndexQueue::Test::Searchable::Subclass.new("3", "three")
53
+ record_1 = Sunspot::IndexQueue::Test::Searchable.new(1, "one")
54
+ record_2 = Sunspot::IndexQueue::Test::Searchable.new(2, "two")
55
+ record_3 = Sunspot::IndexQueue::Test::Searchable::Subclass.new(3, "three")
61
56
  Sunspot::IndexQueue::Test::Searchable.save(record_1, record_2, record_3)
62
57
 
63
58
  # Enqueue records
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,23 @@
1
1
  require 'rubygems'
2
+
3
+ if ENV["ACTIVE_RECORD_VERSION"]
4
+ gem 'activerecord', ENV["ACTIVE_RECORD_VERSION"]
5
+ else
6
+ gem 'activerecord'
7
+ end
8
+
9
+ if ENV["DATA_MAPPER_VERSON"]
10
+ gem 'dm-core', ENV["DATA_MAPPER_VERSON"]
11
+ else
12
+ gem 'dm-core'
13
+ end
14
+
15
+ if ENV["SUNSPOT_VERSION"]
16
+ gem 'sunspot', ENV["SUNSPOT_VERSION"]
17
+ else
18
+ gem 'sunspot'
19
+ end
20
+
2
21
  require File.expand_path('../../lib/sunspot_index_queue', __FILE__)
3
22
 
4
23
  module Sunspot
@@ -24,7 +43,7 @@ module Sunspot
24
43
 
25
44
  def save (*objects)
26
45
  objects.each do |obj|
27
- db[obj.id] = obj.dup
46
+ db[obj.id.to_s] = obj.dup
28
47
  end
29
48
  end
30
49
  end
@@ -42,7 +61,11 @@ module Sunspot
42
61
 
43
62
  class DataAccessor < Sunspot::Adapters::DataAccessor
44
63
  def load (id)
45
- Searchable.db ? Searchable.db[id] : Searchable.new(id)
64
+ Searchable.db ? Searchable.db[id.to_s] : Searchable.new(id)
65
+ end
66
+
67
+ def load_all (ids)
68
+ ids.collect{|id| load(id)}.compact
46
69
  end
47
70
  end
48
71
 
@@ -55,7 +78,7 @@ module Sunspot
55
78
  class Subclass < Searchable
56
79
  end
57
80
  end
58
-
81
+
59
82
  Sunspot::Adapters::InstanceAdapter.register(Searchable::InstanceAdapter, Searchable)
60
83
  Sunspot::Adapters::DataAccessor.register(Searchable::DataAccessor, Searchable)
61
84
  Sunspot.setup(Searchable) do
@@ -72,10 +95,10 @@ module Sunspot
72
95
  def initialize (options = {})
73
96
  if options[:record]
74
97
  @record_class_name = options[:record].class.name
75
- @record_id = options[:record].id.to_s
98
+ @record_id = options[:record].id
76
99
  else
77
100
  @record_class_name = options[:record_class_name]
78
- @record_id = options[:record_id].to_s
101
+ @record_id = options[:record_id]
79
102
  end
80
103
  @is_delete = !!options[:delete]
81
104
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{sunspot_index_queue}
8
- s.version = "1.0.0"
8
+ s.version = "1.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Brian Durand"]
12
- s.date = %q{2010-06-22}
12
+ s.date = %q{2011-01-01}
13
13
  s.description = %q{This gem provides asynchronous indexing to Solr for the sunspot gem. It uses a pluggable model for the backing queue and provides support for ActiveRecord and MongoDB out of the box.}
14
14
  s.email = %q{brian@embellishedvisions.com}
15
15
  s.extra_rdoc_files = [
@@ -17,6 +17,7 @@ Gem::Specification.new do |s|
17
17
  ]
18
18
  s.files = [
19
19
  ".gitignore",
20
+ "CHANGE_LOG.txt",
20
21
  "MIT_LICENSE",
21
22
  "README.rdoc",
22
23
  "Rakefile",
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sunspot_index_queue
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
+ - 1
8
9
  - 0
9
- - 0
10
- version: 1.0.0
10
+ version: 1.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Brian Durand
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-06-22 00:00:00 -05:00
18
+ date: 2011-01-01 00:00:00 -06:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -165,6 +165,7 @@ extra_rdoc_files:
165
165
  - README.rdoc
166
166
  files:
167
167
  - .gitignore
168
+ - CHANGE_LOG.txt
168
169
  - MIT_LICENSE
169
170
  - README.rdoc
170
171
  - Rakefile