diff --git a/lib/api-request.js b/lib/api-request.js index 1c1fcd7d..9eb1f3d8 100644 --- a/lib/api-request.js +++ b/lib/api-request.js @@ -8,7 +8,7 @@ const QUOTE_CHARS = '"\u201C\u201D\u201E\u201F\u2033\u2036' const IN_QUOTES_PATTERN = new RegExp(`^[${QUOTE_CHARS}][^${QUOTE_CHARS}]+[${QUOTE_CHARS}]$`) class ApiRequest { - static ADVANCED_SEARCH_PARAMS = ['title', 'subject', 'contributor', 'callnumber'] + static ADVANCED_SEARCH_PARAMS = ['title', 'subject', 'contributor', 'callnumber', 'standard_number'] static IDENTIFIER_NUMBER_PARAMS = ['isbn', 'issn', 'lccn', 'oclc'] constructor (params) { diff --git a/lib/resources.js b/lib/resources.js index e7a37210..0594f3ab 100644 --- a/lib/resources.js +++ b/lib/resources.js @@ -88,6 +88,7 @@ const parseSearchParams = function (params) { items_size: { type: 'int', default: 100, range: [0, 200] }, items_from: { type: 'int', default: 0 }, callnumber: { type: 'string' }, + standard_number: { type: 'string' }, contributor: { type: 'string' }, title: { type: 'string' }, subject: { type: 'string' }, diff --git a/routes/resources.js b/routes/resources.js index d70fa3b3..852b71c0 100644 --- a/routes/resources.js +++ b/routes/resources.js @@ -100,11 +100,10 @@ module.exports = function (app) { * e.g. discovery/resources/b1234 */ app.get(`/api/v${VER}/discovery/resources/:uri.:ext?`, function (req, res) { - const gatheredParams = req.query const params = Object.assign({}, req.query, { uri: req.params.uri }) - if (Number.isInteger(parseInt(gatheredParams.items_size))) params.items_size = gatheredParams.items_size - if (Number.isInteger(parseInt(gatheredParams.items_from))) params.items_from = gatheredParams.items_from + if (Number.isInteger(parseInt(req.query.items_size))) params.items_size = req.query.items_size + if (Number.isInteger(parseInt(req.query.items_from))) params.items_from = req.query.items_from let handler = app.resources.findByUri diff --git a/test/elastic-query-builder.test.js b/test/elastic-query-builder.test.js index f4384ab7..e75a2968 100644 --- a/test/elastic-query-builder.test.js +++ b/test/elastic-query-builder.test.js @@ -156,6 +156,28 @@ describe('ElasticQueryBuilder', () => { }) }) + describe('standard_number=', () => { + it('applies standard_number clauses to query', () => { + const request = new ApiRequest({ standard_number: 'toast' }) + const inst = ElasticQueryBuilder.forApiRequest(request) + + expect(inst.query.toJson()).to.nested + .include({ + // Match on bib identifiers: + 'bool.must[0].bool.must[0].bool.should[0].prefix.identifierV2\\.value.value': 'toast' + }) + .include({ + // Match on bib id: + 'bool.must[0].bool.must[0].bool.should[1].term.uri.value': 'toast' // , + }) + .include({ + // Match on item barcode: + 'bool.must[0].bool.must[0].bool.should[2].nested.path': 'items', + 'bool.must[0].bool.must[0].bool.should[2].nested.query.term.items\\.idBarcode.value': 'toast' + }) + }) + }) + describe('title=', () => { it('applies title clauses to query', () => { const request = new ApiRequest({ title: 'toast' })