Skip to content

Commit 9b388ea

Browse files
committed
Support role param for contributor browse filters with roles
1 parent f4a5152 commit 9b388ea

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

lib/api-request.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ class ApiRequest {
7373
return this.params.subject_prefix
7474
}
7575

76+
hasContributorRole () {
77+
return this.params.role && this.params.filters.contributorLiteral
78+
}
79+
7680
static fromParams (params) {
7781
return new ApiRequest(params)
7882
}

lib/elasticsearch/elastic-query-builder.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ class ElasticQueryBuilder {
8787
if (this.request.hasSubjectPrefix()) {
8888
this.applySubjectPrefix()
8989
}
90+
91+
if (this.request.hasContributorRole()) {
92+
this.applyContributorRole()
93+
}
9094
}
9195

9296
/**
@@ -170,6 +174,13 @@ class ElasticQueryBuilder {
170174
])
171175
}
172176

177+
/**
178+
* Concat contributor + role if role param is provided
179+
*/
180+
applyContributorRole () {
181+
this.query.addMust(termMatch('contributorRoleLiteral', this.request.params.filters.contributorLiteral + '||' + this.request.params.role))
182+
}
183+
173184
/**
174185
* Build ES query for standard_number searches
175186
*/

lib/resources.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ const parseSearchParams = function (params, overrideParams = {}) {
8585
issn: { type: 'string' },
8686
lccn: { type: 'string' },
8787
oclc: { type: 'string' },
88+
role: { type: 'string' },
8889
merge_checkin_card_items: { type: 'boolean', default: true },
8990
include_item_aggregations: { type: 'boolean', default: true },
9091
...overrideParams

test/elastic-query-builder.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,14 @@ describe('ElasticQueryBuilder', () => {
252252
expect(inst.query.toJson()).to.nested
253253
.include({ 'bool.filter[0].term.genreForm\\.raw': 'Maps' })
254254
})
255+
256+
it('supports contributor + role', () => {
257+
const request = new ApiRequest({ q: '', role: 'performer.', filters: { contributorLiteral: 'Patinkin, Mandy' } })
258+
const inst = ElasticQueryBuilder.forApiRequest(request)
259+
260+
expect(inst.query.toJson()).to.nested
261+
.include({ 'bool.must[0].term.contributorRoleLiteral.value': 'Patinkin, Mandy||performer.' })
262+
})
255263
})
256264

257265
describe('Advanced Search query params', () => {

0 commit comments

Comments
 (0)