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

Commit

Permalink
Search by section headings.
Browse files Browse the repository at this point in the history
  • Loading branch information
Trey Terrell committed Jan 8, 2016
1 parent 228c573 commit 3eb41fd
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 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),
'qf' => %w(title_tesim name_tesim source_metadata_identifier_ssim logical_order_headings_tesim),
'qt' => 'search',
'rows' => 10
}
Expand Down
2 changes: 1 addition & 1 deletion app/models/scanned_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def to_solr(solr_doc = {})
doc[ActiveFedora::SolrQueryBuilder.solr_name("ordered_by", :symbol)] ||= []
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", :symbol)] = logical_order.object.each_section.map(&:label)
doc[ActiveFedora::SolrQueryBuilder.solr_name("logical_order_headings", :stored_searchable)] = logical_order.object.each_section.map(&:label)
end
end

Expand Down
16 changes: 16 additions & 0 deletions spec/controllers/catalog_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,22 @@
expect(document_ids).to eq [resource.id]
end

it "finds items by their section headings" do
resource = FactoryGirl.build(:scanned_resource)
resource.logical_order.order = {
"nodes": [
{
"label": "The Doctor's Tales"
}
]
}
resource.save!

get :index, q: "Tales"

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

def document_ids
assigns[:document_list].map do |x|
x["id"]
Expand Down
4 changes: 2 additions & 2 deletions spec/models/scanned_resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -320,14 +320,14 @@
it "indexes the headings into the solr record" do
subject.logical_order.order = params2

expect(subject.to_solr["logical_order_headings_ssim"]).to eq [
expect(subject.to_solr["logical_order_headings_tesim"]).to eq [
"Chapter 1",
"Chapter 2",
"Chapter 2b"
]
end
it "can index even without order" do
expect(subject.to_solr["logical_order_headings_ssim"]).to eq []
expect(subject.to_solr["logical_order_headings_tesim"]).to eq []
end
it "survives persistence" do
subject.logical_order.order = params
Expand Down

0 comments on commit 3eb41fd

Please sign in to comment.