Skip to content

Commit

Permalink
Move indexing to the indexer. Fixes #202
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Aug 27, 2015
1 parent 7d698dc commit f72ca99
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,5 @@ def human_readable_type
def representative
to_param
end

def to_solr(solr_doc = {})
super(solr_doc).tap do |doc|
# Enables Riiif to not have to recalculate this each time.
doc['height_isi'] = Integer(height.first) if height.present?
doc['width_isi'] = Integer(width.first) if width.present?
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ def generate_solr_document
solr_doc[Solrizer.solr_name(:file_size, :symbol)] = object.file_size[0]
solr_doc['all_text_timv'] = object.full_text.content
solr_doc[Solrizer.solr_name('generic_work_ids', :symbol)] = object.generic_work_ids unless object.generic_work_ids.empty?
solr_doc['height_is'] = Integer(object.height.first) if object.height.present?
solr_doc['width_is'] = Integer(object.width.first) if object.width.present?
end
end
end
Expand Down
15 changes: 6 additions & 9 deletions spec/models/generic_file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -369,18 +369,15 @@ def paranoid_edit_permissions
end

describe 'to_solr' do
let(:indexer) { double }
before do
subject.title = ['One Flew Over the Cuckoo\'s Nest']
subject.characterization.height = '500'
subject.characterization.width = '600'
allow(CurationConcerns::GenericFileIndexingService).to receive(:new)
.with(subject).and_return(indexer)
end
let(:solr_doc) { subject.to_solr }

it 'has a solr_doc' do
expect(solr_doc['title_tesim']).to eq ['One Flew Over the Cuckoo\'s Nest']
expect(solr_doc['title_sim']).to eq ['One Flew Over the Cuckoo\'s Nest']
expect(solr_doc['height_isi']).to eq 500
expect(solr_doc['width_isi']).to eq 600
it 'calls the indexer' do
expect(indexer).to receive(:generate_solr_document)
subject.to_solr
end
end

Expand Down
4 changes: 4 additions & 0 deletions spec/services/generic_file_indexing_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
mime_type: 'image/jpeg',
format_label: ['JPEG Image']) do |gf|
gf.full_text.content = 'abcxyz'
gf.characterization.height = '500'
gf.characterization.width = '600'
end
end

Expand Down Expand Up @@ -53,6 +55,8 @@
expect(subject[Solrizer.solr_name('based_near')]).to eq ['Medina, Saudi Arabia']
expect(subject[Solrizer.solr_name('mime_type')]).to eq ['image/jpeg']
expect(subject['all_text_timv']).to eq('abcxyz')
expect(subject['height_is']).to eq 500
expect(subject['width_is']).to eq 600
end
end
end

0 comments on commit f72ca99

Please sign in to comment.