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

Commit

Permalink
Indexing collection slug - closes #332
Browse files Browse the repository at this point in the history
  • Loading branch information
escowles committed Jan 11, 2016
1 parent 2453bf3 commit e3129cb
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class CatalogController < ApplicationController
self.search_params_logic += [:hide_parented_resources, :join_from_parent]
def self.search_config
{
'qf' => %w(title_tesim name_tesim source_metadata_identifier_ssim logical_order_headings_tesim),
'qf' => %w(title_tesim name_tesim source_metadata_identifier_ssim logical_order_headings_tesim collection_slug_sim),
'qt' => 'search',
'rows' => 10
}
Expand Down
5 changes: 4 additions & 1 deletion app/models/multi_volume_work.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ class MultiVolumeWork < ActiveFedora::Base

def to_solr(solr_doc = {})
super.tap do |doc|
doc[ActiveFedora::SolrQueryBuilder.solr_name("collection", :facetable)] = in_collections.collect(&:title)
in_collections.each do |col|
doc[ActiveFedora::SolrQueryBuilder.solr_name("collection", :facetable)] = col.title
doc[ActiveFedora::SolrQueryBuilder.solr_name("collection_slug", :facetable)] = col.exhibit_id
end
end
end
end
5 changes: 4 additions & 1 deletion app/models/scanned_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ def to_solr(solr_doc = {})
doc[ActiveFedora::SolrQueryBuilder.solr_name("ordered_by", :symbol)] += send(:ordered_by_ids)
doc[ActiveFedora::SolrQueryBuilder.solr_name("logical_order", :symbol)] = [logical_order.order.to_json]
doc[ActiveFedora::SolrQueryBuilder.solr_name("logical_order_headings", :stored_searchable)] = logical_order.object.each_section.map(&:label)
doc[ActiveFedora::SolrQueryBuilder.solr_name("collection", :facetable)] = in_collections.map(&:title)
in_collections.each do |col|
doc[ActiveFedora::SolrQueryBuilder.solr_name("collection", :facetable)] = col.title
doc[ActiveFedora::SolrQueryBuilder.solr_name("collection_slug", :facetable)] = col.exhibit_id
end
end
end

Expand Down
19 changes: 15 additions & 4 deletions spec/controllers/catalog_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,22 @@

expect(document_ids).to eq [resource.id]
end
end

describe "resources in collections" do
it "finds resources in a collection by the collection's slug" do
resource = FactoryGirl.create(:scanned_resource_in_collection)
resource.save

get :index, q: "slug1"

expect(document_ids).to eq [resource.id]
end
end

def document_ids
assigns[:document_list].map do |x|
x["id"]
end
def document_ids
assigns[:document_list].map do |x|
x["id"]
end
end
end
9 changes: 9 additions & 0 deletions spec/models/scanned_resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -357,4 +357,13 @@
expect(subject.reload.logical_order.order).to eq params2.with_indifferent_access
end
end

describe "collection indexing" do
let(:scanned_resource) { FactoryGirl.create(:scanned_resource_in_collection) }
let(:solr_doc) { scanned_resource.to_solr }
it "indexes collection" do
expect(solr_doc['collection_sim']).to eq('Test Collection')
expect(solr_doc['collection_slug_sim']).to eq('slug1')
end
end
end

0 comments on commit e3129cb

Please sign in to comment.