This repository has been archived by the owner on May 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #327 from sul-dlss/indexers
Move indexing code into the app (from dor-services)
- Loading branch information
Showing
30 changed files
with
1,682 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# frozen_string_literal: true | ||
|
||
# Borrowed from https://github.com/samvera/valkyrie/blob/master/lib/valkyrie/persistence/solr/composite_indexer.rb | ||
class CompositeIndexer | ||
attr_reader :indexers | ||
def initialize(*indexers) | ||
@indexers = indexers | ||
end | ||
|
||
def new(resource:) | ||
Instance.new(indexers, resource: resource) | ||
end | ||
|
||
class Instance | ||
attr_reader :indexers, :resource | ||
def initialize(indexers, resource:) | ||
@resource = resource | ||
@indexers = indexers.map { |i| i.new(resource: resource) } | ||
end | ||
|
||
# @return [Hash] the merged solr document for all the sub-indexers | ||
def to_solr | ||
indexers.map(&:to_solr).inject({}, &:merge) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# frozen_string_literal: true | ||
|
||
# Indexing provided by ActiveFedora | ||
class DataIndexer | ||
include ActiveFedora::Indexing | ||
|
||
attr_reader :resource | ||
def initialize(resource:) | ||
@resource = resource | ||
end | ||
|
||
# we need to override this until https://github.com/samvera/active_fedora/pull/1371 | ||
# has been released | ||
def to_solr(solr_doc = {}, opts = {}) | ||
super.tap do |doc| | ||
doc['active_fedora_model_ssi'] = has_model | ||
end | ||
end | ||
|
||
delegate :create_date, :modified_date, :state, :pid, :inner_object, | ||
:datastreams, :relationships, :has_model, to: :resource | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# frozen_string_literal: true | ||
|
||
class DescribableIndexer | ||
attr_reader :resource | ||
def initialize(resource:) | ||
@resource = resource | ||
end | ||
|
||
# @return [Hash] the partial solr document for describable concerns | ||
def to_solr | ||
add_metadata_format_to_solr_doc.merge(add_mods_to_solr_doc) | ||
end | ||
|
||
def add_metadata_format_to_solr_doc | ||
{ 'metadata_format_ssim' => 'mods' } | ||
end | ||
|
||
def add_mods_to_solr_doc | ||
solr_doc = {} | ||
mods_sources = { | ||
sw_title_display: %w[sw_display_title_tesim], | ||
main_author_w_date: %w[sw_author_ssim sw_author_tesim], | ||
sw_sort_author: %w[sw_author_sort_ssi], | ||
sw_language_facet: %w[sw_language_ssim sw_language_tesim], | ||
sw_genre: %w[sw_genre_ssim sw_genre_tesim], | ||
format_main: %w[sw_format_ssim sw_format_tesim], | ||
topic_facet: %w[sw_topic_ssim sw_topic_tesim], | ||
era_facet: %w[sw_subject_temporal_ssim sw_subject_temporal_tesim], | ||
geographic_facet: %w[sw_subject_geographic_ssim sw_subject_geographic_tesim], | ||
%i[term_values typeOfResource] => %w[mods_typeOfResource_ssim mods_typeOfResource_tesim], | ||
pub_year_sort_str: %w[sw_pub_date_sort_ssi], | ||
pub_year_int: %w[sw_pub_date_sort_isi], | ||
pub_year_display_str: %w[sw_pub_date_facet_ssi] | ||
} | ||
|
||
mods_sources.each_pair do |meth, solr_keys| | ||
vals = meth.is_a?(Array) ? resource.stanford_mods.send(meth.shift, *meth) : resource.stanford_mods.send(meth) | ||
|
||
next if vals.nil? || (vals.respond_to?(:empty?) && vals.empty?) | ||
|
||
solr_keys.each do |key| | ||
solr_doc[key] ||= [] | ||
solr_doc[key].push(*vals) | ||
end | ||
# asterisk to avoid multi-dimensional array: push values, not the array | ||
end | ||
|
||
# convert multivalued fields to single value | ||
%w[sw_pub_date_sort_ssi sw_pub_date_sort_isi sw_pub_date_facet_ssi].each do |key| | ||
solr_doc[key] = solr_doc[key].first unless solr_doc[key].nil? | ||
end | ||
# some fields get explicit "(none)" placeholder values, mostly for faceting | ||
%w[sw_language_tesim sw_genre_tesim sw_format_tesim].each do |key| | ||
solr_doc[key] = ['(none)'] if solr_doc[key].blank? | ||
end | ||
solr_doc | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# frozen_string_literal: true | ||
|
||
class EditableIndexer | ||
include SolrDocHelper | ||
|
||
attr_reader :resource | ||
def initialize(resource:) | ||
@resource = resource | ||
end | ||
|
||
def to_solr | ||
{}.tap do |solr_doc| | ||
add_solr_value(solr_doc, 'default_rights', default_rights_for_indexing, :string, [:symbol]) | ||
add_solr_value(solr_doc, 'agreement', resource.agreement, :string, [:symbol]) if resource.agreement_object | ||
add_solr_value(solr_doc, 'default_use_license_machine', resource.use_license, :string, [:stored_sortable]) | ||
end | ||
end | ||
|
||
# @return [String] A description of the rights defined in the default object rights datastream. Can be 'Stanford', 'World', 'Dark' or 'None' | ||
def default_rights_for_indexing | ||
Dor::RightsMetadataDS::RIGHTS_TYPE_CODES.fetch(resource.default_rights, 'Unrecognized default rights value') | ||
end | ||
end |
Oops, something went wrong.