supernova 0.3.11 → 0.3.12

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.11
1
+ 0.3.12
@@ -146,24 +146,26 @@ class Supernova::SolrIndexer
146
146
  db.send(db.respond_to?(:query) ? :query : :select_all, query)
147
147
  end
148
148
 
149
- def index_query(query)
149
+ def index_query(query, &block)
150
150
  rows = query_db(query)
151
151
  if self.max_rows_to_direct_index < rows.count
152
- index_with_json_file(rows)
152
+ index_with_json_file(rows, &block)
153
153
  else
154
- index_directly(rows)
154
+ index_directly(rows, &block)
155
155
  end
156
156
  end
157
157
 
158
- def index_directly(rows)
158
+ def index_directly(rows, &block)
159
159
  rows.each do |row|
160
- Supernova::Solr.connection.add(row)
160
+ row = yield(row) if block_given?
161
+ row = Supernova::Solr.connection.add(row)
161
162
  end
162
163
  Supernova::Solr.connection.commit if rows.any?
163
164
  end
164
165
 
165
- def index_with_json_file(rows)
166
+ def index_with_json_file(rows, &block)
166
167
  rows.each do |row|
168
+ row = yield(row) if block_given?
167
169
  write_to_file(row)
168
170
  end
169
171
  finish
@@ -41,6 +41,11 @@ describe "Solr" do
41
41
  has :user_id, :type => :integer
42
42
  has :popularity, :type => :integer
43
43
 
44
+ def row_to_solr(row)
45
+ row["indexed_at_dt"] = Time.now.utc.iso8601
46
+ row
47
+ end
48
+
44
49
  clazz Offer
45
50
  end
46
51
 
@@ -49,6 +54,7 @@ describe "Solr" do
49
54
  offer2 = Offer.create!(:user_id => 2, :popularity => 20)
50
55
  indexer = OfferIndex.new(:db => ActiveRecord::Base.connection)
51
56
  indexer.index!
57
+ OfferIndex.search_scope.to_a.first.instance_variable_get("@solr_doc")["indexed_at_dt"].should_not be_nil
52
58
  OfferIndex.search_scope.to_a.total_entries.should == 2
53
59
  OfferIndex.search_scope.order("user_id desc").to_a.should == [offer2, offer1]
54
60
  indexer.instance_variable_get("@index_file_path").should be_nil
@@ -61,6 +67,7 @@ describe "Solr" do
61
67
  indexer.index!
62
68
  indexer.instance_variable_get("@index_file_path").should_not be_nil
63
69
  OfferIndex.search_scope.to_a.total_entries.should == 2
70
+ OfferIndex.search_scope.to_a.first.instance_variable_get("@solr_doc")["indexed_at_dt"].should_not be_nil
64
71
  OfferIndex.search_scope.order("user_id desc").to_a.should == [offer2, offer1]
65
72
  File.should_not be_exists(indexer.instance_variable_get("@index_file_path"))
66
73
  end
@@ -71,6 +78,7 @@ describe "Solr" do
71
78
  indexer = OfferIndex.new(:db => ActiveRecord::Base.connection, :max_rows_to_direct_index => 0, :local_solr => true)
72
79
  indexer.index!
73
80
  indexer.instance_variable_get("@index_file_path").should_not be_nil
81
+ OfferIndex.search_scope.to_a.first.instance_variable_get("@solr_doc")["indexed_at_dt"].should_not be_nil
74
82
  OfferIndex.search_scope.to_a.total_entries.should == 2
75
83
  OfferIndex.search_scope.order("user_id desc").to_a.should == [offer2, offer1]
76
84
  File.should_not be_exists(indexer.instance_variable_get("@index_file_path"))
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{supernova}
8
- s.version = "0.3.11"
8
+ s.version = "0.3.12"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Tobias Schwab"]
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: supernova
3
3
  version: !ruby/object:Gem::Version
4
- hash: 5
4
+ hash: 11
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 11
10
- version: 0.3.11
9
+ - 12
10
+ version: 0.3.12
11
11
  platform: ruby
12
12
  authors:
13
13
  - Tobias Schwab