Skip to content

Commit

Permalink
Add indexing service to index member ids, fixes #61
Browse files Browse the repository at this point in the history
  • Loading branch information
awead committed May 13, 2015
1 parent deb5f80 commit e0625e5
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 10 deletions.
2 changes: 2 additions & 0 deletions lib/hydra/pcdm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ module PCDM
autoload :CollectionBehavior, 'hydra/pcdm/models/concerns/collection_behavior'
autoload :ObjectBehavior, 'hydra/pcdm/models/concerns/object_behavior'

autoload :Indexer, 'hydra/pcdm/indexer'

def self.collection? collection
return false unless collection.respond_to? :type
collection.type.include? RDFVocabularies::PCDMTerms.Collection
Expand Down
12 changes: 12 additions & 0 deletions lib/hydra/pcdm/indexer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module Hydra::PCDM
class Indexer < ActiveFedora::IndexingService

def generate_solr_document
super.tap do |solr_doc|
solr_doc["objects_ssim"] = object.objects.map { |o| o.id }
solr_doc["collections_ssim"] = object.collections.map { |o| o.id } unless Hydra::PCDM.object?(object)
end
end

end
end
3 changes: 3 additions & 0 deletions lib/hydra/pcdm/models/concerns/collection_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ module CollectionBehavior
inserted_content_relation: RDF::Vocab::ORE.proxyFor, class_name: "ActiveFedora::Base",
through: 'ActiveFedora::Aggregation::Proxy', foreign_key: :target

def self.indexer
Hydra::PCDM::Indexer
end
end

# behavior:
Expand Down
4 changes: 4 additions & 0 deletions lib/hydra/pcdm/models/concerns/object_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ module ObjectBehavior

directly_contains :files, has_member_relation: RDFVocabularies::PCDMTerms.hasFile,
class_name: "Hydra::PCDM::File"

def self.indexer
Hydra::PCDM::Indexer
end
end


Expand Down
23 changes: 17 additions & 6 deletions spec/hydra/pcdm/models/collection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,22 @@ class Cullection < Hydra::PCDM::Collection
expect(collection1.collections).to eq []
end

it 'should only return collections' do
collection1.collections = [collection2,collection3]
collection1.objects = [object1,object2]
collection1.save
expect(collection1.collections).to eq [collection2,collection3]
end
context 'with other collections' do
before do
collection1.collections = [collection2,collection3]
collection1.objects = [object1,object2]
collection1.save
end
it 'should only return collections' do
expect(collection1.collections).to eq [collection2,collection3]
end
it 'should solrize member ids' do
expect(collection1.to_solr["objects_ssim"]).to include(object1.id,object2.id)
expect(collection1.to_solr["objects_ssim"]).not_to include(collection3.id,collection2.id)
expect(collection1.to_solr["collections_ssim"]).to include(collection3.id,collection2.id)
expect(collection1.to_solr["collections_ssim"]).not_to include(object1.id,object2.id)
end
end
end


Expand Down Expand Up @@ -258,4 +268,5 @@ class Awbject < Hydra::PCDM::Object
expect(collection.reload.related_objects).to eq [object]
end
end

end
17 changes: 13 additions & 4 deletions spec/hydra/pcdm/models/object_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,19 @@
expect(object1.objects).to eq [object2, object3]
end

xit 'should add a object to the objects aggregation' do
context 'when aggregating other objects' do
before do
object1.objects = [object2, object3]
object1.save
end
subject { object1.objects }
it { is_expected.to eq [object2, object3] }
it 'solrizes member ids' do
expect(object1.to_solr["objects_ssim"]).to include(object3.id, object2.id)
end
end

xit 'should add an object to the objects aggregation' do
object1.objects = [object2,object3]
object1.save
object1.objects << object4
Expand Down Expand Up @@ -151,9 +163,6 @@ class DummyExtObject < Hydra::PCDM::Object
end

describe 'Related objects' do
let(:object1) { Hydra::PCDM::Object.create }
let(:object2) { Hydra::PCDM::Object.create }

before do
object1.related_objects = [object2]
object1.save
Expand Down

0 comments on commit e0625e5

Please sign in to comment.