Skip to content

Instantly share code, notes, and snippets.

@mankind
Last active July 17, 2019 08:49
Show Gist options
  • Save mankind/d14673d216757f847adab81bf3dd7762 to your computer and use it in GitHub Desktop.
Save mankind/d14673d216757f847adab81bf3dd7762 to your computer and use it in GitHub Desktop.
attempt to display samvera active-fedora json metatdata field using custom indexer approach
<%= presenter.attribute_to_html(:formatted_creator, render_as: :faceted) %>
class JournalArticleIndexer < Hyrax::WorkIndexer
def generate_solr_document
super.tap do |solr_doc|
stored_value = object.creator
solr_doc['formatted_creator_tesim'] = JSON.parse(stored_value.first).collect { |hash| format_creator(hash) } if object.creator.present?
end
end
private
def format_creator(hash)
"name - #{hash['creator_given_name']}: orcid - #{hash['creator_orcid']} : type: #{hash['creator_name_type']}"
end
end
module Hyku
class JournalArticlePresenter < ManifestEnabledWorkShowPresenter
def creator
solr_document.formatted_creator
end
end
end
module Hyrax
class JournalArticlesController < ApplicationController
self.curation_concern_type = JournalArticle
# Use this line if you want to use a custom presenter
self.show_presenter = Hyku::JournalArticlePresenter
end
end
#First tried adding attribute but it didn't give me what I want, the I tried adding a method still no success
#leaving both code here for feedback from the community
class SolrDocument
#attribute :formatted_creator, Solr::Array, solr_name('formatted_creator_tesim')
def formatted_creator
self[Solrizer.solr_name('formatted_creator')]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment