DocumentsSearch.reduce( reducer as function, seed as anyValue ) as DocumentsSearch
Specifies a function similar to Array.prototype.reduce() to apply to each document within the slice. See the Usage Notes for details.
Parameters | |
---|---|
reducer | The reducing function. |
seed | The initial reduced value passed to the reducing function. |
function (prev, current, index, state)
Where the parameters contain the following:
prev
- The output returned by the previous call, or the seed value on the first call.
current
- The current document.
index
- The number of the current document.
state
- A state object with a boolean-valued
isLast
> property that indicated the last call. You can set it to true to prematurely halt the reduction.
You cannot use this method in conjunction with
DocumentsSearch.map
.
// Use a custom reducer, with an initial seed value const jsearch = require('/MarkLogic/jsearch.sjs'); jsearch.documents() .where(cts.jsonPropertyValueQuery('author','Mark Twain')) .reduce(function (prev, match, index, state) { // do something }, {count: 0, value: 0, matches: []}) .result()
Stack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.