Skip to content

Commit

Permalink
Fix bug reading numItemsTotal from inner_hits
Browse files Browse the repository at this point in the history
  • Loading branch information
nonword committed Jun 10, 2024
1 parent 15a0881 commit 1174576
Show file tree
Hide file tree
Showing 66 changed files with 12,366 additions and 13,163 deletions.
2 changes: 1 addition & 1 deletion lib/resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ module.exports = function (app, _private = null) {
// Mindfully throw errors for known issues:
if (!resp || !resp.hits) {
throw new Error('Error connecting to index')
} else if (resp && resp.hits && resp.hits.total === 0) {
} else if (resp?.hits?.total?.value === 0) {
throw new errors.NotFoundError(`Record not found: ${params.uri}`)
} else {
const massagedResponse = new ResponseMassager(resp)
Expand Down
4 changes: 2 additions & 2 deletions lib/response_massager.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ class ResponseMassager {
hit._source.items = hit.inner_hits.items.hits.hits.map((itemHit) => itemHit._source)

// Grab the "items" inner_hits total as numItemsMatched:
hit._source.numItemsMatched = [hit.inner_hits.items.hits.total]
hit._source.numItemsMatched = [hit.inner_hits.items.hits.total.value]

// If response includes an "allItems" inner_hits query, use the total
// from that to get numItemsTotal. If "allItems inner_hits query
// doesn't exist (because no item filters are in play) just use "items"
// inner_hits query:
const unfilteredItems = (hit.inner_hits.allItems || hit.inner_hits.items)
hit._source.numItemsTotal = [unfilteredItems.hits.total]
hit._source.numItemsTotal = [unfilteredItems.hits.total.value]
}
// Process "electronicResources" inner_hits
if (hit.inner_hits && hit.inner_hits.electronicResources) {
Expand Down
Loading

0 comments on commit 1174576

Please sign in to comment.