Skip to content

Commit

Permalink
Merge pull request #101 from NYPL/main
Browse files Browse the repository at this point in the history
add recordTypeId to index
  • Loading branch information
charmingduchess authored Dec 3, 2024
2 parents 142f613 + c4affcd commit c6b5468
Show file tree
Hide file tree
Showing 12 changed files with 412 additions and 528 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,
recordTypeId: 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 recordTypeId = this.bib.ldr()?.recType
if (recordTypeId) return recordTypeId
else return null
}

serialPublicationDates () {
return this._valueToIndexFromBasicMapping('serialPublicationDates')
}
Expand Down
39 changes: 35 additions & 4 deletions lib/utils/nypl-source-mapper.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const axios = require('axios')
class NyplSourceMapper {
constructor (mapping) {
this.nyplSourceMap = mapping
Expand Down Expand Up @@ -50,13 +49,45 @@ class NyplSourceMapper {
}
}

/**
* Create a NyplSourceMapper instance
*/
const createInstance = async () => {
const sourceMappingUrl = `https://raw.githubusercontent.com/NYPL/nypl-core/${process.env.NYPL_CORE_VERSION || 'master'}/mappings/recap-discovery/nypl-source-mapping.json`

// Retrieve json file:
const resp = await fetch(sourceMappingUrl)
.catch((e) => {
throw new Error(`Error retrieving ${sourceMappingUrl}: ${e}`)
})

// Assert 2xx status:
if (!resp?.ok) {
throw new Error(`Error retrieving ${sourceMappingUrl} - got status ${resp?.status}`)
}

// Parse JSON:
const data = await resp.json()
.catch((e) => {
throw new Error(`Error parsing ${sourceMappingUrl}: ${e}`)
})

// Check for invalid data structure:
if (!data || !data['sierra-nypl']) {
throw new Error(`Error parsing data at ${sourceMappingUrl}`)
}

return new NyplSourceMapper(data)
}

let sourceMapperInstance = null

/**
* Get singleton NyplSourceMapper instance
*/
NyplSourceMapper.instance = async () => {
if (!sourceMapperInstance) {
sourceMapperInstance = await axios.get(`https://raw.githubusercontent.com/NYPL/nypl-core/${process.env.NYPL_CORE_VERSION || 'master'}/mappings/recap-discovery/nypl-source-mapping.json`).then((resp) => {
return new NyplSourceMapper(resp.data)
})
sourceMapperInstance = createInstance()
}
return sourceMapperInstance
}
Expand Down
Loading

0 comments on commit c6b5468

Please sign in to comment.