Class: Solrizer::Extractor
- Inherits:
-
Object
- Object
- Solrizer::Extractor
- Defined in:
- lib/solrizer/extractor.rb
Overview
Provides utilities for extracting solr fields from a variety of objects and/or creating solr documents from a given object Note: These utilities are optional. You can implement .to_solr directly on your classes if you want to bypass using Extractors.
Each of the Solrizer implementations (ie. solrizer-fedora) provides its own Extractor module that extends the behaviors of Solrizer::Extractor with methods specific to that implementation (ie. extract_tag, extract_rels_ext, xml_to_solr, html_to_solr).
By convention, the solrizer implementations will mix their own Extractors’ behaviors into this class when you load them into an application.
Class Method Summary collapse
-
.format_node_value(values) ⇒ String
Strips the majority of whitespace from the values array and then joins them with a single blank delimitter Returns an empty string if values argument is nil.
-
.insert_solr_field_value(solr_doc, field_name, field_value) ⇒ Object
Insert
field_value
forfield_name
intosolr_doc
Handles inserting new values into a Hash while ensuring that you don’t destroy or overwrite any existing values in the hash.
Instance Method Summary collapse
-
#extract_hash(input_hash, solr_hash = Hash.new) ⇒ Hash
Deprecated.
-
#format_node_value(values) ⇒ Object
Alias for Solrizer::Extractor#format_node_value.
-
#insert_solr_field_value(solr_doc, field_name, field_value) ⇒ Object
Alias for Solrizer::Extractor#insert_solr_field_value.
Class Method Details
.format_node_value(values) ⇒ String
Strips the majority of whitespace from the values array and then joins them with a single blank delimitter Returns an empty string if values argument is nil
34 35 36 37 38 39 40 41 |
# File 'lib/solrizer/extractor.rb', line 34 def self.format_node_value values if values.nil? return "" else values = [values] unless values.respond_to? :map return values.map{|val| val.gsub(/\s+/,' ').strip}.join(" ") end end |
.insert_solr_field_value(solr_doc, field_name, field_value) ⇒ Object
Insert field_value
for field_name
into solr_doc
Handles inserting new values into a Hash while ensuring that you don’t destroy or overwrite any existing values in the hash. Ensures that field values are always appended to arrays within the values hash. Also ensures that values are run through format_node_value
22 23 24 25 26 27 |
# File 'lib/solrizer/extractor.rb', line 22 def self.insert_solr_field_value(solr_doc, field_name, field_value) formatted_value = self.format_node_value(field_value) solr_doc[field_name] ||= [] solr_doc[field_name] << formatted_value return solr_doc end |
Instance Method Details
#extract_hash(input_hash, solr_hash = Hash.new) ⇒ Hash
Deprecated. merges input_hash into solr_hash
61 62 63 64 |
# File 'lib/solrizer/extractor.rb', line 61 def extract_hash( input_hash, solr_hash=Hash.new ) warn "[DEPRECATION] `extract_hash` is deprecated. Just pass values directly into your solr values hash" return solr_hash.merge!(input_hash) end |
#format_node_value(values) ⇒ Object
Alias for Solrizer::Extractor#format_node_value
51 52 53 |
# File 'lib/solrizer/extractor.rb', line 51 def format_node_value values Solrizer::Extractor.format_node_value(values) end |
#insert_solr_field_value(solr_doc, field_name, field_value) ⇒ Object
Alias for Solrizer::Extractor#insert_solr_field_value
46 47 48 |
# File 'lib/solrizer/extractor.rb', line 46 def insert_solr_field_value(solr_doc, field_name, field_value) Solrizer::Extractor.insert_solr_field_value(solr_doc, field_name, field_value) end |