Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/qa.env
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ENCRYPTED_ELASTICSEARCH_URI=AQECAHh7ea2tyZ6phZgT4B9BDKwguhlFtRC6hgt+7HbmeFsrsgAAAJYwgZMGCSqGSIb3DQEHBqCBhTCBggIBADB9BgkqhkiG9w0BBwEwHgYJYIZIAWUDBAEuMBEEDPOwtMEINT56sYXZfwIBEIBQNwCWEB5HLfhE4rcjNfW03vrsHrR0gNP2PsHGAnpsYCE+GvmhpehhmFcixI94gJfzfose4bgzQx1sc2WRpy/nP13H+s37w5SZhCHUEf/6Lg4=
RESOURCES_INDEX=resources-qa-2026-07-14
RESOURCES_INDEX=resources-qa-2026-08-25
BROWSE_INDEX=browse-qa-2026-01-15
ENCRYPTED_ELASTICSEARCH_API_KEY=AQECAHh7ea2tyZ6phZgT4B9BDKwguhlFtRC6hgt+7HbmeFsrsgAAAJ4wgZsGCSqGSIb3DQEHBqCBjTCBigIBADCBhAYJKoZIhvcNAQcBMB4GCWCGSAFlAwQBLjARBAwB1VWJWKAwIiCKyOgCARCAV9Chp9ALDDtlbXm3S5Lo251SevwcHYpG+cUxFvu2O0mA6mxA4x9ZbDDlT1gK6/SaMSB7AKll8BrJxSkBwTZiyaihVPGLC+PS1lejtBGisxEGo2pt3QlY8Q==

Expand Down
22 changes: 9 additions & 13 deletions lib/display-field-unpacker.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
const parseValueAndLabel = (delimitedString) => {
if (!delimitedString.includes('||')) {
return { value: delimitedString, display: null }
}
const [value, display] = delimitedString.split('||')
return { value, display }
}
// name+title is used for search links, name for browse links, label for full display
const toDisplayField = ({ name, title, label }) => ({
displayLabel: label,
name,
nameTitle: title ? `${name} ${title}` : name

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there not always a period between name and title? getting back to our convo from yesterday.

})

module.exports = (elasticSearchResponse) => {
elasticSearchResponse.hits.hits.forEach((bib) => {
// Contributors and creators are packed like so <name>||<display label> where <display label>
// can have prefix, title, and roles. We'd like to unpack them in a friendly format for the frontend
// to display the full label and use the isolated name for link-building
Object.entries(bib._source).forEach(([key, value]) => {
if (key.endsWith('_displayPacked')) {
const fieldName = key.replace('_displayPacked', '')
bib._source[fieldName + 'Display'] = value.map((packedValue) => parseValueAndLabel(packedValue))
if (key.endsWith('_displayComponents')) {
const fieldName = key.replace('_displayComponents', '')
bib._source[fieldName + 'Display'] = value.map(toDisplayField)
delete bib._source[key]
}
})
Expand Down
14 changes: 7 additions & 7 deletions test/display-field-unpacker.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ const { expect } = require('chai')
const displayFieldsUnpacker = require('../lib/display-field-unpacker')
const packedDisplayBib = require('./fixtures/packed-display-response.json')

describe('Display field unpacker', () => {
describe('When a bib has a packed display property', () => {
it('adds each of the items in that array as unpacked objects', () => {
describe('Display field parser', () => {
describe('When a bib has a display components property', () => {
it('adds each of the items in that array as a name, label, nameTitle object', () => {
const displayFieldsUnpacked = displayFieldsUnpacker(packedDisplayBib).hits.hits[0]._source
expect(Object.keys(displayFieldsUnpacked).length).to.equal(2)
expect(displayFieldsUnpacked).to.deep.equal({
testDisplay: [
{ value: 'someValue', display: 'someDisplay' },
{ value: 'someValueB', display: 'someDisplayB' },
{ value: 'someValueC', display: null }
{ displayLabel: 'Smith, John, author', name: 'Smith, John', nameTitle: 'Smith, John' },
{ displayLabel: 'Bayer, Jeffrey. Cataloging test record.', name: 'Bayer, Jeffrey', nameTitle: 'Bayer, Jeffrey Cataloging test record' },
{ displayLabel: 'Org Inc.', name: 'Org Inc', nameTitle: 'Org Inc' }
],
testOtherDisplay: [
{ value: 'otherValue', display: 'otherDisplay' }
{ displayLabel: 'Bean, Richard, 1956-, editor', name: 'Bean, Richard, 1956-', nameTitle: 'Bean, Richard, 1956-' }
]
})
})
Expand Down
12 changes: 6 additions & 6 deletions test/fixtures/packed-display-response.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
"hits": [
{
"_source": {
"test_displayPacked": [
"someValue||someDisplay",
"someValueB||someDisplayB",
"someValueC"
"test_displayComponents": [
{ "name": "Smith, John", "role": "author", "title": null, "label": "Smith, John, author" },
{ "name": "Bayer, Jeffrey", "role": null, "title": "Cataloging test record", "label": "Bayer, Jeffrey. Cataloging test record." },
{ "name": "Org Inc", "role": null, "title": null, "label": "Org Inc." }
],
"testOther_displayPacked": [
"otherValue||otherDisplay"
"testOther_displayComponents": [
{ "name": "Bean, Richard, 1956-", "role": "editor", "title": null, "label": "Bean, Richard, 1956-, editor" }
]
}
}
Expand Down
Loading
Loading