marcspec 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +2 -0
- data/README.rdoc +4 -38
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/marcspec/customspec.rb +11 -0
- data/lib/marcspec/solrfieldspec.rb +3 -1
- data/lib/marcspec/specset.rb +15 -2
- data/spec/specset_spec.rb +20 -0
- metadata +8 -8
data/CHANGES
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
0.6.0
|
2
|
+
* Allow custom functions to return values for multiple solr fields at once; should help avoid duplication of work.
|
1
3
|
0.5.0
|
2
4
|
* Allow solr field names to repeat in a spec set. This allows you to cumulatively add to a solr field based on "regular"
|
3
5
|
and custom (or, say, two custom) specs.
|
data/README.rdoc
CHANGED
@@ -3,45 +3,11 @@
|
|
3
3
|
The MARCSpec contains classes designed to make it (relatively) easy to specify
|
4
4
|
a data field (my use case specifically is solr) in terms of sets of MARC fields and subfields.
|
5
5
|
|
6
|
-
== A simple breakdown of the hierarchy
|
7
|
-
|
8
|
-
This is all based on how the excellent [Solrmarc](http://code.google.com/p/solrmarc/)
|
9
|
-
deals with configuration. MARCSpec supports a subset of Solrmarc's configuration
|
10
|
-
options.
|
11
|
-
|
12
|
-
* A {MARCSpec::SpecSet} consists of a (possibly empty) set of named {MARCSpec::Map}
|
13
|
-
and a list of {MARCSpec::SolrFieldSpec} and/or {MARCSpec::CustomSolrSpec}.
|
14
|
-
* A {MARCSpec::SolrFieldSpec} consists of a field name, a list of MARC field specs (see below),
|
15
|
-
an optional {MARCSpec::Map} for translating raw values to something else, and
|
16
|
-
a bunch of optional specials (e.g., a notation to only use the first value,
|
17
|
-
a default value if no appropriate data is in the MARC record, a default value
|
18
|
-
for when marc data is found, but nothing is in the map, etc.)
|
19
|
-
* A {MARCSpec::CustomSolrSpec} occupies the same niche as a {MARCSpec::SolrFieldSpec}, but
|
20
|
-
allows you to use a custom routine instead of the pre-packaged MARC specification syntax.
|
21
|
-
* A MARC Field Spec is one of the following
|
22
|
-
* A {MARCSpec::LeaderSpec} for dealing with the leader
|
23
|
-
* A {MARCSpec::ControlFieldSpec}, consisting of a tag (as a string, not a number) and
|
24
|
-
an optional zero-based index (e.g., "001[3]") or range (e.g., "001[11..13]")
|
25
|
-
* A {MARCSpec::VariableFieldSpec}, consisting of a tag, a couple indicator patterns
|
26
|
-
(currently ignored, but stay tuned), an optional list of subfields (default
|
27
|
-
is all), and an optional string used to join the subfields (default is
|
28
|
-
a single space)
|
29
|
-
* A *map* is one of:
|
30
|
-
* A {MARCSpec::KVMap}, which is just a Ruby hash. It will match at most one k-v pair, although
|
31
|
-
the "value" might actually be either a scalar or an array of scalars
|
32
|
-
* A {MARCSpec::MultiValueMap}, which is an array of key/value duples. A passed
|
33
|
-
potential map is compared (via ===) with every key, returning all
|
34
|
-
the associated values. Again, a single "key" can be associated with an array of
|
35
|
-
return values; the whole thing is flattened out before returning
|
36
|
-
|
37
|
-
Obviously, better descriptions and full documentation is available in each
|
38
|
-
individual class.
|
39
|
-
|
40
|
-
== Better examples in marc2solr
|
41
|
-
|
42
|
-
Better documented samples are available as part of the marc2solr project
|
43
|
-
at http://github.com/billdueber/marc2solr -- look in the simple_sample area.
|
44
6
|
|
7
|
+
== Docs and examples in marc2solr
|
8
|
+
|
9
|
+
Documented samples are available as part of the marc2solr project
|
10
|
+
at http://github.com/billdueber/marc2solr -- look in the simple_sample area.
|
45
11
|
|
46
12
|
|
47
13
|
== Note on Patches/Pull Requests
|
data/Rakefile
CHANGED
@@ -14,7 +14,7 @@ begin
|
|
14
14
|
gem.add_development_dependency "yard", ">= 0"
|
15
15
|
|
16
16
|
gem.add_dependency 'marc4j4r', '>=0.9.0'
|
17
|
-
gem.add_dependency 'jruby_streaming_update_solr_server', '>=0.
|
17
|
+
gem.add_dependency 'jruby_streaming_update_solr_server', '>=0.3.1'
|
18
18
|
|
19
19
|
|
20
20
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.6.0
|
data/lib/marcspec/customspec.rb
CHANGED
@@ -40,6 +40,7 @@ module MARCSpec
|
|
40
40
|
raise ArgumentError, "Custom solr spec must have a field name in :solrField, module in :module, and the method name as a symbol in :methodSymbol"
|
41
41
|
end
|
42
42
|
|
43
|
+
|
43
44
|
@methodArgs = opts[:methodArgs] || []
|
44
45
|
|
45
46
|
@first = opts[:firstOnly] || false
|
@@ -47,6 +48,16 @@ module MARCSpec
|
|
47
48
|
@map = opts[:map] || nil
|
48
49
|
@noMapKeyDefault = opts[:noMapKeyDefault] || nil
|
49
50
|
|
51
|
+
if @solrField.is_a? Array
|
52
|
+
@arity = @solrField.size
|
53
|
+
if @first or @default or @map or @noMapKeyDefault
|
54
|
+
raise ArgumentError, "Custom spec with multiple solrFields can't have :first, :map, :default, or :noMapKeyDefault set"
|
55
|
+
end
|
56
|
+
else
|
57
|
+
@arity = 1
|
58
|
+
end
|
59
|
+
|
60
|
+
|
50
61
|
end
|
51
62
|
|
52
63
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'stringio'
|
2
2
|
module MARCSpec
|
3
3
|
class SolrFieldSpec
|
4
|
-
attr_accessor :solrField, :first, :map, :noMapKeyDefault, :marcfieldspecs, :default
|
4
|
+
attr_accessor :solrField, :first, :map, :noMapKeyDefault, :marcfieldspecs, :default, :arity
|
5
5
|
|
6
6
|
def initialize(opts)
|
7
7
|
@solrField = opts[:solrField]
|
@@ -9,6 +9,7 @@ module MARCSpec
|
|
9
9
|
@default = opts[:default] || nil
|
10
10
|
@map = opts[:map] || nil
|
11
11
|
@noMapKeyDefault = opts[:noMapKeyDefault] || nil
|
12
|
+
@arity = 1
|
12
13
|
@marcfieldspecs = []
|
13
14
|
end
|
14
15
|
|
@@ -27,6 +28,7 @@ module MARCSpec
|
|
27
28
|
|
28
29
|
def marc_values r, doc = {}
|
29
30
|
vals = raw_marc_values r, doc
|
31
|
+
return vals if @arity > 1
|
30
32
|
unless vals.is_a? Array
|
31
33
|
vals = [vals]
|
32
34
|
end
|
data/lib/marcspec/specset.rb
CHANGED
@@ -16,6 +16,13 @@ module MARCSpec
|
|
16
16
|
end
|
17
17
|
self[key].flatten!
|
18
18
|
end
|
19
|
+
|
20
|
+
def additive_merge! hashlike
|
21
|
+
hashlike.each do |k, v|
|
22
|
+
self.add(k, v)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
19
26
|
end
|
20
27
|
|
21
28
|
class SpecSet
|
@@ -82,8 +89,14 @@ module MARCSpec
|
|
82
89
|
|
83
90
|
def fill_hashlike_from_marc r, hashlike
|
84
91
|
@solrfieldspecs.each do |sfs|
|
85
|
-
|
86
|
-
|
92
|
+
if sfs.arity == 1
|
93
|
+
hashlike.add(sfs.solrField,sfs.marc_values(r, hashlike))
|
94
|
+
else
|
95
|
+
vals = sfs.marc_values(r, hashlike)
|
96
|
+
(0..(sfs.arity - 1)).each do |i|
|
97
|
+
hashlike.add(sfs.solrField[i], vals[i])
|
98
|
+
end
|
99
|
+
end
|
87
100
|
end
|
88
101
|
end
|
89
102
|
|
data/spec/specset_spec.rb
CHANGED
@@ -22,6 +22,11 @@ module A
|
|
22
22
|
end
|
23
23
|
return vals
|
24
24
|
end
|
25
|
+
|
26
|
+
|
27
|
+
def self.three_value_custom doc, r
|
28
|
+
return [1, 2, ['a', 'b']]
|
29
|
+
end
|
25
30
|
end
|
26
31
|
end
|
27
32
|
|
@@ -77,6 +82,21 @@ describe "SpecSet Basics" do
|
|
77
82
|
h = ss.hash_from_marc @one
|
78
83
|
h['titleA'].sort.should.equal expected.sort
|
79
84
|
end
|
85
|
+
|
86
|
+
it "should allow multi-headed custom fields" do
|
87
|
+
@speclist << {:solrField => ['one', 'two', 'letters'],
|
88
|
+
:module => A::B,
|
89
|
+
:methodSymbol => :three_value_custom,
|
90
|
+
}
|
91
|
+
ss = MARCSpec::SpecSet.new
|
92
|
+
ss.buildSpecsFromList(@speclist)
|
93
|
+
h = ss.hash_from_marc @one
|
94
|
+
h['one'].should.equal [1]
|
95
|
+
h['two'].should.equal [2]
|
96
|
+
h['letters'].should.equal ['a', 'b']
|
97
|
+
end
|
98
|
+
|
99
|
+
|
80
100
|
end
|
81
101
|
|
82
102
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: marcspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 7
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 6
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.6.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- BillDueber
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-08-
|
18
|
+
date: 2010-08-17 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -70,12 +70,12 @@ dependencies:
|
|
70
70
|
requirements:
|
71
71
|
- - ">="
|
72
72
|
- !ruby/object:Gem::Version
|
73
|
-
hash:
|
73
|
+
hash: 17
|
74
74
|
segments:
|
75
75
|
- 0
|
76
|
-
-
|
77
|
-
-
|
78
|
-
version: 0.
|
76
|
+
- 3
|
77
|
+
- 1
|
78
|
+
version: 0.3.1
|
79
79
|
type: :runtime
|
80
80
|
version_requirements: *id004
|
81
81
|
description: Relies on marc4j4r, based on work in solrmarc
|