-
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 4167/all items #401
Scc 4167/all items #401
Changes from 7 commits
e67a0f8
30adf57
cc540e7
06944dc
53f1b0e
9dac068
949ad54
38d7e01
2140cd2
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 |
---|---|---|
|
@@ -4,7 +4,6 @@ const parallelFieldsExtractor = require('./parallel-fields-extractor') | |
const { isAeonUrl } = require('../lib/util') | ||
const FulfillmentResolver = require('./fulfillment_resolver') | ||
const RequestabilityResolver = require('./requestability_resolver') | ||
// const addNumItemsMatched = require('./item-match-numerator') | ||
|
||
class ResponseMassager { | ||
constructor (responseReceived) { | ||
|
@@ -19,8 +18,11 @@ class ResponseMassager { | |
* | ||
* Also copies ".total" properties into convenient places for serialization. | ||
*/ | ||
processInnerHitsProperties (response) { | ||
processInnerHitsProperties (response, allItemsBibQuery) { | ||
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. I updated the args here because I didn't see a clearer way to branch the logic. I don't love this update, but let me know if you see any alternatives. 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. I hear you. I think it's fine on balance. This seems like the right place to sort items. What triggers the sorting is the question. An alternative to adding a "do the sorting" param would be to change the check on line 23 to |
||
response.hits.hits.forEach((hit) => { | ||
if (allItemsBibQuery) { | ||
hit._source.items.sort((a, b) => a.enumerationChronology_sort[0] > b.enumerationChronology_sort[0] ? -1 : 1) | ||
} | ||
// Process "items" inner_hits | ||
if (hit.inner_hits && hit.inner_hits.items) { | ||
// Reassign items inner_hits to .items | ||
|
@@ -58,10 +60,10 @@ class ResponseMassager { | |
|
||
massagedResponse (request, options = {}) { | ||
let response = this.elasticSearchResponse | ||
|
||
const allItemsBibQuery = request?.query?.all_items | ||
// Inspect response inner_hits queries and move properties around to ease | ||
// serialization: | ||
response = this.processInnerHitsProperties(response) | ||
response = this.processInnerHitsProperties(response, allItemsBibQuery) | ||
|
||
// Rename parallel fields: | ||
response = parallelFieldsExtractor(response) | ||
|
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 can't leave a comment on the exact line, but around line 34-38 it looks like we can get rid of some code.
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.
You mean the part where we populate
hit._source.numItemsTotal
? I believe that's there to ensure that we get an accurate items count even if we have active item filters. When there are active item filters we insert a second inner_hits call without any item filters so that we can use that count fornumItemsTotal
. In theall_items
case, there are no item filters by definition, so theallItems
inner_hits won't be triggered.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.
opted for something in the middle - renamed the param in
processInnerHitsProperties
to sound more agnostic to what is triggering it.