From f6ce7ab99379f03dd0cd00257a5211dc5d0bb538 Mon Sep 17 00:00:00 2001 From: Eddie Rubeiz Date: Wed, 18 Dec 2024 15:30:53 -0500 Subject: [PATCH] using a text field for box and folder --- app/controllers/catalog_controller.rb | 17 +++++++++++++++++ app/indexers/work_indexer.rb | 6 ++++++ solr/config/schema.xml | 6 ++++++ spec/indexers/work_indexer_spec.rb | 26 ++++++++++++++++++++++++++ 4 files changed, 55 insertions(+) diff --git a/app/controllers/catalog_controller.rb b/app/controllers/catalog_controller.rb index d56eb8737..799202132 100644 --- a/app/controllers/catalog_controller.rb +++ b/app/controllers/catalog_controller.rb @@ -361,6 +361,23 @@ def active_sort_fields # case for a BL "search field", which is really a dismax aggregate # of Solr search fields. + + # See https://github.com/sciencehistory/scihist_digicoll/issues/2585 + # Note that a Work can be associated with two consecutive boxes, in which case the box number is something like "34-35". + config.add_search_field('box') do |field| + field.label = 'Box' + field.solr_parameters = { + qf: 'box_tsi', + } + end + + config.add_search_field('folder') do |field| + field.label = 'Folder' + field.solr_parameters = { + qf: 'folder_tsi', + } + end + # config.add_search_field('title') do |field| # # solr_parameters hash are sent to Solr as ordinary url query params. # field.solr_parameters = { diff --git a/app/indexers/work_indexer.rb b/app/indexers/work_indexer.rb index 9d6b56ca6..bea23b3c1 100644 --- a/app/indexers/work_indexer.rb +++ b/app/indexers/work_indexer.rb @@ -61,6 +61,12 @@ class WorkIndexer < Kithe::Indexer acc.concat(DateIndexHelper.new(record).expanded_years) end + to_field "box_tsi", obj_extract("physical_container"), transform( ->(v) { v.box if v.box.present? }) + to_field "folder_tsi", obj_extract("physical_container"), transform( ->(v) { v.folder if v.folder.present? }) + to_field "box_sort", obj_extract("physical_container"), transform( ->(v) { v.box[/\d+/] if v.box.present? }) + to_field "folder_sort", obj_extract("physical_container"), transform( ->(v) { v.folder[/\d+/] if v.folder.present? }) + + # For sorting by oldest first to_field "earliest_date" do |record, acc| # for Solr, we need in "xml schema" format, with 00:00:00 time, and UTC timezone diff --git a/solr/config/schema.xml b/solr/config/schema.xml index 0f5166959..2a8d48676 100644 --- a/solr/config/schema.xml +++ b/solr/config/schema.xml @@ -257,6 +257,12 @@ + + + + + +