Skip to content

Commit

Permalink
Add support for standard_number=
Browse files Browse the repository at this point in the history
  • Loading branch information
nonword committed Nov 18, 2024
1 parent 68de1c2 commit 7aa5e0f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/api-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions lib/resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand Down
5 changes: 2 additions & 3 deletions routes/resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
22 changes: 22 additions & 0 deletions test/elastic-query-builder.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' })
Expand Down

0 comments on commit 7aa5e0f

Please sign in to comment.