Skip to content

Commit

Permalink
Add parallelSubjectLiteral and boosting for subject prefix query
Browse files Browse the repository at this point in the history
  • Loading branch information
danamansana committed Jan 28, 2025
1 parent 699054b commit 2c351c0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
22 changes: 19 additions & 3 deletions lib/elasticsearch/elastic-query-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ class ElasticQueryBuilder {
* identifier searches like those coming from Worldcat
*/
buildAllQuery () {
console.log('buildAllQuery: ', this.request);
// Require a basic multi-match when keyword used:
if (this.request.params.q) {
this.requireMultiMatch(SEARCH_SCOPES.all.fields)
Expand Down Expand Up @@ -161,10 +160,17 @@ class ElasticQueryBuilder {
}

buildSubjectPrefixQuery () {
console.log('prefix request: ', this.request);
if (!this.request.hasSearch()) return
const q = this.request.querySansQuotes()
this.query.addMust(prefixMatch('subjectLiteral.raw', q))
this.query.addMust({
bool: {
should: [
prefixMatch('subjectLiteral.raw', q),
prefixMatch('parallelSubjectLiteral.raw', q)
]
}
})
this.boostSubjectMatches()
}

/**
Expand Down Expand Up @@ -339,6 +345,16 @@ class ElasticQueryBuilder {
])
}

/**
* Boost bibs with strong subjectLiteral matches
**/
boostSubjectMatches () {
const q = this.request.querySansQuotes()
this.query.addShoulds([
termMatch('subjectLiteral.raw', q, 50)
])
}

/**
* Boost bibs with strong creator/contributor matches
*/
Expand Down
4 changes: 2 additions & 2 deletions lib/resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -621,10 +621,10 @@ module.exports = function (app, _private = null) {

// Conduct a search across resources:
app.resources.search = function (params, opts, request) {
app.logger.debug("Unparsed params: ", params);
app.logger.debug('Unparsed params: ', params)
params = parseSearchParams(params)

app.logger.debug("Parsed params: ", params)
app.logger.debug('Parsed params: ', params)

let body = buildElasticBody(params)

Expand Down

0 comments on commit 2c351c0

Please sign in to comment.