Module: OM::XML::TerminologyBasedSolrizer::ClassMethods

Defined in:
lib/om/xml/terminology_based_solrizer.rb

Overview

Module Methods

Instance Method Summary collapse

Instance Method Details

#solrize(doc, solr_doc = Hash.new, field_mapper = nil) ⇒ Object

Build a solr document from doc based on its terminology

Parameters:

  • doc (OM::XML::Document)
  • solr_doc (Hash) (defaults to: Hash.new)

    (optional) solr_doc (values hash) to populate



15
16
17
18
19
20
21
22
23
# File 'lib/om/xml/terminology_based_solrizer.rb', line 15

def solrize(doc, solr_doc=Hash.new, field_mapper = nil)
  unless doc.class.terminology.nil?
    doc.class.terminology.terms.each_pair do |term_name,term|
      doc.solrize_term(term, solr_doc, field_mapper) unless term.is_root_term?
    end
  end

  return solr_doc
end

#solrize_node(node_value, doc, term_pointer, term, solr_doc = Hash.new, field_mapper = nil, opts = {}) ⇒ Hash

Populate a solr document with solr fields corresponding to the given xml node Field names are generated using settings from the term in the doc‘s terminology corresponding to term_pointer If the supplied term does not have an index_as attribute, no indexing will be performed.

Parameters:

  • node_value (Nokogiri::XML::Node)

    node to solrize

  • doc (OM::XML::Document)

    document the node came from

  • term_pointer (Array)

    Array pointing to the term that should be used for solrization settings

  • term (Term)

    the term to be solrized

  • solr_doc (Hash) (defaults to: Hash.new)

    (optional) solr_doc (values hash) to populate

Returns:

  • (Hash)

    the solr doc



58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/om/xml/terminology_based_solrizer.rb', line 58

def solrize_node(node_value, doc, term_pointer, term, solr_doc = Hash.new, field_mapper = nil, opts = {})
  return solr_doc unless term.index_as && !term.index_as.empty?
  
  generic_field_name_base = OM::XML::Terminology.term_generic_name(*term_pointer)
  create_and_insert_terms(generic_field_name_base, node_value, term.index_as, solr_doc)
  
  if term_pointer.length > 1
    hierarchical_field_name_base = OM::XML::Terminology.term_hierarchical_name(*term_pointer)
    create_and_insert_terms(hierarchical_field_name_base, node_value, term.index_as, solr_doc)
  end
  solr_doc
end

#solrize_term(doc, term, solr_doc = Hash.new, field_mapper = nil, opts = {}) ⇒ Object

Populate a solr document with fields based on nodes in xml Values for a term are gathered by to term_pointer using OM::XML::TermValueOperators.term_values and are deserialized by OM according to :type, as determined in its terminology. The content of the actual field in solr is each node of the nodeset returned by OM, rendered to a string.

Parameters:

  • doc (OM::XML::Document)

    xml document to extract values from

  • term (OM::XML::Term)

    corresponding to desired xml values

  • solr_doc (Hash) (defaults to: Hash.new)

    (optional) solr_doc (values hash) to populate



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/om/xml/terminology_based_solrizer.rb', line 33

def solrize_term(doc, term, solr_doc = Hash.new, field_mapper = nil, opts={})
  parents = opts.fetch(:parents, [])
  term_pointer = parents+[term.name]
  nodeset = doc.term_values(*term_pointer)
  
  nodeset.each do |n|
    doc.solrize_node(n, term_pointer, term, solr_doc, field_mapper)
    unless term.kind_of? OM::XML::NamedTermProxy
      term.children.each_pair do |child_term_name, child_term|
        doc.solrize_term(child_term, solr_doc, field_mapper, opts={:parents=>parents+[{term.name=>nodeset.index(n)}]})
      end
    end
  end
  solr_doc
end