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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ Filters are applied using a `filters` param that expects this syntax on the quer

> /resources?filters[property1]=value1&filters[property2]=value2

Where `property*` is one of: 'owner', 'subjectLiteral', 'holdingLocation', 'deliveryLocation', 'language', 'materialType', 'mediaType', 'carrierType', 'publisher', 'contributor', 'creator', 'issuance', 'createdYear', 'dateAfter', or 'dateBefore'.
Where `property*` is one of: 'owner', 'subjectLiteral', 'holdingLocation', 'deliveryLocation', 'language', 'materialType', 'mediaType', 'carrierType', 'publisher', 'contributor', 'creator', 'contributorNameTitle', 'issuance', 'createdYear', 'dateAfter', or 'dateBefore'.

The value given should be _exact_. Do not use quotes.

Expand Down
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
})

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
1 change: 1 addition & 0 deletions lib/elasticsearch/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ const FILTER_CONFIG = {
carrierType: { operator: 'match', field: ['carrierType.id', 'carrierType.label'], repeatable: true },
publisher: { operator: 'match', field: ['publisherLiteral.keywordLowercasedStripped'], repeatable: true },
contributorLiteral: { operator: 'match', field: ['contributorLiteral.keywordLowercasedStripped', 'parallelContributorLiteral.keywordLowercasedStripped', 'creatorLiteral.keywordLowercasedStripped', 'parallelCreatorLiteral.keywordLowercasedStripped'], repeatable: true },
contributorNameTitle: { operator: 'match', field: ['contributorNameTitle.keywordLowercasedStripped', 'parallelContributorNameTitle.keywordLowercasedStripped'], repeatable: true },
creatorLiteral: { operator: 'match', field: ['creatorLiteral.keywordLowercasedStripped', 'parallelCreatorLiteral.keywordLowercasedStripped'], repeatable: true },
issuance: { operator: 'match', field: ['issuance.id', 'issuance.label'], repeatable: true },
createdYear: { operator: 'match', field: ['createdYear'], repeatable: true },
Expand Down
4 changes: 2 additions & 2 deletions swagger.v1.1.x.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
{
"name": "filters[*]",
"in": "query",
"description": "Specify a hash of filters to apply, where key is: 'format', 'buildingLocation', 'owner', 'subjectLiteral', 'holdingLocation', 'deliveryLocation', 'language', 'materialType', 'mediaType', 'carrierType', 'publisher', 'contributor', 'creator', 'issuance', 'createdYear', 'dateAfter', or 'dateBefore'",
"description": "Specify a hash of filters to apply, where key is: 'format', 'buildingLocation', 'owner', 'subjectLiteral', 'holdingLocation', 'deliveryLocation', 'language', 'materialType', 'mediaType', 'carrierType', 'publisher', 'contributor', 'creator', 'contributorNameTitle', 'issuance', 'createdYear', 'dateAfter', or 'dateBefore'",
"required": false,
"type": "string"
},
Expand Down Expand Up @@ -299,7 +299,7 @@
{
"name": "filters[*]",
"in": "query",
"description": "Specify a hash of filters to apply, where key is: 'buildingLocation', 'owner', 'subjectLiteral', 'holdingLocation', 'deliveryLocation', 'language', 'materialType', 'mediaType', 'carrierType', 'publisher', 'contributor', 'creator', 'issuance', 'createdYear', 'dateAfter', or 'dateBefore'",
"description": "Specify a hash of filters to apply, where key is: 'buildingLocation', 'owner', 'subjectLiteral', 'holdingLocation', 'deliveryLocation', 'language', 'materialType', 'mediaType', 'carrierType', 'publisher', 'contributor', 'creator', 'contributorNameTitle', 'issuance', 'createdYear', 'dateAfter', or 'dateBefore'",
"required": false,
"type": "string"
}
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