blacklight-marc 5.10.0 → 6.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -1
- data/.travis.yml +12 -17
- data/Gemfile +21 -14
- data/README.md +18 -1
- data/Rakefile +2 -2
- data/app/assets/stylesheets/blacklight_marc.scss +42 -0
- data/app/helpers/blacklight_marc_helper.rb +17 -0
- data/{lib → app/models/concerns}/blacklight/solr/document/marc.rb +0 -0
- data/{lib → app/models/concerns}/blacklight/solr/document/marc_export.rb +0 -20
- data/app/views/bookmarks/_endnote.html.erb +1 -1
- data/app/views/bookmarks/_refworks.html.erb +1 -1
- data/app/views/catalog/_refworks_form.html.erb +6 -0
- data/app/views/catalog/show.refworks.erb +1 -0
- data/blacklight-marc.gemspec +9 -5
- data/config/locales/blacklight_marc.de.yml +5 -0
- data/config/locales/{blacklight.en.yml → blacklight_marc.en.yml} +2 -2
- data/config/locales/blacklight_marc.es.yml +5 -0
- data/config/locales/{blacklight.fr.yml → blacklight_marc.fr.yml} +0 -0
- data/config/locales/blacklight_marc.it.yml +5 -0
- data/config/locales/blacklight_marc.pt-BR.yml +5 -0
- data/lib/blacklight/marc.rb +2 -4
- data/lib/blacklight/marc/catalog.rb +23 -0
- data/lib/blacklight/marc/engine.rb +18 -0
- data/lib/blacklight/marc/indexer.rb +80 -0
- data/lib/blacklight/marc/indexer/dewey.rb +35 -0
- data/lib/blacklight/marc/indexer/formats.rb +194 -0
- data/lib/blacklight/marc/routes.rb +2 -2
- data/lib/blacklight/marc/version.rb +1 -1
- data/lib/generators/blacklight/marc/install_generator.rb +21 -7
- data/lib/generators/blacklight/marc/templates/app/models/marc_indexer.rb +161 -0
- data/lib/generators/blacklight/marc/templates/config/{SolrMarc/translation_maps → translation_maps}/README_MAPS +0 -0
- data/lib/generators/blacklight/marc/templates/config/{SolrMarc/translation_maps → translation_maps}/callnumber_map.properties +0 -0
- data/lib/generators/blacklight/marc/templates/config/{SolrMarc/translation_maps → translation_maps}/composition_era_map.properties +0 -0
- data/lib/generators/blacklight/marc/templates/config/{SolrMarc/translation_maps → translation_maps}/country_map.properties +0 -0
- data/lib/generators/blacklight/marc/templates/config/{SolrMarc/translation_maps → translation_maps}/format_map.properties +0 -0
- data/lib/generators/blacklight/marc/templates/config/{SolrMarc/translation_maps → translation_maps}/instrument_map.properties +0 -0
- data/lib/generators/blacklight/marc/templates/config/{SolrMarc/translation_maps → translation_maps}/language_map.properties +0 -0
- data/lib/railties/solr_marc.rake +24 -27
- data/spec/features/bookmarks_spec.rb +17 -0
- data/spec/features/librarian_view_spec.rb +1 -1
- data/spec/features/record_view_spec.rb +13 -0
- data/spec/features/search_formats_spec.rb +31 -0
- data/spec/helpers/blacklight_marc_helper_spec.rb +20 -0
- data/spec/lib/indexer/dewey_spec.rb +86 -0
- data/spec/lib/indexer/formats_spec.rb +65 -0
- data/spec/lib/tasks/solr_marc_task_spec.rb +14 -18
- data/spec/lib/traject_indexer_spec.rb +132 -0
- data/spec/routing/routes_spec.rb +2 -2
- data/spec/spec_helper.rb +8 -1
- data/spec/support/controller_level_helpers.rb +21 -0
- data/spec/test_app_templates/lib/generators/test_app_generator.rb +1 -3
- data/spec/views/bookmarks/_endnote.html.erb_spec.rb +4 -0
- data/spec/views/bookmarks/_refworks.html.erb_spec.rb +4 -0
- data/spec/views/catalog/_document_action.html.erb_spec.rb +21 -0
- data/spec/views/catalog/index.atom.builder_spec.rb +58 -0
- data/test_support/config/translation_maps/test_dewey.properties +99 -0
- data/test_support/config/translation_maps/test_formats.properties +22 -0
- metadata +101 -30
- data/lib/SolrMarc.jar +0 -0
- data/lib/blacklight/marc/railtie.rb +0 -17
- data/lib/generators/blacklight/marc/templates/config/SolrMarc/config-test.properties +0 -37
- data/lib/generators/blacklight/marc/templates/config/SolrMarc/config.properties +0 -37
- data/lib/generators/blacklight/marc/templates/config/SolrMarc/index.properties +0 -97
- data/lib/generators/blacklight/marc/templates/config/SolrMarc/index_scripts/dewey.bsh +0 -47
- data/lib/generators/blacklight/marc/templates/config/SolrMarc/index_scripts/format.bsh +0 -126
- data/lib/generators/blacklight_marc/marc_generator.rb +0 -9
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/lib/railties/solr_marc.rake
CHANGED
@@ -4,7 +4,24 @@
|
|
4
4
|
# config.properties defaults to config/demo_config.properties (in the plugin, not the rails app)
|
5
5
|
|
6
6
|
require 'fileutils'
|
7
|
-
|
7
|
+
require 'traject'
|
8
|
+
# monkey patch
|
9
|
+
class Traject::SolrJsonWriter
|
10
|
+
def record_id_from_context(context)
|
11
|
+
marc_id = context.source_record && context.source_record['001'] && context.source_record['001'].value
|
12
|
+
output_id = context.output_hash["id"]
|
13
|
+
|
14
|
+
return [marc_id, output_id].compact.join("/")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
module SolrMarc
|
18
|
+
def self.indexer
|
19
|
+
@indexer ||= ::MarcIndexer.new
|
20
|
+
end
|
21
|
+
def self.indexer=(ix)
|
22
|
+
@indexer = ix
|
23
|
+
end
|
24
|
+
end
|
8
25
|
namespace :solr do
|
9
26
|
namespace :marc do
|
10
27
|
|
@@ -24,17 +41,17 @@ namespace :solr do
|
|
24
41
|
task :index => "index:work"
|
25
42
|
namespace :index do
|
26
43
|
|
27
|
-
task :work do
|
44
|
+
task :work => :environment do
|
28
45
|
solrmarc_arguments = compute_arguments
|
29
46
|
|
30
47
|
# If no marc records given, display :info task
|
31
48
|
if (ENV["NOOP"] || (!solrmarc_arguments["MARC_FILE"]))
|
32
49
|
Rake::Task[ "solr:marc:index:info" ].execute
|
33
|
-
else
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
50
|
+
else
|
51
|
+
require './app/models/marc_indexer' unless defined?(MarcIndexer)
|
52
|
+
open(solrmarc_arguments['MARC_FILE']) do |io|
|
53
|
+
SolrMarc.indexer.process(io)
|
54
|
+
end
|
38
55
|
end
|
39
56
|
|
40
57
|
end # work
|
@@ -59,14 +76,6 @@ namespace :solr do
|
|
59
76
|
|
60
77
|
Note that SolrMarc search path includes directory of config_path,
|
61
78
|
so translation_maps and index_scripts dirs will be found there.
|
62
|
-
|
63
|
-
SOLRMARC_JAR_PATH: #{solrmarc_arguments[:solrmarc_jar_path]}
|
64
|
-
|
65
|
-
SOLRMARC_MEM_ARGS: #{solrmarc_arguments[:solrmarc_mem_arg]}
|
66
|
-
|
67
|
-
SolrMarc command that will be run:
|
68
|
-
|
69
|
-
#{solrmarc_command_line(solrmarc_arguments)}
|
70
79
|
EOS
|
71
80
|
end
|
72
81
|
end # index
|
@@ -134,18 +143,6 @@ def compute_arguments
|
|
134
143
|
return arguments
|
135
144
|
end
|
136
145
|
|
137
|
-
def solrmarc_command_line(arguments)
|
138
|
-
cmd = "java #{arguments[:solrmarc_mem_arg]} "
|
139
|
-
cmd += " -Dsolr.hosturl=#{arguments[:solr_url]} " unless arguments[:solr_url].blank?
|
140
|
-
|
141
|
-
cmd += " -Dsolrmarc.solr.war.path=#{arguments[:solr_war_path]}" unless arguments[:solr_war_path].blank?
|
142
|
-
cmd += " -Dsolr.path=#{arguments[:solr_path]}" unless arguments[:solr_path].blank?
|
143
|
-
|
144
|
-
cmd += " -jar #{arguments[:solrmarc_jar_path]} #{arguments[:config_properties_path]} #{arguments["MARC_FILE"]}"
|
145
|
-
return cmd
|
146
|
-
end
|
147
|
-
|
148
|
-
|
149
146
|
def locate_path(*subpath_fragments)
|
150
147
|
local_root = File.expand_path File.join(File.dirname(__FILE__), '..', '..')
|
151
148
|
subpath = subpath_fragments.join('/')
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Bookmark tools" do
|
4
|
+
it "should have an endnote export" do
|
5
|
+
visit solr_document_path('2007020969')
|
6
|
+
click_button 'Bookmark'
|
7
|
+
visit "/bookmarks.endnote?q="
|
8
|
+
expect(page).to have_content " %@ 9780743297790"
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should have a refworks export" do
|
12
|
+
visit solr_document_path('2007020969')
|
13
|
+
click_button 'Bookmark'
|
14
|
+
visit "/bookmarks.refworks_marc_txt?q="
|
15
|
+
expect(page).to have_content "LEADER 01490cam a2200361 a 4500001 2007020969"
|
16
|
+
end
|
17
|
+
end
|
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe "Librarian view" do
|
4
4
|
it "should show marc fields" do
|
5
|
-
visit
|
5
|
+
visit solr_document_path('2009373513')
|
6
6
|
click_link "Librarian View"
|
7
7
|
expect(page).to have_content "Librarian View"
|
8
8
|
expect(page).to have_content "LEADER 01213nam a22003614a 4500"
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe "Record View" do
|
5
|
+
describe "Tools" do
|
6
|
+
it "should have a refworks link" do
|
7
|
+
visit solr_document_path('2008305903')
|
8
|
+
expect(page).to have_link "Export to Refworks"
|
9
|
+
link = find_link("Export to Refworks")
|
10
|
+
expect(link['href']).to include CGI.escape(solr_document_path('2008305903', format: :refworks_marc_txt))
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe "Search Formats" do
|
6
|
+
before do
|
7
|
+
# Get all the fields from Solr, so the #index documents have the MARC field (to trigger appropriate
|
8
|
+
# export formats)
|
9
|
+
CatalogController.blacklight_config.default_solr_params[:fl] = '*'
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should return new-line separated RIS records" do
|
13
|
+
visit "/catalog.endnote?q="
|
14
|
+
expect(page.status_code).to eq 200
|
15
|
+
rmt_regex = /^%0/
|
16
|
+
expect(page).to have_content "%A Bstan-ʼdzin-rgya-mtsho,"
|
17
|
+
expect(page).to have_content "%@ 9789573908678"
|
18
|
+
expect(page.body).to match rmt_regex
|
19
|
+
expect(page.body.scan(rmt_regex).length).to eq 10
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should return new-line separated MARC records" do
|
23
|
+
visit "/catalog.refworks_marc_txt?q="
|
24
|
+
expect(page.status_code).to eq 200
|
25
|
+
rmt_regex = /LEADER .+\n(\d\d\d .. .+\n)+/
|
26
|
+
expect(page).to have_content "LEADER 01221cam a22002534a 4500001"
|
27
|
+
expect(page).to have_content "LEADER 01127cam a22002895a 4500001"
|
28
|
+
expect(page.body).to match rmt_regex
|
29
|
+
expect(page.body.scan(rmt_regex).length).to eq 10
|
30
|
+
end
|
31
|
+
end
|
@@ -23,4 +23,24 @@ describe BlacklightMarcHelper do
|
|
23
23
|
expect(helper.render_endnote_texts([one, two])).to eq "one\ntwo\n"
|
24
24
|
end
|
25
25
|
end
|
26
|
+
require 'spec_helper'
|
27
|
+
|
28
|
+
describe '#document_action_path' do
|
29
|
+
before do
|
30
|
+
allow(helper).to receive_messages(controller_name: 'catalog')
|
31
|
+
end
|
32
|
+
|
33
|
+
let(:document_action_config) { Blacklight::Configuration::ToolConfig.new(tool_config) }
|
34
|
+
let(:document) { SolrDocument.new(id: '123') }
|
35
|
+
|
36
|
+
subject { helper.document_action_path(document_action_config, id: document) }
|
37
|
+
|
38
|
+
context "for endnote" do
|
39
|
+
let(:tool_config) { { if: :render_refworks_action?, partial: "document_action",
|
40
|
+
name: :endnote, key: :endnote, path: :single_endnote_catalog_path } }
|
41
|
+
|
42
|
+
it { is_expected.to eq '/catalog/123.endnote' }
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
26
46
|
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Blacklight::Marc::Indexer::Dewey do
|
5
|
+
let(:test_class) do
|
6
|
+
c = Class.new(Blacklight::Marc::Indexer)
|
7
|
+
c.send :include, Blacklight::Marc::Indexer::Dewey
|
8
|
+
c
|
9
|
+
end
|
10
|
+
subject {test_class.new}
|
11
|
+
before do
|
12
|
+
$:.unshift './test_support/config'
|
13
|
+
subject.instance_eval do
|
14
|
+
to_field 'dewey100', dewey_facets(base: :hundreds, translation_map: 'test_dewey')
|
15
|
+
to_field 'dewey010', dewey_facets(base: :tens, translation_map: 'test_dewey')
|
16
|
+
to_field 'dewey_text', dewey_text
|
17
|
+
settings do
|
18
|
+
store "writer_class_name", "Traject::JsonWriter"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
let(:dewey) do
|
23
|
+
MARC::DataField.new('082',' ',' ',['a','343/13'])
|
24
|
+
end
|
25
|
+
let(:huey) do
|
26
|
+
MARC::DataField.new('082',' ',' ',['a','lol/wut'])
|
27
|
+
end
|
28
|
+
describe '#dewey_facets' do
|
29
|
+
it do
|
30
|
+
expect(subject).to respond_to(:dewey_facets)
|
31
|
+
end
|
32
|
+
it 'should map valid dewey' do
|
33
|
+
record = double('Record')
|
34
|
+
# just return bytes for control field, subfield array for data
|
35
|
+
expect(record).to receive(:fields).with(['082','880']).exactly(2).times.and_return([dewey])
|
36
|
+
val = []
|
37
|
+
subject.dewey_facets(base: :hundreds, translation_map: 'test_dewey').call(record,val,subject)
|
38
|
+
expect(val).to eql(['300s - Social Sciences'])
|
39
|
+
val = []
|
40
|
+
subject.dewey_facets(base: :tens, translation_map: 'test_dewey').call(record,val,subject)
|
41
|
+
expect(val).to eql(['340s - Law'])
|
42
|
+
end
|
43
|
+
it 'should ignore invalid dewey' do
|
44
|
+
record = double('Record')
|
45
|
+
# just return bytes for control field, subfield array for data
|
46
|
+
expect(record).to receive(:fields).with(['082','880']).exactly(2).times.and_return([huey])
|
47
|
+
val = []
|
48
|
+
subject.dewey_facets(base: :hundreds, translation_map: 'test_dewey').call(record,val,subject)
|
49
|
+
expect(val).to eql([])
|
50
|
+
val = []
|
51
|
+
subject.dewey_facets(base: :tens, translation_map: 'test_dewey').call(record,val,subject)
|
52
|
+
expect(val).to eql([])
|
53
|
+
end
|
54
|
+
end
|
55
|
+
describe '#dewey_text' do
|
56
|
+
it do
|
57
|
+
expect(subject).to respond_to(:dewey_text)
|
58
|
+
end
|
59
|
+
it 'should generate formatted, unmapped text' do
|
60
|
+
record = double('Record')
|
61
|
+
# just return bytes for control field, subfield array for data
|
62
|
+
expect(record).to receive(:fields).with(['082','880']).and_return([dewey])
|
63
|
+
val = []
|
64
|
+
subject.dewey_text.call(record,val,subject)
|
65
|
+
expect(val).to eql(['343 13'])
|
66
|
+
end
|
67
|
+
it 'should ignore invalid dewey' do
|
68
|
+
record = double('Record')
|
69
|
+
# just return bytes for control field, subfield array for data
|
70
|
+
expect(record).to receive(:fields).with(['082','880']).times.and_return([huey])
|
71
|
+
val = []
|
72
|
+
subject.dewey_text.call(record,val,subject)
|
73
|
+
expect(val).to eql([])
|
74
|
+
end
|
75
|
+
end
|
76
|
+
describe '#valid_dewey?' do
|
77
|
+
it do
|
78
|
+
expect(subject).to respond_to(:valid_dewey?)
|
79
|
+
end
|
80
|
+
it 'shoud audit values' do
|
81
|
+
expect(subject.valid_dewey?'111.4').to be_truthy
|
82
|
+
expect(subject.valid_dewey?'111.a').to be_truthy
|
83
|
+
expect(subject.valid_dewey?'a11.4').to be_falsy
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
#require 'marc'
|
4
|
+
describe Blacklight::Marc::Indexer::Formats do
|
5
|
+
let(:test_class) do
|
6
|
+
c = Class.new(Blacklight::Marc::Indexer)
|
7
|
+
c.send :include, Blacklight::Marc::Indexer::Formats
|
8
|
+
c
|
9
|
+
end
|
10
|
+
|
11
|
+
subject {test_class.new}
|
12
|
+
before do
|
13
|
+
subject.instance_eval do
|
14
|
+
to_field 'format', get_format
|
15
|
+
settings do
|
16
|
+
provide "writer_class_name", "Traject::JsonWriter"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#get_format' do
|
22
|
+
let(:electronic) do
|
23
|
+
MARC::DataField.new('245',' ',' ',['h','electronic resource'])
|
24
|
+
end
|
25
|
+
it 'should respond' do
|
26
|
+
expect(subject).to respond_to(:get_format)
|
27
|
+
end
|
28
|
+
it 'should map for 245h fields' do
|
29
|
+
record = double('Record')
|
30
|
+
# just return bytes for control field, subfield array for data
|
31
|
+
expect(record).to receive(:fields).with(['245','880']).and_return([electronic])
|
32
|
+
val = []
|
33
|
+
subject.get_format.call(record,val,subject)
|
34
|
+
expect(val).to eql(['Electronic'])
|
35
|
+
end
|
36
|
+
it 'should map for 007 fields' do
|
37
|
+
record = double('Record')
|
38
|
+
allow(record).to receive(:fields).with(["245", "880"]).and_return([])
|
39
|
+
expect(record).to receive(:fields).with(["007", "880"]).and_return([MARC::ControlField.new('007','CA')])
|
40
|
+
val = []
|
41
|
+
subject.get_format.call(record,val,subject)
|
42
|
+
expect(val).to eql(['TapeCartridge'])
|
43
|
+
end
|
44
|
+
it 'should map for leader' do
|
45
|
+
record = double('Record')
|
46
|
+
allow(record).to receive(:fields).with(["245", "880"]).and_return([])
|
47
|
+
allow(record).to receive(:fields).with(["007", "880"]).and_return([])
|
48
|
+
allow(record).to receive(:[]).with('001').and_return(MARC::ControlField.new('001',''))
|
49
|
+
expect(record).to receive(:leader).and_return('012345am')
|
50
|
+
val = []
|
51
|
+
subject.get_format.call(record,val,subject)
|
52
|
+
expect(val).to eql(['Book'])
|
53
|
+
end
|
54
|
+
it 'should default' do
|
55
|
+
record = double('Record')
|
56
|
+
allow(record).to receive(:fields).with(["245", "880"]).and_return([])
|
57
|
+
allow(record).to receive(:fields).with(["007", "880"]).and_return([])
|
58
|
+
allow(record).to receive(:[]).with('001').and_return(MARC::ControlField.new('001',''))
|
59
|
+
allow(record).to receive(:leader).and_return('012345##')
|
60
|
+
val = []
|
61
|
+
subject.get_format.call(record,val,subject)
|
62
|
+
expect(val).to eql(['Unknown'])
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -23,36 +23,32 @@ describe "solr:marc:*" do
|
|
23
23
|
Rake.application.rake_require "../lib/railties/solr_marc"
|
24
24
|
Rake::Task.define_task(:environment)
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
describe 'solr:marc:index_test_data' do
|
28
28
|
it 'should print out usage using NOOP=true' do
|
29
29
|
root = Rails.root
|
30
30
|
ENV['NOOP'] = "true"
|
31
|
-
o = capture_stdout do
|
32
|
-
@rake['solr:marc:index_test_data'].invoke
|
31
|
+
o = capture_stdout do
|
32
|
+
@rake['solr:marc:index_test_data'].invoke
|
33
33
|
end
|
34
|
-
|
35
|
-
expect(o).to match(Regexp.escape("
|
34
|
+
|
35
|
+
expect(o).to match(Regexp.escape("Possible environment variables, with settings as invoked"))
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
39
|
describe "solr:marc:index" do
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
40
|
+
after do
|
41
|
+
SolrMarc.indexer= nil
|
42
|
+
end
|
43
|
+
it "should index the test data configured" do
|
44
|
+
indexer = double(MarcIndexer)
|
45
|
+
allow(indexer).to receive(:process).with("dummy.mrc")
|
46
|
+
SolrMarc.indexer= indexer
|
47
|
+
#expect(indexer).to receive(:process).with("dummy.mrc")
|
44
48
|
ENV["MARC_FILE"] = "dummy.mrc"
|
45
49
|
output = capture_stdout do
|
46
|
-
@rake['solr:marc:index:
|
50
|
+
@rake['solr:marc:index:work'].invoke
|
47
51
|
end
|
48
|
-
output =~ /SolrMarc command that will be run:\n\s*\n\s*(.*)\n/
|
49
|
-
java_cmd = $1
|
50
|
-
|
51
|
-
expect(java_cmd).not_to be_nil
|
52
|
-
expect(java_cmd).to match "java -Xmx512m"
|
53
|
-
expect(java_cmd).to match /-jar .*\/SolrMarc\.jar/
|
54
|
-
expect(java_cmd).to match "#{Rails.root}/config/SolrMarc/config-test.properties dummy.mrc"
|
55
|
-
expect(java_cmd).to match "-Dsolr.hosturl=http://127.0.0.1:[0-9]{2,5}/solr"
|
56
52
|
end
|
57
53
|
|
58
54
|
end
|
@@ -0,0 +1,132 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
def music_record
|
4
|
+
"<collection xmlns=\"http://www.loc.gov/MARC21/slim\">
|
5
|
+
<record>
|
6
|
+
<leader>01828cjm a2200409 a 4500</leader>
|
7
|
+
<controlfield tag=\"001\">a4768316</controlfield>
|
8
|
+
<controlfield tag=\"003\">SIRSI</controlfield>
|
9
|
+
<controlfield tag=\"007\">sd fungnnmmned</controlfield>
|
10
|
+
<controlfield tag=\"008\">020117p20011990xxuzz h d</controlfield>
|
11
|
+
|
12
|
+
<datafield tag=\"245\" ind1=\"0\" ind2=\"0\">
|
13
|
+
<subfield code=\"a\">Music for horn</subfield>
|
14
|
+
<subfield code=\"h\">[sound recording] /</subfield>
|
15
|
+
<subfield code=\"c\">Brahms, Beethoven, von Krufft.</subfield>
|
16
|
+
</datafield>
|
17
|
+
|
18
|
+
<datafield tag=\"260\" ind1=\" \" ind2=\" \">
|
19
|
+
<subfield code=\"a\">[United States] :</subfield>
|
20
|
+
<subfield code=\"b\">Harmonia Mundi USA,</subfield>
|
21
|
+
<subfield code=\"c\">p2001.</subfield>
|
22
|
+
</datafield>
|
23
|
+
|
24
|
+
<datafield tag=\"700\" ind1=\"1\" ind2=\" \">
|
25
|
+
<subfield code=\"a\">Greer, Lowell.</subfield>
|
26
|
+
</datafield>
|
27
|
+
|
28
|
+
<datafield tag=\"700\" ind1=\"1\" ind2=\" \">
|
29
|
+
<subfield code=\"a\">Lubin, Steven.</subfield>
|
30
|
+
</datafield>
|
31
|
+
|
32
|
+
<datafield tag=\"700\" ind1=\"1\" ind2=\" \">
|
33
|
+
<subfield code=\"a\">Chase, Stephanie,</subfield>
|
34
|
+
<subfield code=\"d\">1957-</subfield>
|
35
|
+
</datafield>
|
36
|
+
|
37
|
+
<datafield tag=\"700\" ind1=\"1\" ind2=\"2\">
|
38
|
+
<subfield code=\"a\">Brahms, Johannes,</subfield>
|
39
|
+
<subfield code=\"d\">1833-1897.</subfield>
|
40
|
+
<subfield code=\"t\">Trios,</subfield>
|
41
|
+
<subfield code=\"m\">piano, violin, horn,</subfield>
|
42
|
+
<subfield code=\"n\">op. 40,</subfield>
|
43
|
+
<subfield code=\"r\">E? major.</subfield>
|
44
|
+
</datafield>
|
45
|
+
|
46
|
+
<datafield tag=\"700\" ind1=\"1\" ind2=\"2\">
|
47
|
+
<subfield code=\"a\">Beethoven, Ludwig van,</subfield>
|
48
|
+
<subfield code=\"d\">1770-1827.</subfield>
|
49
|
+
<subfield code=\"t\">Sonatas,</subfield>
|
50
|
+
<subfield code=\"m\">horn, piano,</subfield>
|
51
|
+
<subfield code=\"n\">op. 17,</subfield>
|
52
|
+
<subfield code=\"r\">F major.</subfield>
|
53
|
+
</datafield>
|
54
|
+
|
55
|
+
<datafield tag=\"700\" ind1=\"1\" ind2=\"2\">
|
56
|
+
<subfield code=\"a\">Krufft, Nikolaus von,</subfield>
|
57
|
+
<subfield code=\"d\">1779-1818.</subfield>
|
58
|
+
<subfield code=\"t\">Sonata,</subfield>
|
59
|
+
<subfield code=\"m\">horn, piano,</subfield>
|
60
|
+
<subfield code=\"r\">F major.</subfield>
|
61
|
+
</datafield>
|
62
|
+
</record>
|
63
|
+
</collection>"
|
64
|
+
end
|
65
|
+
module TestIndexer
|
66
|
+
def initialize
|
67
|
+
super
|
68
|
+
settings do
|
69
|
+
# have to override the defaults!
|
70
|
+
store "marc_source.type", "xml"
|
71
|
+
store "writer_class_name", "TestIndexer::Writer"
|
72
|
+
end
|
73
|
+
to_field "id", trim(extract_marc("001"), :first => true)
|
74
|
+
to_field "format", extract_marc('007[0-1]') do |rec, acc|
|
75
|
+
legacy_formats = Traject::TranslationMap.new("test_formats")
|
76
|
+
acc << rec.leader[6..7]
|
77
|
+
acc << rec.leader[7]
|
78
|
+
acc.map! {|x| legacy_formats[x]}
|
79
|
+
acc.compact! # get rid of nils
|
80
|
+
acc << 'Unknown' # the default
|
81
|
+
acc.replace Array(acc[0]) # just take the first
|
82
|
+
end
|
83
|
+
to_field "mapped", map_value(literal('k'),translation_map:"test_formats")
|
84
|
+
end
|
85
|
+
class Writer
|
86
|
+
def self.accumulator=(acc)
|
87
|
+
@acc = acc
|
88
|
+
end
|
89
|
+
def self.accumulator
|
90
|
+
@acc
|
91
|
+
end
|
92
|
+
attr_reader :settings
|
93
|
+
|
94
|
+
def initialize(argSettings)
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
def serialize(context);end
|
99
|
+
def close;end
|
100
|
+
def put(context)
|
101
|
+
puts context.output_hash.inspect
|
102
|
+
TestIndexer::Writer.accumulator << context.output_hash
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
describe Blacklight::Marc::Indexer do
|
108
|
+
before do
|
109
|
+
$:.unshift './test_support/config'
|
110
|
+
end
|
111
|
+
subject { Blacklight::Marc::Indexer.new }
|
112
|
+
it do
|
113
|
+
expect(subject).to respond_to(:process)
|
114
|
+
end
|
115
|
+
context "XML indexing" do
|
116
|
+
let(:test_class) do
|
117
|
+
c = Class.new(Blacklight::Marc::Indexer)
|
118
|
+
c.send :include, TestIndexer
|
119
|
+
end
|
120
|
+
subject {test_class.new}
|
121
|
+
it do
|
122
|
+
io = StringIO.new(music_record)
|
123
|
+
vals = []
|
124
|
+
TestIndexer::Writer.accumulator= vals
|
125
|
+
subject.writer_class = TestIndexer::Writer
|
126
|
+
subject.process(io)
|
127
|
+
json = vals.first
|
128
|
+
expect(json['format']).to eql(['Sound Disc'])
|
129
|
+
expect(json['mapped']).to eql(['Image'])
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|