Skip to content

Commit

Permalink
Update field used for collections in a backwards compatible way, sort…
Browse files Browse the repository at this point in the history
…able A-Z
  • Loading branch information
mejackreed committed May 4, 2018
1 parent 4515b8f commit a09cb94
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 8 deletions.
7 changes: 5 additions & 2 deletions app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,10 @@ 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
Expand Down Expand Up @@ -209,7 +212,7 @@ class CatalogController < ApplicationController
# This was added for the Feigbenbaum exhibit. It includes any general <note> 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
Expand Down
4 changes: 2 additions & 2 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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:, **)
Expand Down
3 changes: 3 additions & 0 deletions lib/traject/dor_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion solr/config/schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,10 @@
<field name="modsxml" type="string" indexed="false" stored="true" />
<!-- collection (facet and display): "sirsi" or, for DOR items, the id of their parent coll -->
<field name="collection" type="string" indexed="true" stored="true" multiValued="true" omitNorms="true" />
<!-- collection_with_title: easy way to indicate item's parent coll title in UI (may be deprecated in future) -->
<!-- DEPRECATED: collection_with_title: easy way to indicate item's parent coll title in UI (may be deprecated in future) -->
<field name="collection_with_title" type="string" indexed="true" stored="true" multiValued="true" />
<!-- collection_leading_title: easy way to indicate item's parent coll title in UI, sortable by A-Z (may be deprecated in future) -->
<field name="collection_leading_title" type="string" indexed="true" stored="true" multiValued="true" />
<!-- collection_search: allow searching within collections for aggr. colls -->
<field name="collection_search" type="string_punct_stop" indexed="true" stored="true" multiValued="true" omitNorms="true" />
<!-- display_type: used by UI code, e.g. 'file' or 'image' -->
Expand Down
2 changes: 2 additions & 0 deletions solr/config/solrconfig.xml
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,7 @@
<str name="facet.field">pub_year_tisim</str>
<str name="facet.field">topic_facet</str>
<str name="facet.field">collection_with_title</str>
<str name="facet.field">collection_leading_title</str>

<!-- Highlighting defaults -->
<str name="hl.fl">all_search full_text_search full_text_search_en full_text_search_pt full_text_search_id</str>
Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions spec/features/indexing_integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions spec/fixtures/sample_solr_docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
6 changes: 3 additions & 3 deletions spec/helpers/application_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
describe ApplicationHelper, type: :helper do
describe '#collection_title' do
it 'unmangles the collection title from the compound field' do
expect(helper.collection_title('foo-|-bar')).to eq 'bar'
expect(helper.collection_title('foo-|-bar')).to eq 'foo'
end
end

describe '#collection_title_for_index_field' do
it 'unmangles the collection title from the compound field' do
expect(helper.document_collection_title(value: 'foo-|-bar')).to eq 'bar'
expect(helper.document_collection_title(value: 'foo-|-bar')).to eq 'foo'
end

it 'handles multivalued fields' do
expect(helper.document_collection_title(value: ['foo-|-bar', 'baz-|-bop'])).to eq 'bar and bop'
expect(helper.document_collection_title(value: ['foo-|-bar', 'baz-|-bop'])).to eq 'foo and baz'
end
end

Expand Down

0 comments on commit a09cb94

Please sign in to comment.