-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SCC-4348: callnumber= and standard_number= param #420
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
const ElasticQuery = require('./elastic-query') | ||
const ApiRequest = require('../api-request') | ||
const { escapeQuery, namedQuery, prefixMatch, termMatch, phraseMatch } = require('./utils') | ||
const { regexEscape } = require('../util') | ||
|
||
|
@@ -60,17 +61,6 @@ class ElasticQueryBuilder { | |
this.requireMultiMatch(SEARCH_SCOPES.all.fields) | ||
} | ||
|
||
// Coming from Adv Search? Add additional multi-match clauses for subject, | ||
// contributor, title: | ||
if (this.request.advancedSearchParamsThatAreAlsoScopes()) { | ||
this.request | ||
.advancedSearchParamsThatAreAlsoScopes() | ||
.forEach((param) => | ||
// Require a match on subject, contributor, or title fields: | ||
this.requireMultiMatch(SEARCH_SCOPES[param].fields, this.request.params[param]) | ||
) | ||
} | ||
|
||
if (this.request.hasSearch()) { | ||
// Apply common boosting: | ||
this.boostNyplOwned() | ||
|
@@ -90,6 +80,9 @@ class ElasticQueryBuilder { | |
} | ||
} | ||
|
||
// Look for query params coming from Adv Search: | ||
this.applyAdvancedSearchParams() | ||
|
||
// Lastly, if any identifier-number params are present (lccn=, isbn=, etc), | ||
// add those clauses: | ||
if (this.request.hasIdentifierNumberParam()) { | ||
|
@@ -464,6 +457,37 @@ class ElasticQueryBuilder { | |
this.query.addMust(should.length === 1 ? should[0] : { bool: { should } }) | ||
} | ||
|
||
/** | ||
* Handle use of subject=, contributor=, title=, & callnumber= Adv Search | ||
* params. | ||
* Note that the RC Adv Search page may also apply filters, which are | ||
* handled by `applyFilters`. | ||
**/ | ||
applyAdvancedSearchParams () { | ||
// We're specifically interested in params that match supported search- | ||
// scopes because we can build a whole ES query just using the existing | ||
// logic for that search scope: | ||
if (this.request.advancedSearchParamsThatAreAlsoScopes()) { | ||
this.request | ||
.advancedSearchParamsThatAreAlsoScopes() | ||
.forEach((advSearchParam) => { | ||
const advSearchValue = this.request.params[advSearchParam] | ||
// Build a new ApiRequest object for this search-scope: | ||
const request = ApiRequest.fromParams({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this pattern being used elsewhere? something about it makes me uneasy... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because |
||
q: advSearchValue, | ||
search_scope: advSearchParam | ||
}) | ||
|
||
// Build the ES query for the search-scope and value: | ||
const builder = ElasticQueryBuilder.forApiRequest(request) | ||
const subquery = builder.query.toJson() | ||
|
||
// Add the query to the greater ES query's must clauses: | ||
this.query.addMust(subquery) | ||
}) | ||
} | ||
} | ||
|
||
/** | ||
* Examine request for user-filters. When found, add them to query. | ||
*/ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what are the advanced search params that are not also scopes? is that just filters?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realize this is older work, but I think this method wants a different name. It's not the
search_scope
ness of the params we're interested in, but rather that they're valid single value query params (as opposed to a compoundq=spaghetti&search_scope=title
format). the method itself isn't actually verifying that they are also search scopes, just that they are in the approved array of advanced search params.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The word "advanced" in "advanced search params" is just a reminder that this is for supporting params used in RC Adv Search, but actually there are many params besides
q=
that are not filters. For exampleisbn=
,issn=
. In the future there could be more. The fact that these params are also validsearch_scope
values is actually important because we're leveraging the existing search-scope logic to build the sub-query. We very much want each of the adv search params to individually work the same as the namesake search scopes do, so we do want to use the same logic. The method thus does verify that they are also search-scopes (recent update here). In the future, there may be other Adv Search params (e.g. 'ISBN'), which would be included in an "approved array of advanced search params" but wold not have a namesake search-scope. To support that, we would have to add custom handler code to add the extra clauses for that new adv-search param. The fact that all non-filter adv search params happen to have equivalent search-scopes right now is a convenience, but not one we assume will remain, hence the awkward function name.