From 3f76edb30b4fc4540a28137e09803b51ce30c58a Mon Sep 17 00:00:00 2001 From: Jack Reed Date: Fri, 4 May 2018 16:29:28 -0600 Subject: [PATCH] Update field used for collections in a backwards compatible way, sortable A-Z --- app/controllers/catalog_controller.rb | 4 ++-- app/helpers/application_helper.rb | 4 ++-- lib/traject/dor_config.rb | 3 +++ solr/config/schema.xml | 4 +++- solr/config/solrconfig.xml | 2 ++ spec/features/indexing_integration_spec.rb | 1 + spec/fixtures/sample_solr_docs.json | 1 + 7 files changed, 14 insertions(+), 5 deletions(-) diff --git a/app/controllers/catalog_controller.rb b/app/controllers/catalog_controller.rb index 9528706f6..4220ee40d 100644 --- a/app/controllers/catalog_controller.rb +++ b/app/controllers/catalog_controller.rb @@ -149,7 +149,7 @@ class CatalogController < ApplicationController config.add_facet_field 'folder_name_ssi', label: 'Folder Name', limit: true config.add_facet_field 'donor_tags_ssim', label: 'Donor tags', limit: true config.add_facet_field 'doc_subtype_ssi', label: 'Document Subtype', limit: true - config.add_facet_field 'collection_with_title', label: 'Collection', limit: true, helper_method: :collection_title + config.add_facet_field 'collection_leading_title', label: 'Collection', limit: true, helper_method: :collection_title # Have BL send all facet field names to Solr, which has been the default # previously. Simply remove these lines if you'd rather use Solr request @@ -209,7 +209,7 @@ class CatalogController < ApplicationController # This was added for the Feigbenbaum exhibit. It includes any general from # the MODs that do not have attributes. It is used for display and is not facetable. config.add_index_field 'general_notes_ssim', label: 'Notes', helper_method: :notes_wrap - config.add_index_field 'collection_with_title', label: 'Collection', helper_method: :document_collection_title + config.add_index_field 'collection_leading_title', label: 'Collection', helper_method: :document_collection_title # Fields specific to Parker Exhibit config.add_index_field 'incipit_tesim', label: 'Incipit' config.add_index_field 'toc_search', label: 'Table of contents', helper_method: :table_of_contents_separator diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index b119e4ace..b5bd48bc2 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -2,10 +2,10 @@ # :nodoc: module ApplicationHelper - # Collection titles are indexed as a compound druid + title; we need to + # Collection titles are indexed as a compound title + druid; we need to # unmangle it for display. def collection_title(value, separator: '-|-') - value.split(separator).last + value.split(separator).first end def document_collection_title(value:, **) diff --git a/lib/traject/dor_config.rb b/lib/traject/dor_config.rb index 5de48eeb0..8c7a27a68 100644 --- a/lib/traject/dor_config.rb +++ b/lib/traject/dor_config.rb @@ -20,6 +20,9 @@ to_field 'display_type', conditional(->(resource, *_) { !resource.collection? }, accumulate { |resource, *_| display_type(dor_content_type(resource)) }) to_field 'collection', (accumulate { |resource, *_| resource.collections.map(&:bare_druid) }) +to_field 'collection_leading_title', (accumulate do |resource, *_| + resource.collections.map { |collection| "#{coll_title(collection)}-|-#{collection.bare_druid}" } +end) to_field 'collection_with_title', (accumulate do |resource, *_| resource.collections.map { |collection| "#{collection.bare_druid}-|-#{coll_title(collection)}" } end) diff --git a/solr/config/schema.xml b/solr/config/schema.xml index f967bd0bf..8cc0a2bdb 100644 --- a/solr/config/schema.xml +++ b/solr/config/schema.xml @@ -216,8 +216,10 @@ - + + + diff --git a/solr/config/solrconfig.xml b/solr/config/solrconfig.xml index d6aeca29d..58ac314a3 100644 --- a/solr/config/solrconfig.xml +++ b/solr/config/solrconfig.xml @@ -810,6 +810,7 @@ pub_year_tisim topic_facet collection_with_title + collection_leading_title all_search full_text_search full_text_search_en full_text_search_pt full_text_search_id @@ -823,6 +824,7 @@ author_person_full_display, vern_author_person_full_display, collection, collection_type, + collection_leading_title, collection_with_title, crez_course_info, db_az_subject, diff --git a/spec/features/indexing_integration_spec.rb b/spec/features/indexing_integration_spec.rb index e22093594..c0b844747 100644 --- a/spec/features/indexing_integration_spec.rb +++ b/spec/features/indexing_integration_spec.rb @@ -123,6 +123,7 @@ it 'has collection information' do expect(document).to include collection: ['ms016pb9280'], + collection_leading_title: ['Edward A. Feigenbaum papers, 1950-2007 (inclusive)-|-ms016pb9280'], collection_with_title: ['ms016pb9280-|-Edward A. Feigenbaum papers, 1950-2007 (inclusive)'], collection_titles_ssim: ['Edward A. Feigenbaum papers, 1950-2007 (inclusive)'] end diff --git a/spec/fixtures/sample_solr_docs.json b/spec/fixtures/sample_solr_docs.json index bf8b5effe..a32117fee 100644 --- a/spec/fixtures/sample_solr_docs.json +++ b/spec/fixtures/sample_solr_docs.json @@ -2748,6 +2748,7 @@ "spotlight_resource_id_ssim": null, "spotlight_resource_type_ssim": "dor_harvesters", "collection": ["ms016pb9280"], + "collection_leading_title": ["ms016pb9280-|-Edward A. Feigenbaum papers, 1950-2007 (inclusive)"], "collection_with_title": ["Edward A. Feigenbaum papers, 1950-2007 (inclusive)-|-ms016pb9280"], "author_person_facet": ["A. Rosenfeld"], "author_person_display": ["A. Rosenfeld"],