Class: Blacklight::Marc::Indexer
- Inherits:
-
Traject::Indexer
- Object
- Traject::Indexer
- Blacklight::Marc::Indexer
- Includes:
- Traject::Macros::Marc21Semantics, Traject::Macros::MarcFormats
- Defined in:
- lib/blacklight/marc/indexer.rb
Direct Known Subclasses
Defined Under Namespace
Constant Summary collapse
- ATOZ =
('a'..'z').to_a.join('')
- ATOU =
('a'..'u').to_a.join('')
Instance Method Summary collapse
- #first_value(block, options = {}) ⇒ Object
- #get_xml(options = {}) ⇒ Object
-
#initialize ⇒ Indexer
constructor
A new instance of Indexer.
- #map_value(block, options = {}) ⇒ Object
- #trim(block, options = {}) ⇒ Object
Constructor Details
#initialize ⇒ Indexer
Returns a new instance of Indexer.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/blacklight/marc/indexer.rb', line 21 def initialize super settings do provide "reader_class_name", "Traject::MarcReader" if c = Blacklight.connection_config provide "solr.url", c[:url] end provide "solr_writer.commit_on_close", "true" provide "solr_writer.thread_pool", 1 provide "solr_writer.batch_size", 100 provide "writer_class_name", "Traject::SolrJsonWriter" provide 'processing_thread_pool', 1 provide "log.batch_size", 10_000 end end |
Instance Method Details
#first_value(block, options = {}) ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/blacklight/marc/indexer.rb', line 37 def first_value block, ={} lambda do |record, accumulator| if block.arity == 3 block.call(record,accumulator,) else block.call(record,accumulator) end accumulator.replace Array(accumulator[0]) # just take the first end end |
#get_xml(options = {}) ⇒ Object
75 76 77 78 79 |
# File 'lib/blacklight/marc/indexer.rb', line 75 def get_xml ={} lambda do |record, accumulator| accumulator << MARC::FastXMLWriter.encode(record) end end |
#map_value(block, options = {}) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/blacklight/marc/indexer.rb', line 47 def map_value block, ={} if translation_map_arg = .delete(:translation_map) translation_map = Traject::TranslationMap.new(translation_map_arg) else translation_map = nil end lambda do |record, accumulator| if block.arity == 3 block.call(record,accumulator,) else block.call(record,accumulator) end if translation_map translation_map.translate_array! accumulator end end end |
#trim(block, options = {}) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/blacklight/marc/indexer.rb', line 64 def trim block, ={} lambda do |record, accumulator| vals = [] if block.arity == 3 block.call(record,accumulator,) else block.call(record,accumulator) end accumulator.each {|x| x.strip!} end end |