Skip to content

Commit

Permalink
index valkyrie work attributes consistent with AF
Browse files Browse the repository at this point in the history
### Background

Most attributes for Hyrax::Work are defined using `Hyrax::Schema` includes.  A few are defined with `attribute` statements.  Some of these attributes were indexed by ActiveFedora.  Adding in indexing for these to be consistent with ActiveFedora’s indexing.

Indexed in AF, but not in ValkyrieWorkIndexer…
* generic_type_sim
* file_set_ids_ssim

Defined as attribute in Hyrax::Work, but not indexed
* on_behalf_of
* proxy_depositor
* state

Looking for confirmation on how to handle these.

### Related Work

Issue #4487 - Solr docs generated by ActiveFedora and Hyrax::ValkyrieWorkIndexer are not compatible
  • Loading branch information
elrayle committed Oct 1, 2020
1 parent 940e100 commit 1c6b56b
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
32 changes: 32 additions & 0 deletions app/indexers/hyrax/valkyrie_work_indexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,37 @@ class ValkyrieWorkIndexer < Hyrax::ValkyrieIndexer
include Hyrax::PermissionIndexer
include Hyrax::VisibilityIndexer
include Hyrax::Indexer(:core_metadata)

def to_solr # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
super.tap do |solr_doc|
admin_set_label = admin_set_label(resource.admin_set_id)
solr_doc['admin_set_sim'] = admin_set_label
solr_doc['admin_set_tesim'] = admin_set_label
solr_doc['member_ids_ssim'] = resource.member_ids
solr_doc['member_of_collections_ssim'] = collection_labels(resource.member_of_collection_ids)
solr_doc['member_of_collection_ids_ssim'] = resource.member_of_collection_ids

# solr_doc['on_behalf_of'] = ''
# solr_doc['proxy_depositor'] = ''
# solr_doc['state'] = ''

# solr_doc['generic_type_sim'] = ['Work']

# This enables us to return a Work when we have a FileSet that matches
# the search query. While at the same time allowing us not to return Collections
# when a work in the collection matches the query.
# solr_doc['file_set_ids_ssim'] = solr_doc['member_ids_ssim'] # TODO: Doesn't this return child works too?
end

private

def admin_set_label(id)
Hyrax.query_service.find_by(id: id).title
end

def collection_labels(ids)
Hyrax.query_service.find_many_by_ids(ids: ids)&.map(&:first_title)
end
end
end
end
16 changes: 16 additions & 0 deletions spec/indexers/hyrax/valkyrie_work_indexer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,20 @@ def to_solr

it_behaves_like 'a Work indexer'
end

describe '#to_solr' do
let(:admin_set_title) { 'An Admin Set' }
let(:admin_set) { create(:admin_set, title: admin_set_title) }
let(:collection_title) { 'A Collection' }
let(:col1) { valkyrie_create(:hyrax_collection, title: collection_title)}
let(:work) { valkyrie_create(:hyrax_work, :with_member_works, member_of_collection_ids: [col1.id], admin_set_id: admin_set.id) }

it 'includes attributes defined outside Hyrax::Schema include' do
expect(solr_document.fetch('admin_set_sim')).to eq admin_set_title
expect(solr_document.fetch('admin_set_tesim')).to eq admin_set_title
expect(solr_document.fetch('member_ids_ssim')).to match_array work.member_ids
expect(solr_document.fetch('member_of_collections_ssim')).to match_array [collection_title]
expect(solr_document.fetch('member_of_collection_ids_ssim')).to match_array [col1.id]
end
end
end

0 comments on commit 1c6b56b

Please sign in to comment.