Skip to content
This repository has been archived by the owner on May 14, 2022. It is now read-only.

Commit

Permalink
Index Category.
Browse files Browse the repository at this point in the history
  • Loading branch information
tpendragon committed May 10, 2017
1 parent 48914e3 commit 87478b1
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
6 changes: 6 additions & 0 deletions app/indexers/work_indexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ def generate_solr_document
authority.find(code)[:label] if authority
end.compact
end
subject_authority = AuthorityFinder.for(property: :subject, model: object)
if subject_authority
solr_doc[Solrizer.solr_name("category", :facetable)] = object.send(:subject).map do |code|
subject_authority.find(code)[:vocabulary] if subject_authority
end.compact
end
solr_doc[Solrizer.solr_name("language", :facetable)] = object.language.map do |code|
AuthorityFinder.for(property: :language, model: object).try(:find, code).try(:[], :label) || LanguageService.label(code)
end
Expand Down
6 changes: 5 additions & 1 deletion app/models/vocabulary_subauthority.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ def sub_vocabs
Vocabulary.where(parent_id: @vocabulary.id).to_a
end

def vocabulary(item)
item.try(:vocabulary) || item.try(:parent)
end

def format_item(item)
{ id: item.id, label: item.label, type: item.class.name, active: true }.with_indifferent_access
{ id: item.id, label: item.label, type: item.class.name, vocabulary: vocabulary(item).try(:label), active: true }.with_indifferent_access
end
end
1 change: 1 addition & 0 deletions spec/models/ephemera_folder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
let(:folder) { FactoryGirl.build(:ephemera_folder, subject: [VocabularyTerm.first.id.to_s]) }
it "Returns the label for the IDs" do
expect(folder.to_solr["subject_sim"]).to eq ["English"]
expect(folder.to_solr["category_sim"]).to eq ["Test"]
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions spec/models/vocabulary_subauthority_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
subject { described_class.new(parent.label) }

it 'lists terms and vocabularies' do
child_hash = { id: child.id, label: child.label, type: child.class.name, active: true }.with_indifferent_access
term_hash = { id: term.id, label: term.label, type: term.class.name, active: true }.with_indifferent_access
child_hash = { id: child.id, label: child.label, type: child.class.name, vocabulary: 'Parent Vocabulary', active: true }.with_indifferent_access
term_hash = { id: term.id, label: term.label, type: term.class.name, vocabulary: 'Parent Vocabulary', active: true }.with_indifferent_access
expect(subject.all).to contain_exactly(child_hash, term_hash)
end

it 'finds terms by their ids' do
term_hash = { id: term.id, label: term.label, type: term.class.name, active: true }.with_indifferent_access
term_hash = { id: term.id, label: term.label, type: term.class.name, vocabulary: 'Parent Vocabulary', active: true }.with_indifferent_access
expect(subject.find(term.id)).to eq(term_hash)
end
end

0 comments on commit 87478b1

Please sign in to comment.