Skip to content

Commit

Permalink
Incorporate latest all, title, and contrib queries
Browse files Browse the repository at this point in the history
Incorporate latest queries from Mike.
  • Loading branch information
nonword committed Jun 5, 2024
1 parent d40f54c commit 66c7df7
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 42 deletions.
4 changes: 2 additions & 2 deletions config/qa.env
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Greg built self-hosted production domain:
ENCRYPTED_ELASTICSEARCH_URI=AQECAHh7ea2tyZ6phZgT4B9BDKwguhlFtRC6hgt+7HbmeFsrsgAAAHgwdgYJKoZIhvcNAQcGoGkwZwIBADBiBgkqhkiG9w0BBwEwHgYJYIZIAWUDBAEuMBEEDIYpOz/BbRlJZUul7gIBEIA1idumQ6fdf/j5/pzF4t96MGGH/eV1gD4WCyLUnScgNYqtRNK0ajRO6XVroswsrJtgCwUerDM=
# 2024-05-29:
ENCRYPTED_RESOURCES_INDEX=AQECAHh7ea2tyZ6phZgT4B9BDKwguhlFtRC6hgt+7HbmeFsrsgAAAHIwcAYJKoZIhvcNAQcGoGMwYQIBADBcBgkqhkiG9w0BBwEwHgYJYIZIAWUDBAEuMBEEDFVXv05VtUwVtXit3wIBEIAv7GbABuJ+cOEA7ZqVzPEdL6zGytekVKeQnh4z50B2RXXsUKlMUz6osvh6S4koOYY=
# 2024-05-31:
ENCRYPTED_RESOURCES_INDEX=AQECAHh7ea2tyZ6phZgT4B9BDKwguhlFtRC6hgt+7HbmeFsrsgAAAHIwcAYJKoZIhvcNAQcGoGMwYQIBADBcBgkqhkiG9w0BBwEwHgYJYIZIAWUDBAEuMBEEDCMPc+iiGA0Q3PdUJQIBEIAvKyPl8IkGYjTCX1hmBAI3yGYUvyc7kpD7EHTMxx6WH3Esu0Wge8+DGDPqDpuJX9Y=

ENCRYPTED_SCSB_URL=AQECAHh7ea2tyZ6phZgT4B9BDKwguhlFtRC6hgt+7HbmeFsrsgAAAH8wfQYJKoZIhvcNAQcGoHAwbgIBADBpBgkqhkiG9w0BBwEwHgYJYIZIAWUDBAEuMBEEDBKllElmWYLxGOGopQIBEIA8JJyKde/8m8iCJGKR5D8HoTJhXHeyvw9eIDeuUNKiXLfJwoVz+PDAZSxkCQtM9O91zGhXbe3l6Bk1RlYJ
ENCRYPTED_SCSB_API_KEY=AQECAHh7ea2tyZ6phZgT4B9BDKwguhlFtRC6hgt+7HbmeFsrsgAAAGMwYQYJKoZIhvcNAQcGoFQwUgIBADBNBgkqhkiG9w0BBwEwHgYJYIZIAWUDBAEuMBEEDNw8KXkyN8HvtjAX0gIBEIAgX+XG2fxTj6kSchrd/dfHB05KU5pkT0LtPxUTuNCXoLc=
Expand Down
118 changes: 78 additions & 40 deletions lib/resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,7 @@ module.exports = function (app, _private = null) {
return resp
})
.then((updatedResponse) => ResourceResultsSerializer.serialize(updatedResponse, opts))
.then((resp) => Object.assign(resp, { debug: { query: body } }))
})
}

Expand Down Expand Up @@ -1228,6 +1229,8 @@ const buildElasticQuery = function (params) {

// Mike, Elastic consultant, additions:
query.bool.should = []

// Boost NYPL hits:
query.bool.should.push({
term: {
nyplSource: {
Expand All @@ -1236,57 +1239,92 @@ const buildElasticQuery = function (params) {
}
}
})
if (['all', 'title'].includes(params.search_scope)) {
query.bool.should.push({
match_phrase: {
'title.folded': {
query: params.q,
boost: 50

// Boost on-site bibs:
query.bool.should.push({
nested: {
path: 'items',
query: {
regexp: {
'items.holdingLocation.id': {
value: 'loc:(ma|pa|sc).*',
flags: 'ALL',
boost: 2
}
}
}
})
query.bool.should.push({
prefix: {
'title.keywordNormalized': {
value: params.q,
boost: 100
}
})

// Build a version of the query without quotes, if used, since the quote
// character will not be in the literal value:
const querySansQuotes = /^"[^"]+"$/.test(params.q)
? params.q.substring(1, params.q.length - 1)
: params.q

if (['all', 'title'].includes(params.search_scope)) {
query.bool.should = query.bool.should.concat([
{
match_phrase: {
'title.folded': {
query: querySansQuotes,
boost: 50
}
}
}
})
query.bool.should.push({
term: {
'title.keywordNormalized': {
value: params.q,
boost: 105
},
{
prefix: {
'title.keywordLowercasedStripped': {
value: querySansQuotes,
boost: 25
}
}
}
})
query.bool.should.push({
term: {
'title.keyword': {
value: params.q,
boost: 150
},
{
term: {
'title.keywordLowercasedStripped': {
value: querySansQuotes,
boost: 105
}
}
},
{
term: {
'title.keywordLowercased': {
value: querySansQuotes,
boost: 110
}
}
},
{
term: {
'title.keyword': {
value: querySansQuotes,
boost: 150
}
}
}
})
])
}
if (['all', 'contributor'].includes(params.search_scope)) {
query.bool.should.push({
prefix: {
'contributorLiteral.keyword': {
value: params.q,
boost: 100
query.bool.should = query.bool.should.concat([
{
match_phrase: {
'contributorLiteral.folded': {
query: querySansQuotes,
boost: 100
}
}
}
})
query.bool.should.push({
term: {
'contributorLiteral.keyword': {
value: params.q,
boost: 105
},
{
match_phrase: {
'creatorLiteral.keyword': {
query: querySansQuotes,
boost: 100
}
}
}
})
])
}
}

Expand Down

0 comments on commit 66c7df7

Please sign in to comment.