diff --git a/lib/elastic-search/index-schema.js b/lib/elastic-search/index-schema.js index 3041b51..e162b16 100644 --- a/lib/elastic-search/index-schema.js +++ b/lib/elastic-search/index-schema.js @@ -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: { diff --git a/lib/es-models/bib.js b/lib/es-models/bib.js index 8a94505..ef485d3 100644 --- a/lib/es-models/bib.js +++ b/lib/es-models/bib.js @@ -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()) { @@ -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) ) } } diff --git a/lib/es-models/item.js b/lib/es-models/item.js index c701738..4ee9504 100644 --- a/lib/es-models/item.js +++ b/lib/es-models/item.js @@ -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() diff --git a/test/unit/es-item.test.js b/test/unit/es-item.test.js index 2e32334..11f6b06 100644 --- a/test/unit/es-item.test.js +++ b/test/unit/es-item.test.js @@ -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'))