Skip to content

Commit

Permalink
Merge pull request #99 from NYPL/main
Browse files Browse the repository at this point in the history
Add recordTypeId to index
  • Loading branch information
charmingduchess authored Nov 27, 2024
2 parents e2b1233 + 23607d8 commit 4ad4efb
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 12 deletions.
1 change: 1 addition & 0 deletions lib/elastic-search/index-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ exports.schema = () => ({
publicDomain: propertyTemplates.boolean,
publisherLiteral: propertyTemplates.fulltextWithRawFolded,
publicationStatement: propertyTemplates.exactStringNotIndexed,
recordType: propertyTemplates.exactString,
serialPublicationDates: propertyTemplates.exactStringNotIndexed,
seriesStatement: propertyTemplates.fulltextWithRawFolded,
shelfMark: {
Expand Down
28 changes: 16 additions & 12 deletions lib/es-models/bib.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,22 +308,23 @@ class EsBib extends EsBase {
idOclc () {
let oclcs = []

;[
const marcMappings = [
{ marc: '991', subfield: 'y' },
{ marc: '035', subfield: 'a' },
{ marc: '001' }
].forEach((mapping) => {
]
marcMappings.forEach((mapping) => {
let matches = this.bib.varField(mapping.marc, [mapping.subfield])

// Special handling for 035 values:
if (mapping.marc === '035') {
const oclcPrefix = /^\(OCoLC\)/
matches = matches
// Only consider 035 identifiers prefixed (OCoLC):
// Only consider 035 identifiers prefixed (OCoLC):
.filter((match) => {
return oclcPrefix.test(match.value)
})
// Strip (OCoLC) prefix:
// Strip (OCoLC) prefix:
.map((match) => {
match.value = match.value.replace(oclcPrefix, '')
return match
Expand Down Expand Up @@ -472,14 +473,11 @@ class EsBib extends EsBase {

// loop over the content so a separate object is generated for each one.
return notesArray
.map(({ varFieldMatchObject, description }, index) =>
// the array has primary and parallel varFieldMatch objects. An orphan
// parallel value will not have a value property, rather a parallel.value
({
label: varFieldMatchObject.value,
type: 'bf:Note',
noteType: description
})
.map(({ varFieldMatchObject, description }, index) => ({
label: varFieldMatchObject.value,
type: 'bf:Note',
noteType: description
})
)
}

Expand Down Expand Up @@ -615,6 +613,12 @@ class EsBib extends EsBase {
return this._valueToIndexFromBasicMapping('publisherLiteral')
}

recordTypeId () {
const recordType = this.bib.ldr()?.recType
if (recordType) return recordType
else return null
}

serialPublicationDates () {
return this._valueToIndexFromBasicMapping('serialPublicationDates')
}
Expand Down
21 changes: 21 additions & 0 deletions test/unit/es-bib.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,27 @@ describe('EsBib', function () {
})
})

describe('recordTypeId', () => {
it('should return recordTypeId based on ldr rectype', () => {
const sierraBib = new SierraBib({})
sinon.stub(sierraBib, 'ldr').returns({ recType: 'h' })
const esBib = new EsBib(sierraBib)
expect(esBib.recordTypeId()).to.deep.equal('h')
})
it('should return null for empty rectype', () => {
const sierraBib = new SierraBib({})
sinon.stub(sierraBib, 'ldr').returns({ recType: '' })
const esBib = new EsBib(sierraBib)
expect(esBib.materialType()).to.equal(null)
})
it('should not break if ldr is undefined', () => {
const sierraBib = new SierraBib({})
sinon.stub(sierraBib, 'ldr').returns()
const esBib = new EsBib(sierraBib)
expect(esBib.materialType()).to.equal(null)
})
})

describe('materialType', () => {
it('should return materialType based on ldr rectype', () => {
const sierraBib = new SierraBib({})
Expand Down

0 comments on commit 4ad4efb

Please sign in to comment.