-
Notifications
You must be signed in to change notification settings - Fork 17
Add SearchResult.forEachHit #386
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
Conversation
Codecov Report
@@ Coverage Diff @@
## 6-dev #386 +/- ##
==========================================
+ Coverage 96.68% 96.71% +0.02%
==========================================
Files 30 30
Lines 1447 1460 +13
==========================================
+ Hits 1399 1412 +13
Misses 48 48
Continue to review full report at Codecov.
|
src/controllers/searchResult/base.js
Outdated
} | ||
} | ||
|
||
results = await results.next(); |
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.
Don't we support node 6?
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.
Node 6 LTS support ends on the 30/04/2019, shall we continue to support it anyway?
let results; | ||
|
||
if (firstCall) { | ||
results = new this.constructor(this._kuzzle, this._request, this._options, this._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.
why do we need to instantiate a new SearchResult
object here ?
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 next
method does not return a new SearchResult
but instead it modify his properties.
I instantiate a new SearchResult
to avoid mutating the original one when calling forEachHit
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 agree, the next
method should return a new SearchResult
instance, as it is done in other SDK, instead of mutating the current object.
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.
OK, so it's next
method that should return a new instance.
Instead of a complex recursive code with firstCall
, I'd rather fix the next
method first.
Once done, you will only need to loop into this.hits
and then call this.next().forEachHit(actions)
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 disagree with that feature entirely.
First, about the implementation: it gives the impression that the callback will be executed sequentially, but you're batch-processing it (asynchronous for each hit of a page, and each page sequentially). This is confusing ans misleading.
Second, I don't see what's wrong with the pattern it's supposed to replace: it's simple, it's clear, and it's short.
Third, I don't know how to properly document that feature. The only way to do it is to justify its existence by mentioning the pattern it aims to replace, and that doesn't feel enough to me.
This feels like a lot of code for a marginal gain to me.
About the code, for me we are developing theses SDK precisely to help users to develop application faster. |
I can't help but think that all your feature does, is to get rid of one perfectly concise and clear Going down that route, why not also add Anyway, we'll need the team to review that one, because I don't think we can solve this disagreement by ourselves. edit: and you can't compare this feature with |
What does this PR do?
Adds a
SearchResult.forEachHit
method that take a callback action and execute it over every hit of the search.This method iterate over the page of results with the
next()
method and call the provided action of every elements of theresults.hits
array.When we use the
document:search
method, a very current pattern is to apply an action on every results of the search whatever the number of pages.Doc: kuzzleio/documentation#281
How should this be manually tested?
results.forEachHit(hit => console.log(hit._id))