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
4 changes: 4 additions & 0 deletions lib/elastic-search/index-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,10 @@ exports.schema = () => ({
accessMessage: propertyTemplates.entity,
accessMessage_packed: propertyTemplates.packed,
aeonUrl: propertyTemplates.exactString,
buildingLocationId: {
type: 'keyword',
eager_global_ordinals: true
},
catalogItemType: propertyTemplates.entity,
catalogItemType_packed: propertyTemplates.packed,
collectionId: {
Expand Down
13 changes: 4 additions & 9 deletions lib/es-models/bib.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class EsBib extends EsBase {
}

/**
* Set of distinct research center location ids, e.g. ['rc', 'ma']
* Set of distinct research center location ids from bib's items, e.g. ['rc', 'ma']
*/
buildingLocationIds () {
if (this.bib.isPartnerRecord()) {
Expand All @@ -56,14 +56,9 @@ class EsBib extends EsBase {
const items = this.items()
return unique(
items
// Filter on items with a holdingLocation:
.filter((item) => item.holdingLocation() && item.holdingLocation().length)
// Translate holdingLocation into plain id:
.map((item) => item.holdingLocation()[0].id.split(':').pop())
// Translate into parent id:
.map((locationId) => locationId.substring(0, 2))
// Restrict to known Research parent locations:
.filter((id) => ['ma', 'pa', 'sc', 'rc', 'bu'].includes(id))
.map((item) => item.buildingLocationId && item.buildingLocationId())
.flat()
.filter(Boolean)
)
}
}
Expand Down
12 changes: 12 additions & 0 deletions lib/es-models/item.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ class EsItem extends BaseItemMixin(EsBase) {
return aeonUrl ? [aeonUrl] : null
}

buildingLocationId () {
const holdingLoc = this.holdingLocation && this.holdingLocation()
if (holdingLoc && holdingLoc.length) {
const loc = holdingLoc[0].id.split(':').pop()
const parentLoc = loc.substring(0, 2)
if (['ma', 'pa', 'sc', 'rc', 'bu'].includes(parentLoc)) {
return [parentLoc]
}
}
return null
}

catalogItemType () {
const itemType = this.item.getItemType()

Expand Down
18 changes: 18 additions & 0 deletions test/unit/es-item.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,24 @@ describe('EsItem', function () {
})
})

describe('buildingLocationId', function () {
it('returns building location based on item holding location', function () {
const record = new SierraItem(require('../fixtures/item-14441624.json'))
const esItem = new EsItem(record)
expect(esItem.buildingLocationId()).to.deep.equal(['ma'])
})

it('returns null if item holding location does not map to a building locatin', function () {
const fakeRecord = new SierraItem({
id: '1234',
nyplSource: 'sierra-nypl',
location: { code: 'zzzzz' }
})
const esItem = new EsItem(fakeRecord)
expect(esItem.buildingLocationId()).to.equal(null)
})
})

describe('catalogItemType', function () {
it('should return mapped item type if present', function () {
const record = new SierraItem(require('../fixtures/item-17145801.json'))
Expand Down
Loading