supernova 0.4.13 → 0.4.14
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +22 -2
- data/VERSION +1 -1
- data/bin/start_solr +3 -1
- data/lib/supernova/solr_indexer.rb +13 -10
- data/spec/supernova/solr_indexer_spec.rb +43 -15
- data/supernova.gemspec +2 -2
- metadata +4 -4
data/README.rdoc
CHANGED
@@ -2,7 +2,27 @@
|
|
2
2
|
|
3
3
|
== Setup
|
4
4
|
|
5
|
-
|
5
|
+
=== Define Solr Index
|
6
|
+
|
7
|
+
class LocationIndex < Supernova::SolrIndexer
|
8
|
+
has :title, :type => :text
|
9
|
+
has :location, :type => :string
|
10
|
+
|
11
|
+
clazz Location
|
12
|
+
|
13
|
+
# is called before hash is added to index (with original database row)
|
14
|
+
# only called when defined
|
15
|
+
def before_index(row)
|
16
|
+
row.merge(:indexed_b => true)
|
17
|
+
end
|
18
|
+
|
19
|
+
# is called with a made up record of class defined with "clazz Location" and
|
20
|
+
# should return a hash which is merged into the original hash
|
21
|
+
# only called when method defined and clazz set
|
22
|
+
def extra_attributes_from_record(record)
|
23
|
+
{ :normalized_title_s => record.normalized_title }
|
24
|
+
end
|
25
|
+
end
|
6
26
|
|
7
27
|
=== Anonymous Scopes
|
8
28
|
|
@@ -36,7 +56,7 @@
|
|
36
56
|
Offer.search_scope.near(47.0, 11.0).within(100.meters)
|
37
57
|
Offer.search_scope.near(other_offer).within(100.meters)
|
38
58
|
|
39
|
-
== Contributing to
|
59
|
+
== Contributing to supernova
|
40
60
|
|
41
61
|
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
42
62
|
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.14
|
data/bin/start_solr
CHANGED
@@ -1,3 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
3
|
+
solr_home = File.expand_path("../solr", File.dirname(__FILE__))
|
4
|
+
cmd = %(cd /usr/local/Cellar/solr/3.1.0/libexec/example && java -Dsolr.solr.home=#{solr_home} -Djetty.port=8985 -jar start.jar > #{solr_home}/solr.log 2>&1 &)
|
5
|
+
exec cmd
|
@@ -71,9 +71,7 @@ class Supernova::SolrIndexer
|
|
71
71
|
end
|
72
72
|
|
73
73
|
def index!
|
74
|
-
index_query(query_to_index)
|
75
|
-
map_for_solr(row)
|
76
|
-
end
|
74
|
+
index_query(query_to_index)
|
77
75
|
end
|
78
76
|
|
79
77
|
def map_for_solr(row)
|
@@ -97,7 +95,8 @@ class Supernova::SolrIndexer
|
|
97
95
|
hash["indexed_at_dt"] = Time.now.utc.iso8601
|
98
96
|
hash["id_s"] = [self.class.table_name, hash["id"]].compact.join("/") if hash["id"]
|
99
97
|
self.class.field_definitions.each do |field, options|
|
100
|
-
if
|
98
|
+
if hash.has_key?(field.to_s)
|
99
|
+
value = hash.delete(field.to_s)
|
101
100
|
if options[:type] == :date
|
102
101
|
value = Time.utc(value.year, value.month, value.day) if value.is_a?(Date)
|
103
102
|
value = value.utc.iso8601
|
@@ -175,18 +174,23 @@ class Supernova::SolrIndexer
|
|
175
174
|
db.send(db.respond_to?(:query) ? :query : :select_all, query)
|
176
175
|
end
|
177
176
|
|
178
|
-
def
|
179
|
-
|
177
|
+
def solr_rows_to_index_for_query(query)
|
178
|
+
query_db(query).map do |row|
|
179
|
+
map_for_solr(row)
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
def index_query(query)
|
184
|
+
rows = solr_rows_to_index_for_query(query)
|
180
185
|
if self.max_rows_to_direct_index < rows.count
|
181
|
-
index_with_json_file(rows
|
186
|
+
index_with_json_file(rows)
|
182
187
|
else
|
183
|
-
index_directly(rows
|
188
|
+
index_directly(rows)
|
184
189
|
end
|
185
190
|
end
|
186
191
|
|
187
192
|
def index_directly(rows, &block)
|
188
193
|
rows.each do |row|
|
189
|
-
row = yield(row) if block_given?
|
190
194
|
row = Supernova::Solr.connection.add(row)
|
191
195
|
end
|
192
196
|
Supernova::Solr.connection.commit if rows.any?
|
@@ -194,7 +198,6 @@ class Supernova::SolrIndexer
|
|
194
198
|
|
195
199
|
def index_with_json_file(rows, &block)
|
196
200
|
rows.each do |row|
|
197
|
-
row = yield(row) if block_given?
|
198
201
|
write_to_file(row)
|
199
202
|
end
|
200
203
|
finish
|
@@ -25,6 +25,7 @@ describe Supernova::SolrIndexer do
|
|
25
25
|
indexer_clazz.has(:artist_id, :type => :integer)
|
26
26
|
indexer_clazz.has(:description, :type => :text)
|
27
27
|
indexer_clazz.has(:created_at, :type => :date)
|
28
|
+
indexer_clazz.has(:indexed, :type => :boolean, :virtual => true)
|
28
29
|
end
|
29
30
|
|
30
31
|
before(:each) do
|
@@ -69,16 +70,6 @@ describe Supernova::SolrIndexer do
|
|
69
70
|
indexer.should_receive(:index_query).with(query)
|
70
71
|
indexer.index!
|
71
72
|
end
|
72
|
-
|
73
|
-
it "calls map_for_solr with all returned rows from sql" do
|
74
|
-
row1 = double("row1")
|
75
|
-
row2 = double("row2")
|
76
|
-
indexer.stub!(:query).and_return [row1, row2]
|
77
|
-
indexer.stub!(:query_to_index).and_return "some query"
|
78
|
-
indexer.should_receive(:map_for_solr).with(row1)
|
79
|
-
indexer.stub!(:index_query).and_yield(row1)
|
80
|
-
indexer.index!
|
81
|
-
end
|
82
73
|
end
|
83
74
|
|
84
75
|
describe "#map_for_solr" do
|
@@ -211,6 +202,15 @@ describe Supernova::SolrIndexer do
|
|
211
202
|
has :lng, :type => :float
|
212
203
|
has :created_at, :type => :date
|
213
204
|
has :checkin_date, :type => :date
|
205
|
+
has :indexed, :type => :boolean, :virtual => true
|
206
|
+
end
|
207
|
+
|
208
|
+
it "maps virtual fields" do
|
209
|
+
CustomSolrIndex.new.map_hash_keys_to_solr("indexed" => true)["indexed_b"].should == true
|
210
|
+
end
|
211
|
+
|
212
|
+
it "maps fields with false as value" do
|
213
|
+
CustomSolrIndex.new.map_hash_keys_to_solr("indexed" => false)["indexed_b"].should == false
|
214
214
|
end
|
215
215
|
|
216
216
|
it "maps float fields" do
|
@@ -254,9 +254,37 @@ describe Supernova::SolrIndexer do
|
|
254
254
|
end
|
255
255
|
end
|
256
256
|
|
257
|
+
describe "#solr_rows_to_index_for_query" do
|
258
|
+
let(:result) {
|
259
|
+
[
|
260
|
+
{ "title" => "Some Title", "artist_id" => 10 }
|
261
|
+
]
|
262
|
+
}
|
263
|
+
|
264
|
+
{ "title_t" => "Some Title", "artist_id_i" => 10 }.each do |key, value|
|
265
|
+
it "sets #{key} to #{value}" do
|
266
|
+
custom_indexer.should_receive(:query_db).with("some query").and_return(result)
|
267
|
+
custom_indexer.solr_rows_to_index_for_query("some query").first[key].should == value
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
271
|
+
it "also maps virtual attributes" do
|
272
|
+
hash = { "indexed" => true }
|
273
|
+
query = "some query"
|
274
|
+
custom_indexer.should_receive(:query_db).with(query).and_return([hash])
|
275
|
+
custom_indexer.solr_rows_to_index_for_query(query).first["indexed_b"].should == true
|
276
|
+
end
|
277
|
+
end
|
278
|
+
|
257
279
|
describe "#index_query" do
|
258
280
|
let(:query) { %(SELECT CONCAT("user_", id) AS id, title FROM people WHERE type = 'User') }
|
259
281
|
|
282
|
+
it "calls solr_rows_to_index_for_query with query" do
|
283
|
+
result = []
|
284
|
+
indexer.should_receive(:solr_rows_to_index_for_query).with(query).and_return(result)
|
285
|
+
indexer.index_query(query)
|
286
|
+
end
|
287
|
+
|
260
288
|
it "calls index_with_json_file when rows > max_rows_to_direct_index" do
|
261
289
|
indexer.max_rows_to_direct_index = 0
|
262
290
|
rows = [to_index]
|
@@ -289,7 +317,7 @@ describe Supernova::SolrIndexer do
|
|
289
317
|
end
|
290
318
|
|
291
319
|
it "calls write_to_file on all rows" do
|
292
|
-
rows = [
|
320
|
+
rows = [{ "b" => 2 }, { "a" => 1 }]
|
293
321
|
indexer.stub(:query_db).and_return rows
|
294
322
|
indexer.should_receive(:write_to_file).with(rows.first)
|
295
323
|
indexer.should_receive(:write_to_file).with(rows.at(1))
|
@@ -327,8 +355,6 @@ describe Supernova::SolrIndexer do
|
|
327
355
|
solr.should_not_receive(:commit)
|
328
356
|
indexer.index_directly([])
|
329
357
|
end
|
330
|
-
|
331
|
-
it "calls a block given given"
|
332
358
|
end
|
333
359
|
|
334
360
|
describe "#index_file_path" do
|
@@ -625,7 +651,8 @@ describe Supernova::SolrIndexer do
|
|
625
651
|
|
626
652
|
it "adds the attribute_mapping" do
|
627
653
|
indexer_clazz.where(:a => 1).search_options[:attribute_mapping].should == {
|
628
|
-
:artist_id=>{:type=>:integer}, :title=>{:type=>:text}, :created_at=>{:type=>:date}, :description=>{:type=>:text}
|
654
|
+
:artist_id=>{:type=>:integer}, :title=>{:type=>:text}, :created_at=>{:type=>:date}, :description=>{:type=>:text},
|
655
|
+
:indexed => {:type => :boolean, :virtual => true }
|
629
656
|
}
|
630
657
|
end
|
631
658
|
end
|
@@ -636,7 +663,8 @@ describe Supernova::SolrIndexer do
|
|
636
663
|
where(:public => true)
|
637
664
|
end
|
638
665
|
indexer_clazz.published.search_options[:attribute_mapping].should == {
|
639
|
-
:artist_id=>{:type=>:integer}, :title=>{:type=>:text}, :created_at=>{:type=>:date}, :description=>{:type=>:text}
|
666
|
+
:artist_id=>{:type=>:integer}, :title=>{:type=>:text}, :created_at=>{:type=>:date}, :description=>{:type=>:text},
|
667
|
+
:indexed => {:type => :boolean, :virtual => true }
|
640
668
|
}
|
641
669
|
end
|
642
670
|
|
data/supernova.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{supernova}
|
8
|
-
s.version = "0.4.
|
8
|
+
s.version = "0.4.14"
|
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"]
|
12
|
-
s.date = %q{2011-07-
|
12
|
+
s.date = %q{2011-07-27}
|
13
13
|
s.description = %q{Unified search scopes}
|
14
14
|
s.email = %q{tobias.schwab@dynport.de}
|
15
15
|
s.executables = ["start_solr"]
|
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:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 4
|
9
|
-
-
|
10
|
-
version: 0.4.
|
9
|
+
- 14
|
10
|
+
version: 0.4.14
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Tobias Schwab
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-07-
|
18
|
+
date: 2011-07-27 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
requirement: &id001 !ruby/object:Gem::Requirement
|