Skip to content

Commit

Permalink
merging
Browse files Browse the repository at this point in the history
  • Loading branch information
eddierubeiz committed Dec 20, 2024
2 parents 63dfa6a + fd73917 commit b22d51b
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 73 deletions.
4 changes: 2 additions & 2 deletions app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -367,14 +367,14 @@ def active_sort_fields
config.add_search_field('box') do |field|
field.label = 'Box'
field.solr_parameters = {
qf: 'box_isim',
qf: 'box_tsi',
}
end

config.add_search_field('folder') do |field|
field.label = 'Folder'
field.solr_parameters = {
qf: 'folder_isim',
qf: 'folder_tsi',
}
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/collection_show_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def blacklight_config

config.add_sort_field("box_folder") do |field|
field.label = "box and folder"
field.sort = "box_isim asc, folder_isim asc"
field.sort = "box_sort asc, folder_sort asc, title asc"
end
end

Expand Down
3 changes: 1 addition & 2 deletions app/frontend/stylesheets/local/scihist_viewer.scss
Original file line number Diff line number Diff line change
Expand Up @@ -364,13 +364,12 @@ $scihist_image_viewer_thumb_width: 54px; // Needs to match ImageServiceHelper::T
padding: $btn-padding-y-lg $btn-padding-x-lg;

border: 1px solid $primary;
max-width: unset;
flex-grow: 4;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
text-align: left;

text-transform: uppercase;
}
.viewer-spacer {
width: 0;
Expand Down
16 changes: 4 additions & 12 deletions app/indexers/work_indexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,10 @@ class WorkIndexer < Kithe::Indexer
acc.concat(DateIndexHelper.new(record).expanded_years)
end

# Note that a Work can be associated with two consecutive containers,
# in which case e.g. the box number can be something like "34-35".
# Searches for box 35 should match any work that is associated with box 35.
to_field "box_isim" do |record, acc|
val = record&.physical_container&.box
acc.concat val.scan(/\d+/) if val.present?
end

to_field "folder_isim" do |record, acc|
val = record&.physical_container&.folder
acc.concat val.scan(/\d+/) if val.present?
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|
Expand Down
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
"vite-plugin-ruby": "^5.1.0",
"vite-plugin-sass-glob-import": "^3.0.2"
},
"resolutions": {
"blacklight-frontend/bootstrap": "^4.6.2"
},
"browserslist": [
"defaults"
],
Expand Down
6 changes: 6 additions & 0 deletions solr/config/schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,12 @@
<field name="latest_date" type="date_sortmissinglast" stored="true" indexed="true" multiValued="false"/>
<field name="earliest_date" type="date_sortmissinglast" stored="true" indexed="true" multiValued="false"/>


<!-- Box and folder sort fields. Added by Science History Institute. -->
<field name="box_sort" type="int_sortmissinglast" stored="true" indexed="true" multiValued="false"/>
<field name="folder_sort" type="int_sortmissinglast" stored="true" indexed="true" multiValued="false"/>


<!-- Single-value title sort field. Used to sort collections of serials by title.
See https://github.com/sciencehistory/scihist_digicoll/issues/2494
If we can use the first value of (multivalued) text1_tesim instead, let's consider doing that.
Expand Down
61 changes: 40 additions & 21 deletions spec/controllers/collection_show_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,30 +118,49 @@
end
end


describe "box and folder order" do
let(:requested_sort_order) { 'box_and_folder' }

let(:physical_containers) {[
Work::PhysicalContainer.new({ "box"=> "1", "folder"=> "1" }),
Work::PhysicalContainer.new({ "box"=> "2", "folder"=> "1" }),
Work::PhysicalContainer.new({ "box"=> "2", "folder"=> "2" }),
Work::PhysicalContainer.new({ "box"=> "3", "folder"=> "1" }),
Work::PhysicalContainer.new({ "box"=> "3", "folder"=> "2" }),
Work::PhysicalContainer.new({ "box"=> "3", "folder"=> "3-4"}),
Work::PhysicalContainer.new({ "box"=> "3", "folder"=> "5" })
]}

let!(:works) {
(0..6).to_a.map do |i|
create(:work, contained_by: [collection],
title: i, physical_container: physical_containers[i])
end.shuffle
}

let(:random_order) { (0..containers.length - 1).to_a.shuffle }

let(:containers) do
[
{ "box"=> "1", "folder"=> "1" },
{ "box"=> "1" },

{ "box"=> "2", "folder"=> "1" },
{ "box"=> "2", "folder"=> "2" },

{ "box"=> "3", "folder"=> "1" },
{ "box"=> "3", "folder"=> "2" },
{ "box"=> "3-5", "folder"=> "6-4"},

# Non-integer containers go at the end.
{ "folder"=> "1" },
{ "box"=> "??", "folder"=> "goat"},
{ }
]
end


let(:titles) do
containers.map do |pc|
"#{pc.try('box', 'none')},#{pc.try('folder', 'none')}"
end
end

let!(:works) do
random_order.map do |i|
create( :work,
title: titles[i],
physical_container: Work::PhysicalContainer.new(containers[i]),
contained_by: [collection]
)
end
end

it "can sort by box and folder" do
get :index, params: {"q"=>"", "sort"=>"box_and_folder", "collection_id"=> collection.friendlier_id }
expect(titles_as_displayed).to eq (0..6).map &:to_s
get :index, params: {"q"=>"", "sort"=>"box_folder", "collection_id"=> collection.friendlier_id }
expect(titles_as_displayed).to eq titles
end
end

Expand Down
47 changes: 21 additions & 26 deletions spec/indexers/work_indexer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,32 +43,27 @@

# See https://github.com/sciencehistory/scihist_digicoll/issues/2585
describe "box and folder" do
let(:container_info) do
Work::PhysicalContainer.new({"box"=>"1", "folder"=>"3"})
end
let(:work_2) { create(:work, physical_container: container_info) }

it "does not index this metadata unless there are digits" do
output_hash = WorkIndexer.new.map_record(work)
expect(output_hash["box_isim"]).to eq nil
expect(output_hash["folder_isim"]).to eq nil
end

it "indexes the box and folder" do
output_hash = WorkIndexer.new.map_record(work_2)
expect(output_hash["box_isim"]).to eq ["1"]
expect(output_hash["folder_isim"]).to eq ["3"]
end

describe "more than one box or folder associated with the work" do
let(:container_info) do
Work::PhysicalContainer.new({"box"=>"1 - 2", "folder"=>"3 - 4"})
end
it "splits multiple boxes / folders into two integers so they can be matched" do
output_hash = WorkIndexer.new.map_record(work_2)
expect(output_hash["box_isim"]).to eq ["1", "2"]
expect(output_hash["folder_isim"]).to eq ["3", "4"]
end
let(:box_search_field) {'box_tsi'}
let(:box_sort_field) {'box_sort'}
let(:folder_search_field) {'folder_tsi'}
let(:folder_sort_field) {'folder_sort'}

let(:work_2) { create(:work, physical_container: Work::PhysicalContainer.new({"box"=>"1", "folder"=>"3"})) }
let(:work_3) { create(:work, physical_container: Work::PhysicalContainer.new({"box"=>"12, 34, 56", "folder"=>"56, 78, 10"})) }
let(:output_hash) { WorkIndexer.new.map_record(work) }
let(:output_hash_2) { WorkIndexer.new.map_record(work_2) }
let(:output_hash_3) { WorkIndexer.new.map_record(work_3) }

it "puts the first consecutive digits, if found, into the sort fields, and everything into the search fields" do
expect(output_hash[box_search_field]).to eq ['Box']
expect(output_hash[folder_search_field]).to eq ['Folder']
expect(output_hash[box_sort_field]).to be_nil
expect(output_hash[folder_sort_field]).to be_nil

expect(output_hash_3[box_search_field]).to eq ['12, 34, 56']
expect(output_hash_3[folder_search_field]).to eq ['56, 78, 10']
expect(output_hash_3[box_sort_field]).to eq ['12']
expect(output_hash_3[folder_sort_field]).to eq ['56']
end
end

Expand Down
7 changes: 1 addition & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -379,12 +379,7 @@ blacklight-range-limit@9.0.0-beta2:
dependencies:
chart.js "^ 4.4.1"

"bootstrap@>=4.3.1 <6.0.0", bootstrap@^4.6.2:
version "4.6.2"
resolved "https://registry.yarnpkg.com/bootstrap/-/bootstrap-4.6.2.tgz#8e0cd61611728a5bf65a3a2b8d6ff6c77d5d7479"
integrity sha512-51Bbp/Uxr9aTuy6ca/8FbFloBUJZLHwnhTcnjIeRn2suQWsWzcuJhGjKDB5eppVte/8oCdOL3VuwxvZDUggwGQ==

"bootstrap@^ 5.0.0":
"bootstrap@>=4.3.1 <6.0.0", "bootstrap@^ 5.0.0":
version "5.3.3"
resolved "https://registry.yarnpkg.com/bootstrap/-/bootstrap-5.3.3.tgz#de35e1a765c897ac940021900fcbb831602bac38"
integrity sha512-8HLCdWgyoMguSO9o+aH+iuZ+aht+mzW0u3HIMzVu7Srrpv7EBBxTnrFlSCskwdY1+EOFQSm7uMJhNQHkdPcmjg==
Expand Down

0 comments on commit b22d51b

Please sign in to comment.