Class: Dor::IdentifiableIndexer

Inherits:
Object
  • Object
show all
Includes:
SolrDocHelper
Defined in:
lib/dor/indexers/identifiable_indexer.rb

Constant Summary collapse

@@collection_hash =

Module-level variables, shared between ALL mixin includers (and ALL their includers/extenders)! used for caching found values

{}
@@apo_hash =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SolrDocHelper

#add_solr_value

Constructor Details

#initialize(resource:) ⇒ IdentifiableIndexer

Returns a new instance of IdentifiableIndexer.



8
9
10
# File 'lib/dor/indexers/identifiable_indexer.rb', line 8

def initialize(resource:)
  @resource = resource
end

Instance Attribute Details

#resourceObject (readonly)

Returns the value of attribute resource.



7
8
9
# File 'lib/dor/indexers/identifiable_indexer.rb', line 7

def resource
  @resource
end

Class Method Details

.reset_cache!Object

Clears out the cache of items. Used primarily in testing.



50
51
52
53
# File 'lib/dor/indexers/identifiable_indexer.rb', line 50

def self.reset_cache!
  @@collection_hash = {}
  @@apo_hash = {}
end

Instance Method Details

#identity_metadata_sourceString

Returns calculated value for Solr index.

Returns:

  • (String)

    calculated value for Solr index



40
41
42
43
44
45
46
47
# File 'lib/dor/indexers/identifiable_indexer.rb', line 40

def 
  if resource..otherId('catkey').first ||
     resource..otherId('barcode').first
    'Symphony'
  else
    'DOR'
  end
end

#to_solrHash

Returns the partial solr document for identifiable concerns.

Returns:

  • (Hash)

    the partial solr document for identifiable concerns



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/dor/indexers/identifiable_indexer.rb', line 18

def to_solr
  solr_doc = {}
  solr_doc[Dor::INDEX_VERSION_FIELD] = Dor::VERSION
  solr_doc['indexed_at_dtsi'] = Time.now.utc.xmlschema
  resource.datastreams.values.each do |ds|
    add_solr_value(solr_doc, 'ds_specs', ds.datastream_spec_string, :string, [:symbol]) unless ds.new?
  end

  add_solr_value(solr_doc, 'title_sort', resource.label, :string, [:stored_sortable])

  rels_doc = Nokogiri::XML(resource.datastreams['RELS-EXT'].content)
  ns_hash = { 'hydra' => 'http://projecthydra.org/ns/relations#', 'fedora' => 'info:fedora/fedora-system:def/relations-external#', 'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#' }
  apos = rels_doc.search('//rdf:RDF/rdf:Description/hydra:isGovernedBy', ns_hash)
  collections = rels_doc.search('//rdf:RDF/rdf:Description/fedora:isMemberOfCollection', ns_hash)
  solrize_related_obj_titles(solr_doc, apos, @@apo_hash, 'apo_title', 'nonhydrus_apo_title', 'hydrus_apo_title')
  solrize_related_obj_titles(solr_doc, collections, @@collection_hash, 'collection_title', 'nonhydrus_collection_title', 'hydrus_collection_title')
  solr_doc['public_dc_relation_tesim'] ||= solr_doc['collection_title_tesim'] if solr_doc['collection_title_tesim']
  solr_doc['metadata_source_ssi'] = 
  solr_doc
end