Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/api-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ class ApiRequest {
return this.params.subject_prefix
}

hasContributorRole () {
return this.params.role && this.params.filters.contributorLiteral
}

static fromParams (params) {
return new ApiRequest(params)
}
Expand Down
11 changes: 11 additions & 0 deletions lib/elasticsearch/elastic-query-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ class ElasticQueryBuilder {
if (this.request.hasSubjectPrefix()) {
this.applySubjectPrefix()
}

if (this.request.hasContributorRole()) {
this.applyContributorRole()
}
}

/**
Expand Down Expand Up @@ -170,6 +174,13 @@ class ElasticQueryBuilder {
])
}

/**
* Concat contributor + role if role param is provided
*/
applyContributorRole () {
this.query.addMust(termMatch('contributorRoleLiteral', this.request.params.filters.contributorLiteral + '||' + this.request.params.role))
}

/**
* Build ES query for standard_number searches
*/
Expand Down
1 change: 1 addition & 0 deletions lib/resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ const parseSearchParams = function (params, overrideParams = {}) {
issn: { type: 'string' },
lccn: { type: 'string' },
oclc: { type: 'string' },
role: { type: 'string' },
merge_checkin_card_items: { type: 'boolean', default: true },
include_item_aggregations: { type: 'boolean', default: true },
...overrideParams
Expand Down
8 changes: 8 additions & 0 deletions test/elastic-query-builder.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,14 @@ describe('ElasticQueryBuilder', () => {
expect(inst.query.toJson()).to.nested
.include({ 'bool.filter[0].term.genreForm\\.raw': 'Maps' })
})

it('supports contributor + role', () => {
const request = new ApiRequest({ q: '', role: 'performer.', filters: { contributorLiteral: 'Patinkin, Mandy' } })
const inst = ElasticQueryBuilder.forApiRequest(request)

expect(inst.query.toJson()).to.nested
.include({ 'bool.must[0].term.contributorRoleLiteral.value': 'Patinkin, Mandy||performer.' })
})
})

describe('Advanced Search query params', () => {
Expand Down
Loading