solrizer 3.2.0 → 3.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.txt +6 -0
- data/lib/solrizer.rb +44 -38
- data/lib/solrizer/extractor.rb +28 -27
- data/lib/solrizer/field_mapper.rb +1 -4
- data/lib/solrizer/version.rb +1 -1
- data/solrizer.gemspec +0 -1
- data/spec/units/common_spec.rb +7 -10
- data/spec/units/extractor_spec.rb +7 -7
- data/spec/units/field_mapper_spec.rb +47 -47
- data/spec/units/solrizer_spec.rb +17 -17
- data/spec/units/xml_extractor_spec.rb +10 -10
- metadata +2 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fdbccd31fa681a9b641d09d28db5f2658cc19c4d
|
4
|
+
data.tar.gz: 8b3f8f8fd164e2d9720c5bbcad56b3948ef7ffad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c2e433d14eefcbdc9f5c04aefbfaaf3a533f7cb7a8dc896b2096e0c9e9d5dfa42b659af1f66d075c7801341db15adff967900c7c09bf381e1c927a826c4f1426
|
7
|
+
data.tar.gz: 26a18f117e4c1e75192b14c926d7485611c4c148a751488530c75a81d7e1ae2af16619a2337d5f55a0771cb91a83ccc02863cf86d7ec0b18acb5785597935d24
|
data/History.txt
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
h2. 3.3.0
|
2
|
+
* 2014-07-17: Remove dependency on mediashelf-loggable [Justin Coyne]
|
3
|
+
* 2014-07-17: Fix rspec deprecations [Justin Coyne]
|
4
|
+
* 2014-06-04: Refactor format_node_value so we don't need to check responds_to? [Justin Coyne]
|
5
|
+
|
6
|
+
[Justin Coyne]
|
1
7
|
h2. 3.2.0
|
2
8
|
#25 Allow any field_value except nil to be inserted into a solr field
|
3
9
|
#24 Remove dependency on solrizer-fedora, use AF to update index by pid
|
data/lib/solrizer.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
require 'active_support'
|
2
|
+
require 'active_support/core_ext/module/attribute_accessors'
|
3
|
+
|
2
4
|
module Solrizer
|
3
5
|
extend ActiveSupport::Autoload
|
4
6
|
|
@@ -12,51 +14,55 @@ module Solrizer
|
|
12
14
|
autoload :VERSION, 'solrizer/version'
|
13
15
|
autoload :XML, 'solrizer/xml'
|
14
16
|
|
15
|
-
|
16
|
-
Solrizer::VERSION
|
17
|
-
end
|
17
|
+
mattr_accessor :logger, instance_writer: false
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
class << self
|
20
|
+
def version
|
21
|
+
Solrizer::VERSION
|
22
|
+
end
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
24
|
+
def default_field_mapper
|
25
|
+
@@default_field_mapper ||= Solrizer::FieldMapper.new
|
26
|
+
end
|
26
27
|
|
28
|
+
def default_field_mapper=(field_mapper)
|
29
|
+
@@default_field_mapper = field_mapper
|
30
|
+
end
|
27
31
|
|
28
|
-
def self.solr_name(*args)
|
29
|
-
default_field_mapper.solr_name(*args)
|
30
|
-
end
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
#
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
doc[k]
|
33
|
+
def solr_name(*args)
|
34
|
+
default_field_mapper.solr_name(*args)
|
35
|
+
end
|
36
|
+
|
37
|
+
# @params [Hash] doc the hash to insert the value into
|
38
|
+
# @params [String] name the name of the field (without the suffix)
|
39
|
+
# @params [String,Date,Array] value the value (or array of values) to be inserted
|
40
|
+
# @params [Array,Hash] indexer_args the arguments that find the indexer
|
41
|
+
# @returns [Hash] doc the document that was provided with the new field inserted
|
42
|
+
def insert_field(doc, name, value, *indexer_args)
|
43
|
+
# adding defaults indexer
|
44
|
+
indexer_args = [:stored_searchable] if indexer_args.empty?
|
45
|
+
default_field_mapper.solr_names_and_values(name, value, indexer_args).each do |k, v|
|
46
|
+
doc[k] ||= []
|
47
|
+
if v.is_a? Array
|
48
|
+
doc[k] += v
|
49
|
+
else
|
50
|
+
doc[k] = v
|
51
|
+
end
|
46
52
|
end
|
53
|
+
doc
|
47
54
|
end
|
48
|
-
doc
|
49
|
-
end
|
50
55
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
56
|
+
# @params [Hash] doc the hash to insert the value into
|
57
|
+
# @params [String] name the name of the field (without the suffix)
|
58
|
+
# @params [String,Date] value the value to be inserted
|
59
|
+
# @params [Array,Hash] indexer_args the arguments that find the indexer
|
60
|
+
# @returns [Hash] doc the document that was provided with the new field (replacing any field with the same name)
|
61
|
+
def set_field(doc, name, value, *indexer_args)
|
62
|
+
# adding defaults indexer
|
63
|
+
indexer_args = [:stored_searchable] if indexer_args.empty?
|
64
|
+
doc.merge! default_field_mapper.solr_names_and_values(name, value, indexer_args)
|
65
|
+
doc
|
66
|
+
end
|
61
67
|
end
|
62
68
|
end
|
data/lib/solrizer/extractor.rb
CHANGED
@@ -9,34 +9,35 @@ module Solrizer
|
|
9
9
|
#
|
10
10
|
class Extractor
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
12
|
+
class << self
|
13
|
+
# Insert +field_value+ for +field_name+ into +solr_doc+
|
14
|
+
# Handles inserting new values into a Hash while ensuring that you don't destroy or overwrite any existing values in the hash.
|
15
|
+
# Ensures that field values are always appended to arrays within the values hash.
|
16
|
+
# Also ensures that values are run through format_node_value
|
17
|
+
# @param [Hash] solr_doc
|
18
|
+
# @param [String] field_name
|
19
|
+
# @param [String] field_value
|
20
|
+
def insert_solr_field_value(solr_doc, field_name, field_value)
|
21
|
+
formatted_value = format_node_value(field_value)
|
22
|
+
if solr_doc[field_name]
|
23
|
+
solr_doc[field_name] = Array(solr_doc[field_name]) << formatted_value
|
24
|
+
else
|
25
|
+
solr_doc[field_name] = formatted_value
|
26
|
+
end
|
27
|
+
return solr_doc
|
25
28
|
end
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
values = [values] unless values.respond_to? :map
|
39
|
-
return values.map{|val| val.gsub(/\s+/,' ').strip}.join(" ")
|
29
|
+
|
30
|
+
# Strips the majority of whitespace from the values array and then joins them with a single blank delimitter
|
31
|
+
# Returns an empty string if values argument is nil
|
32
|
+
#
|
33
|
+
# @param [Array] values Array of strings representing the values to be formatted
|
34
|
+
# @return [String]
|
35
|
+
def format_node_value values
|
36
|
+
if values.nil?
|
37
|
+
""
|
38
|
+
else
|
39
|
+
Array(values).map{|val| val.gsub(/\s+/,' ').strip}.join(" ")
|
40
|
+
end
|
40
41
|
end
|
41
42
|
end
|
42
43
|
|
@@ -1,4 +1,3 @@
|
|
1
|
-
require "loggable"
|
2
1
|
require 'active_support/core_ext/class/attribute'
|
3
2
|
require 'active_support/core_ext/string/inflections'
|
4
3
|
module Solrizer
|
@@ -100,8 +99,6 @@ module Solrizer
|
|
100
99
|
|
101
100
|
class FieldMapper
|
102
101
|
|
103
|
-
include Loggable
|
104
|
-
|
105
102
|
# ------ Instance methods ------
|
106
103
|
|
107
104
|
attr_reader :id_field, :default_index_types
|
@@ -228,7 +225,7 @@ module Solrizer
|
|
228
225
|
values = (results[name] ||= [])
|
229
226
|
values << value unless value.nil? || values.include?(value)
|
230
227
|
else
|
231
|
-
logger.warn "Setting #{name} to `#{value}', but it already had `#{results[name]}'" if results[name]
|
228
|
+
Solrizer.logger.warn "Setting #{name} to `#{value}', but it already had `#{results[name]}'" if results[name] && Solrizer.logger
|
232
229
|
results[name] = value
|
233
230
|
end
|
234
231
|
end
|
data/lib/solrizer/version.rb
CHANGED
data/solrizer.gemspec
CHANGED
data/spec/units/common_spec.rb
CHANGED
@@ -10,33 +10,30 @@ describe Solrizer::Common do
|
|
10
10
|
Object.send(:remove_const, :Foo)
|
11
11
|
end
|
12
12
|
|
13
|
+
let(:solr_doc) { {} }
|
14
|
+
|
13
15
|
it "should handle many field types" do
|
14
|
-
solr_doc = {}
|
15
16
|
Foo.create_and_insert_terms('my_name', 'value', [:displayable, :searchable, :sortable], solr_doc)
|
16
|
-
solr_doc.
|
17
|
+
expect(solr_doc).to eq('my_name_ssm' => ['value'], 'my_name_si' => 'value', 'my_name_teim' => ['value'])
|
17
18
|
end
|
18
19
|
|
19
20
|
it "should handle dates that are searchable" do
|
20
|
-
solr_doc = {}
|
21
21
|
Foo.create_and_insert_terms('my_name', Date.parse('2013-01-10'), [:stored_searchable], solr_doc)
|
22
|
-
solr_doc.
|
22
|
+
expect(solr_doc).to eq('my_name_dtsim' => ['2013-01-10T00:00:00Z'])
|
23
23
|
end
|
24
24
|
|
25
25
|
it "should handle dates that are stored_sortable" do
|
26
|
-
solr_doc = {}
|
27
26
|
Foo.create_and_insert_terms('my_name', Date.parse('2013-01-10'), [:stored_sortable], solr_doc)
|
28
|
-
solr_doc.
|
27
|
+
expect(solr_doc).to eq('my_name_dtsi' => '2013-01-10T00:00:00Z')
|
29
28
|
end
|
30
29
|
|
31
30
|
it "should handle dates that are displayable" do
|
32
|
-
solr_doc = {}
|
33
31
|
Foo.create_and_insert_terms('my_name', Date.parse('2013-01-10'), [:displayable], solr_doc)
|
34
|
-
solr_doc.
|
32
|
+
expect(solr_doc).to eq('my_name_ssm' => ['2013-01-10'])
|
35
33
|
end
|
36
34
|
|
37
35
|
it "should handle dates that are sortable" do
|
38
|
-
solr_doc = {}
|
39
36
|
Foo.create_and_insert_terms('my_name', Date.parse('2013-01-10'), [:sortable], solr_doc)
|
40
|
-
solr_doc.
|
37
|
+
expect(solr_doc).to eq('my_name_dti' => '2013-01-10T00:00:00Z')
|
41
38
|
end
|
42
39
|
end
|
@@ -8,15 +8,15 @@ describe Solrizer::Extractor do
|
|
8
8
|
|
9
9
|
describe ".format_node_value" do
|
10
10
|
it "should strip white space out of the array and join it with a single blank" do
|
11
|
-
Solrizer::Extractor.format_node_value([" test \n node \t value \t"]).
|
12
|
-
Solrizer::Extractor.format_node_value([" test ", " \n node ", " \t value \t"]).
|
11
|
+
expect(Solrizer::Extractor.format_node_value([" test \n node \t value \t"])).to eq "test node value"
|
12
|
+
expect(Solrizer::Extractor.format_node_value([" test ", " \n node ", " \t value \t"])).to eq "test node value"
|
13
13
|
end
|
14
14
|
it "should return an empty string if given an argument of nil" do
|
15
|
-
Solrizer::Extractor.format_node_value(nil).
|
15
|
+
expect(Solrizer::Extractor.format_node_value(nil)).to eq ''
|
16
16
|
end
|
17
17
|
|
18
18
|
it "should strip white space out of a string" do
|
19
|
-
Solrizer::Extractor.format_node_value("raw string\n with whitespace").
|
19
|
+
expect(Solrizer::Extractor.format_node_value("raw string\n with whitespace")).to eq "raw string with whitespace"
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
@@ -24,19 +24,19 @@ describe Solrizer::Extractor do
|
|
24
24
|
it "should initialize a solr doc list if it is nil" do
|
25
25
|
solr_doc = {'title_tesim' => nil }
|
26
26
|
Solrizer::Extractor.insert_solr_field_value(solr_doc, 'title_tesim', 'Frank')
|
27
|
-
solr_doc.
|
27
|
+
expect(solr_doc).to eq("title_tesim"=>"Frank")
|
28
28
|
end
|
29
29
|
it "should insert multiple" do
|
30
30
|
solr_doc = {'title_tesim' => nil }
|
31
31
|
Solrizer::Extractor.insert_solr_field_value(solr_doc, 'title_tesim', 'Frank')
|
32
32
|
Solrizer::Extractor.insert_solr_field_value(solr_doc, 'title_tesim', 'Margret')
|
33
33
|
Solrizer::Extractor.insert_solr_field_value(solr_doc, 'title_tesim', 'Joyce')
|
34
|
-
solr_doc.
|
34
|
+
expect(solr_doc).to eq("title_tesim"=>["Frank", 'Margret', 'Joyce'])
|
35
35
|
end
|
36
36
|
it "should not make a list if a single valued field is passed in" do
|
37
37
|
solr_doc = {}
|
38
38
|
Solrizer::Extractor.insert_solr_field_value(solr_doc, 'title_dtsi', '2013-03-22T12:33:00Z')
|
39
|
-
solr_doc.
|
39
|
+
expect(solr_doc).to eq("title_dtsi"=>"2013-03-22T12:33:00Z")
|
40
40
|
end
|
41
41
|
|
42
42
|
end
|
@@ -148,100 +148,100 @@ describe Solrizer::FieldMapper do
|
|
148
148
|
# --- Tests ----
|
149
149
|
|
150
150
|
it "should handle the id field" do
|
151
|
-
@mapper.id_field.
|
151
|
+
expect(@mapper.id_field).to eq 'ident'
|
152
152
|
end
|
153
153
|
|
154
154
|
|
155
155
|
describe "extract_type" do
|
156
156
|
it "should map objects to symbols" do
|
157
|
-
@mapper.extract_type(7).
|
158
|
-
@mapper.extract_type(nil).
|
159
|
-
@mapper.extract_type(Date.today).
|
160
|
-
@mapper.extract_type(Time.now).
|
161
|
-
@mapper.extract_type(DateTime.now).
|
162
|
-
@mapper.extract_type("Hi").
|
157
|
+
expect(@mapper.extract_type(7)).to eq :integer
|
158
|
+
expect(@mapper.extract_type(nil)).to eq nil
|
159
|
+
expect(@mapper.extract_type(Date.today)).to eq :date
|
160
|
+
expect(@mapper.extract_type(Time.now)).to eq :time
|
161
|
+
expect(@mapper.extract_type(DateTime.now)).to eq :time
|
162
|
+
expect(@mapper.extract_type("Hi")).to eq :string
|
163
163
|
end
|
164
164
|
end
|
165
165
|
|
166
166
|
describe '.solr_name' do
|
167
167
|
it "should map based on passed descriptors" do
|
168
|
-
@mapper.solr_name('bar', :edible).
|
169
|
-
@mapper.solr_name('bar', :laughable, type: :string).
|
168
|
+
expect(@mapper.solr_name('bar', :edible)).to eq 'bar_food'
|
169
|
+
expect(@mapper.solr_name('bar', :laughable, type: :string)).to eq 'bar_haha'
|
170
170
|
end
|
171
171
|
|
172
172
|
it "should default the index_type to :stored_searchable" do
|
173
|
-
@mapper.solr_name('foo').
|
173
|
+
expect(@mapper.solr_name('foo')).to eq 'foo_s'
|
174
174
|
end
|
175
175
|
|
176
176
|
it "should allow you to pass a string as the suffix" do
|
177
|
-
@mapper.solr_name('bar', 'quack').
|
177
|
+
expect(@mapper.solr_name('bar', 'quack')).to eq 'bar_quack'
|
178
178
|
end
|
179
179
|
|
180
180
|
it "should map based on data type" do
|
181
|
-
@mapper.solr_name('foo', :fungible, type: :integer).
|
182
|
-
@mapper.solr_name('foo', :fungible, type: :garble).
|
183
|
-
@mapper.solr_name('foo', :fungible, type: :date).
|
181
|
+
expect(@mapper.solr_name('foo', :fungible, type: :integer)).to eq 'foo_f1'
|
182
|
+
expect(@mapper.solr_name('foo', :fungible, type: :garble)).to eq 'foo_f2' # based on type.default
|
183
|
+
expect(@mapper.solr_name('foo', :fungible, type: :date)).to eq 'foo_f0' # type.date falls through to container
|
184
184
|
end
|
185
185
|
|
186
186
|
it "should return nil for an unknown index types" do
|
187
|
-
|
187
|
+
expect {
|
188
188
|
@mapper.solr_name('foo', :blargle)
|
189
|
-
}.
|
189
|
+
}.to raise_error(Solrizer::UnknownIndexMacro, "Unable to find `blargle' in [TestMapper0::Descriptors0, Solrizer::DefaultDescriptors]")
|
190
190
|
end
|
191
191
|
|
192
192
|
it "should allow subclasses to selectively override suffixes" do
|
193
193
|
@mapper = TestMapper1.new
|
194
|
-
@mapper.solr_name('foo', type: :date).
|
195
|
-
@mapper.solr_name('foo', type: :string).
|
196
|
-
@mapper.solr_name('foo', :fungible, type: :integer).
|
197
|
-
@mapper.solr_name('foo', :fungible, type: :garble).
|
198
|
-
@mapper.solr_name('foo', :fungible, type: :fratz).
|
199
|
-
@mapper.solr_name('foo', :fungible, type: :date).
|
194
|
+
expect(@mapper.solr_name('foo', type: :date)).to eq 'foo_s'
|
195
|
+
expect(@mapper.solr_name('foo', type: :string)).to eq 'foo_s'
|
196
|
+
expect(@mapper.solr_name('foo', :fungible, type: :integer)).to eq 'foo_f5' # override on data type
|
197
|
+
expect(@mapper.solr_name('foo', :fungible, type: :garble)).to eq 'foo_f4' # override on data type
|
198
|
+
expect(@mapper.solr_name('foo', :fungible, type: :fratz)).to eq 'foo_f2' # from super
|
199
|
+
expect(@mapper.solr_name('foo', :fungible, type: :date)).to eq 'foo_f0' # super definition picks up override on index type
|
200
200
|
end
|
201
201
|
|
202
202
|
|
203
203
|
it "should raise an error when field_type is nil" do
|
204
204
|
mapper = Solrizer::FieldMapper.new
|
205
|
-
|
205
|
+
expect { mapper.solr_name(:heifer, nil, :searchable) }.to raise_error Solrizer::InvalidIndexDescriptor
|
206
206
|
end
|
207
207
|
end
|
208
208
|
|
209
209
|
describe '.solr_names_and_values' do
|
210
210
|
it "should map values based on passed descriptors" do
|
211
|
-
@mapper.solr_names_and_values('foo', 'bar', [:stored_searchable, :laughable, :edible]).
|
211
|
+
expect(@mapper.solr_names_and_values('foo', 'bar', [:stored_searchable, :laughable, :edible])).to eq(
|
212
212
|
'foo_s' => ['bar'],
|
213
213
|
'foo_food' => ['bar'],
|
214
214
|
'foo_haha' => ["Knock knock. Who's there? Bar. Bar who?"]
|
215
|
-
|
215
|
+
)
|
216
216
|
end
|
217
217
|
|
218
218
|
it "should apply mappings based on data type" do
|
219
|
-
@mapper.solr_names_and_values('foo', 7, [:stored_searchable, :laughable]).
|
219
|
+
expect(@mapper.solr_names_and_values('foo', 7, [:stored_searchable, :laughable])).to eq(
|
220
220
|
'foo_s' => ['7'],
|
221
221
|
'foo_ihaha' => ["How many foos does it take to screw in a light bulb? 7."]
|
222
|
-
|
222
|
+
)
|
223
223
|
end
|
224
224
|
|
225
225
|
it "should raise error on unknown index types" do
|
226
|
-
|
226
|
+
expect {
|
227
227
|
@mapper.solr_names_and_values('foo', 'bar', [:blargle])
|
228
|
-
}.
|
228
|
+
}.to raise_error(Solrizer::UnknownIndexMacro, "Unable to find `blargle' in [TestMapper0::Descriptors0, Solrizer::DefaultDescriptors]")
|
229
229
|
end
|
230
230
|
|
231
231
|
it "should generate multiple mappings when two return the _same_ solr name but _different_ values" do
|
232
|
-
@mapper.solr_names_and_values('roll', 'rock', [:unstemmed_searchable, :stored_searchable]).
|
232
|
+
expect(@mapper.solr_names_and_values('roll', 'rock', [:unstemmed_searchable, :stored_searchable])).to eq(
|
233
233
|
'roll_s' => ["rock o'clock", 'rock']
|
234
|
-
|
234
|
+
)
|
235
235
|
end
|
236
236
|
|
237
237
|
it "should not generate multiple mappings when two return the _same_ solr name and the _same_ value" do
|
238
|
-
@mapper.solr_names_and_values('roll', 'rock', [:another_stored_searchable, :stored_searchable]).
|
238
|
+
expect(@mapper.solr_names_and_values('roll', 'rock', [:another_stored_searchable, :stored_searchable])).to eq(
|
239
239
|
'roll_s' => ['rock'],
|
240
|
-
|
240
|
+
)
|
241
241
|
end
|
242
242
|
|
243
243
|
it "should return an empty hash when value is nil" do
|
244
|
-
@mapper.solr_names_and_values('roll', nil, [:another_stored_searchable, :stored_searchable]).
|
244
|
+
expect(@mapper.solr_names_and_values('roll', nil, [:another_stored_searchable, :stored_searchable])).to eq({ })
|
245
245
|
end
|
246
246
|
end
|
247
247
|
|
@@ -251,33 +251,33 @@ describe Solrizer::FieldMapper do
|
|
251
251
|
end
|
252
252
|
|
253
253
|
it "should call the id field 'id'" do
|
254
|
-
@mapper.id_field.
|
254
|
+
expect(@mapper.id_field).to eq 'id'
|
255
255
|
end
|
256
256
|
|
257
257
|
it "should default the index_type to :stored_searchable" do
|
258
|
-
@mapper.solr_name('foo', :type=>:string).
|
258
|
+
expect(@mapper.solr_name('foo', :type=>:string)).to eq 'foo_tesim'
|
259
259
|
end
|
260
260
|
|
261
261
|
it "should support field names as symbols" do
|
262
|
-
@mapper.solr_name(:active_fedora_model, :symbol).
|
262
|
+
expect(@mapper.solr_name(:active_fedora_model, :symbol)).to eq "active_fedora_model_ssim"
|
263
263
|
end
|
264
264
|
|
265
265
|
it "should not apply mappings for searchable by default" do
|
266
266
|
# Just sanity check a couple; copy & pasting all data types is silly
|
267
|
-
@mapper.solr_names_and_values('foo', 'bar', []).
|
268
|
-
@mapper.solr_names_and_values('foo', "1",[]).
|
267
|
+
expect(@mapper.solr_names_and_values('foo', 'bar', [])).to eq({ })
|
268
|
+
expect(@mapper.solr_names_and_values('foo', "1",[])).to eq({ })
|
269
269
|
end
|
270
270
|
|
271
271
|
it "should support full ISO 8601 dates" do
|
272
|
-
@mapper.solr_names_and_values('foo', "2012-11-06", [:dateable]).
|
273
|
-
@mapper.solr_names_and_values('foo', "November 6th, 2012", [:dateable]).
|
274
|
-
@mapper.solr_names_and_values('foo', "6 Nov. 2012", [:dateable]).
|
275
|
-
@mapper.solr_names_and_values('foo', '', [:dateable]).
|
272
|
+
expect(@mapper.solr_names_and_values('foo', "2012-11-06", [:dateable])).to eq('foo_dtsim' =>["2012-11-06T00:00:00Z"])
|
273
|
+
expect(@mapper.solr_names_and_values('foo', "November 6th, 2012", [:dateable])).to eq('foo_dtsim' =>["2012-11-06T00:00:00Z"])
|
274
|
+
expect(@mapper.solr_names_and_values('foo', "6 Nov. 2012", [:dateable])).to eq('foo_dtsim' =>["2012-11-06T00:00:00Z"])
|
275
|
+
expect(@mapper.solr_names_and_values('foo', '', [:dateable])).to eq('foo_dtsim' => [])
|
276
276
|
end
|
277
277
|
|
278
278
|
it "should support searchable, stored_searchable, displayable, facetable, sortable, stored_sortable, unstemmed" do
|
279
279
|
descriptors = [:searchable, :stored_searchable, :displayable, :facetable, :sortable, :stored_sortable, :unstemmed_searchable]
|
280
|
-
@mapper.solr_names_and_values('foo', 'bar', descriptors).
|
280
|
+
expect(@mapper.solr_names_and_values('foo', 'bar', descriptors)).to eq(
|
281
281
|
"foo_teim" => ["bar"], #searchable
|
282
282
|
"foo_tesim" => ["bar"], #stored_searchable
|
283
283
|
"foo_ssm" => ["bar"], #displayable
|
@@ -285,13 +285,13 @@ describe Solrizer::FieldMapper do
|
|
285
285
|
"foo_si" => "bar", #sortable
|
286
286
|
"foo_ssi" => "bar", #stored_sortable
|
287
287
|
"foo_tim" => ["bar"] #unstemmed_searchable
|
288
|
-
|
288
|
+
)
|
289
289
|
end
|
290
290
|
|
291
291
|
it "should support stored_sortable" do
|
292
292
|
time = Time.iso8601("2012-11-06T15:16:17Z")
|
293
|
-
@mapper.solr_names_and_values('foo', time, :stored_sortable).
|
294
|
-
@mapper.solr_names_and_values('foo', 'bar', :stored_sortable).
|
293
|
+
expect(@mapper.solr_names_and_values('foo', time, :stored_sortable)).to eq("foo_dtsi" => "2012-11-06T15:16:17Z")
|
294
|
+
expect(@mapper.solr_names_and_values('foo', 'bar', :stored_sortable)).to eq("foo_ssi" => "bar")
|
295
295
|
end
|
296
296
|
end
|
297
297
|
end
|
data/spec/units/solrizer_spec.rb
CHANGED
@@ -7,68 +7,68 @@ describe Solrizer do
|
|
7
7
|
let(:doc) { Hash.new }
|
8
8
|
it "should insert a field with the default (stored_searchable) indexer" do
|
9
9
|
Solrizer.insert_field(doc, 'foo', 'A name')
|
10
|
-
doc.
|
10
|
+
expect(doc).to eq('foo_tesim' => ['A name'])
|
11
11
|
end
|
12
12
|
it "should not create an array of fields that are not multivalued" do
|
13
13
|
Solrizer.insert_field(doc, 'foo', 'A name', :sortable)
|
14
|
-
doc.
|
14
|
+
expect(doc).to eq('foo_si' => 'A name')
|
15
15
|
end
|
16
16
|
it "should insert a field with multiple indexers" do
|
17
17
|
Solrizer.insert_field(doc, 'foo', 'A name', :sortable, :facetable)
|
18
|
-
doc.
|
18
|
+
expect(doc).to eq('foo_si' => 'A name', 'foo_sim' => ['A name'])
|
19
19
|
end
|
20
20
|
it "should insert Dates" do
|
21
21
|
Solrizer.insert_field(doc, 'foo', Date.parse('2013-01-13'))
|
22
|
-
doc.
|
22
|
+
expect(doc).to eq('foo_dtsim' => ["2013-01-13T00:00:00Z"])
|
23
23
|
end
|
24
24
|
it "should insert Times" do
|
25
25
|
Solrizer.insert_field(doc, 'foo', Time.parse('2013-01-13T22:45:56+06:00'))
|
26
|
-
doc.
|
26
|
+
expect(doc).to eq('foo_dtsim' => ["2013-01-13T16:45:56Z"])
|
27
27
|
end
|
28
28
|
it "should insert true Booleans" do
|
29
29
|
Solrizer.insert_field(doc, 'foo', true)
|
30
|
-
doc.
|
30
|
+
expect(doc).to eq('foo_bsi' => true)
|
31
31
|
end
|
32
32
|
it "should insert false Booleans" do
|
33
33
|
Solrizer.insert_field(doc, 'foo', false)
|
34
|
-
doc.
|
34
|
+
expect(doc).to eq('foo_bsi' => false)
|
35
35
|
end
|
36
36
|
|
37
37
|
it "should insert multiple values" do
|
38
38
|
Solrizer.insert_field(doc, 'foo', ['A name', 'B name'], :sortable, :facetable)
|
39
|
-
doc.
|
39
|
+
expect(doc).to eq('foo_si' => 'B name', 'foo_sim' => ['A name', 'B name'])
|
40
40
|
end
|
41
41
|
|
42
42
|
it 'should insert nothing when passed a nil value' do
|
43
43
|
Solrizer.insert_field(doc, 'foo', nil, :sortable, :facetable)
|
44
|
-
doc.
|
44
|
+
expect(doc).to eq( { } )
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
48
|
describe "on a document with values" do
|
49
|
-
|
49
|
+
let(:doc) { {'foo_si' => 'A name', 'foo_sim' => ['A name']} }
|
50
50
|
|
51
51
|
it "should not overwrite muli-values that exist before" do
|
52
|
-
Solrizer.insert_field(
|
53
|
-
|
52
|
+
Solrizer.insert_field(doc, 'foo', 'B name', :sortable, :facetable)
|
53
|
+
expect(doc).to eq('foo_si' => 'B name', 'foo_sim' => ['A name', 'B name'])
|
54
54
|
end
|
55
55
|
end
|
56
56
|
end
|
57
57
|
describe ".set_field" do
|
58
58
|
describe "on a document with values" do
|
59
|
-
|
59
|
+
let(:doc) { {'foo_si' => ['A name'], 'foo_sim' => ['A name']} }
|
60
60
|
|
61
61
|
it "should overwrite values that exist before" do
|
62
|
-
Solrizer.set_field(
|
63
|
-
|
62
|
+
Solrizer.set_field(doc, 'foo', 'B name', :sortable, :facetable)
|
63
|
+
expect(doc).to eq('foo_si' => 'B name', 'foo_sim' => ['B name'])
|
64
64
|
end
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
68
|
describe ".solr_name" do
|
69
69
|
it "should delegate to default_field_mapper" do
|
70
|
-
Solrizer.solr_name('foo', type: :string).
|
71
|
-
Solrizer.solr_name('foo', :sortable).
|
70
|
+
expect(Solrizer.solr_name('foo', type: :string)).to eq "foo_tesim"
|
71
|
+
expect(Solrizer.solr_name('foo', :sortable)).to eq "foo_si"
|
72
72
|
end
|
73
73
|
end
|
74
74
|
end
|
@@ -10,16 +10,16 @@ describe Solrizer::XML::Extractor do
|
|
10
10
|
|
11
11
|
describe ".xml_to_solr" do
|
12
12
|
it "should turn simple xml into a solr document" do
|
13
|
-
result[:type_tesim].
|
14
|
-
result[:medium_tesim].
|
15
|
-
result[:rights_tesim].
|
16
|
-
result[:date_tesim].
|
17
|
-
result[:format_tesim].
|
18
|
-
result[:format_tesim].
|
19
|
-
result[:format_tesim].
|
20
|
-
result[:format_tesim].
|
21
|
-
result[:title_tesim].
|
22
|
-
result[:publisher_tesim].
|
13
|
+
expect(result[:type_tesim]).to eq "text"
|
14
|
+
expect(result[:medium_tesim]).to eq "Paper Document"
|
15
|
+
expect(result[:rights_tesim]).to eq "Presumed under copyright. Do not publish."
|
16
|
+
expect(result[:date_tesim]).to eq "1985-12-30"
|
17
|
+
expect(result[:format_tesim]).to be_kind_of(Array)
|
18
|
+
expect(result[:format_tesim]).to include("application/tiff")
|
19
|
+
expect(result[:format_tesim]).to include("application/pdf")
|
20
|
+
expect(result[:format_tesim]).to include("application/jp2000")
|
21
|
+
expect(result[:title_tesim]).to eq "This is a Sample Title"
|
22
|
+
expect(result[:publisher_tesim]).to eq "Sample Unversity"
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: solrizer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Zumwalt
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-07-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -38,20 +38,6 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: mediashelf-loggable
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: 0.4.7
|
48
|
-
type: :runtime
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: 0.4.7
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
42
|
name: stomp
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|