Class: DorIndexing::Indexers::AdministrativeTagIndexer

Inherits:
Object
  • Object
show all
Defined in:
lib/dor_indexing/indexers/administrative_tag_indexer.rb

Overview

Index administrative tags for an object

Constant Summary collapse

TAG_PART_DELIMITER =
' : '
SPECIAL_TAG_TYPES_TO_INDEX =
['Project', 'Registered By'].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, administrative_tags:) ⇒ AdministrativeTagIndexer

Returns a new instance of AdministrativeTagIndexer.



12
13
14
15
# File 'lib/dor_indexing/indexers/administrative_tag_indexer.rb', line 12

def initialize(id:, administrative_tags:, **)
  @id = id
  @administrative_tags = administrative_tags
end

Instance Attribute Details

#administrative_tagsObject (readonly)

Returns the value of attribute administrative_tags.



10
11
12
# File 'lib/dor_indexing/indexers/administrative_tag_indexer.rb', line 10

def administrative_tags
  @administrative_tags
end

#idObject (readonly)

Returns the value of attribute id.



10
11
12
# File 'lib/dor_indexing/indexers/administrative_tag_indexer.rb', line 10

def id
  @id
end

Instance Method Details

#to_solrHash

rubocop:disable Metrics/MethodLength rubocop:disable Metrics/AbcSize rubocop:disable Metrics/CyclomaticComplexity

Returns:

  • (Hash)

    the partial solr document for administrative tags



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/dor_indexing/indexers/administrative_tag_indexer.rb', line 21

def to_solr
  solr_doc = {
    'tag_ssim' => [],
    'tag_text_unstemmed_im' => [],
    'exploded_nonproject_tag_ssim' => []
  }
  administrative_tags.each do |tag|
    tag_prefix, rest = tag.split(TAG_PART_DELIMITER, 2)
    prefix = tag_prefix.downcase.strip.gsub(/\s/, '_')

    solr_doc['tag_ssim'] << tag # for Argo display and fq
    solr_doc['tag_text_unstemmed_im'] << tag # for Argo search

    # exploded tags are for hierarchical facets in Argo
    solr_doc['exploded_nonproject_tag_ssim'] += explode_tag_hierarchy(tag) unless prefix == 'project'

    next if rest.blank?

    # Index specific tag types that are used in Argo:
    #  project tags for search results and registered by tags for reports ...
    next unless SPECIAL_TAG_TYPES_TO_INDEX.include?(tag_prefix)

    (solr_doc["#{prefix}_tag_ssim"] ||= []) << rest.strip

    if prefix == 'project'
      solr_doc['exploded_project_tag_ssim'] ||= []
      solr_doc['exploded_project_tag_ssim'] += explode_tag_hierarchy(rest.strip)
    end
  end
  solr_doc
end