Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add parsable label to colls #3147

Merged
merged 3 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions app/indexers/concerns/oregon_digital/parsable_label_behavior.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# frozen_string_literal: true

module OregonDigital
# adds parsable labels to indexers
# moved from GenericIndexer
module ParsableLabelBehavior
extend ActiveSupport::Concern

# rubocop:disable Metrics/AbcSize
# rubocop:disable Metrics/MethodLength
# rubocop:disable Metrics/CyclomaticComplexity
# METHOD: Solrize 'label$uri' into Solr
def label_fetch_properties_solr_doc(object, solr_doc)
# LOOP: Go through the controlled properties to get the field needed for indexing
object.controlled_properties.each do |o|
# FETCH: Get the array of controlled vocab from the properties
controlled_vocabs = object[o]

# CREATE: Make an empty label array
labels = []

# LOOP: Loop through all controlled vocabs uri and solrize to make it into 'label$uri'
controlled_vocabs.each do |cv|
cv.fetch
labels << (cv.solrize.last.is_a?(String) ? ['', cv.solrize.last].join('$') : cv.solrize.last[:label])
rescue IOError, SocketError, TriplestoreAdapter::TriplestoreException
labels << ['', cv.solrize.last].join('$')
end

# ASSIGN: Put the labels into their own field in solr_doc
solr_doc["#{o}_parsable_label_ssim"] = labels

# FETCH: Get the combined_properties from DeepIndex
combined_label = rdf_indexer.combined_properties[o.to_s]
next if combined_label.blank?

# CREATE: Push item into the new field of combine labels
index_parsable_combined_labels(combined_label, labels, solr_doc)
end

# ADD: Add keyword values to topic combined labels
if object.respond_to? :keyword
keyword_labels = object[:keyword].map { |kw| "#{kw}$" }
index_parsable_combined_labels('topic', keyword_labels, solr_doc)
end

# RETURN: Return the solr 'label$uri' in their field
solr_doc
end
# rubocop:enable Metrics/AbcSize
# rubocop:enable Metrics/MethodLength
# rubocop:enable Metrics/CyclomaticComplexity

# METHOD: Create the combined label parsable
def index_parsable_combined_labels(label, values, solr_doc)
solr_doc["#{label}_parsable_combined_label_ssim"] ||= []

solr_doc["#{label}_parsable_combined_label_ssim"] += values
end
end
end
49 changes: 1 addition & 48 deletions app/indexers/generic_indexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class GenericIndexer < Hyrax::WorkIndexer
include OregonDigital::IndexesLinkedMetadata
include OregonDigital::IndexingDatesBehavior
include OregonDigital::StripsStopwords
include OregonDigital::ParsableLabelBehavior

# ABC Size is hard to avoid here because there are many types of fields we need to index.
# Pulling them out of #generate_solr_document and creating their own methods causes this issue to
Expand Down Expand Up @@ -154,53 +155,5 @@ def discoverable_groups
def all_existing_groups
(object.edit_groups + object.read_groups + object.discover_groups)
end

# rubocop:disable Metrics/AbcSize
# rubocop:disable Metrics/MethodLength
# METHOD: Solrize 'label$uri' into Solr
def label_fetch_properties_solr_doc(object, solr_doc)
# LOOP: Go through the controlled properties to get the field needed for indexing
object.controlled_properties.each do |o|
# FETCH: Get the array of controlled vocab from the properties
controlled_vocabs = object[o]

# CREATE: Make an empty label array
labels = []

# LOOP: Loop through all controlled vocabs uri and solrize to make it into 'label$uri'
controlled_vocabs.each do |cv|
cv.fetch
labels << (cv.solrize.last.is_a?(String) ? ['', cv.solrize.last].join('$') : cv.solrize.last[:label])
rescue IOError, SocketError, TriplestoreAdapter::TriplestoreException
labels << ['', cv.solrize.last].join('$')
end

# ASSIGN: Put the labels into their own field in solr_doc
solr_doc["#{o}_parsable_label_ssim"] = labels

# FETCH: Get the combined_properties from DeepIndex
combined_label = rdf_indexer.combined_properties[o.to_s]
next if combined_label.blank?

# CREATE: Push item into the new field of combine labels
index_parsable_combined_labels(combined_label, labels, solr_doc)
end

# ADD: Add keyword values to topic combined labels
keyword_labels = object[:keyword].map { |kw| "#{kw}$" }
index_parsable_combined_labels('topic', keyword_labels, solr_doc)

# RETURN: Return the solr 'label$uri' in their field
solr_doc
end
# rubocop:enable Metrics/AbcSize
# rubocop:enable Metrics/MethodLength

# METHOD: Create the combined label parsable
def index_parsable_combined_labels(label, values, solr_doc)
solr_doc["#{label}_parsable_combined_label_ssim"] ||= []

solr_doc["#{label}_parsable_combined_label_ssim"] += values
end
end
# rubocop:enable Metrics/ClassLength
2 changes: 2 additions & 0 deletions app/indexers/oregon_digital/collection_indexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ class CollectionIndexer < Hyrax::CollectionIndexer
include OregonDigital::IndexesLinkedMetadata
include OregonDigital::IndexingDatesBehavior
include OregonDigital::StripsStopwords
include OregonDigital::ParsableLabelBehavior

# Custom collection indexing options
def generate_solr_document
super.tap do |solr_doc|
# Sortable collection title
solr_doc['title_ssort'] = strip_stopwords(object.title.first)
label_fetch_properties_solr_doc(object, solr_doc)
end
end
end
Expand Down