Loading TOC...

MarkLogic 10 Product Documentation
FacetDefinition.reduce

FacetDefinition.reduce(
   reducer as function,
   seed as anyValue
) as FacetDefinition

Summary

Specifies a function similar to Array.prototype.reduce() to apply to each value within the slice or a configuration object for the built-in reducer, as in a ValuesSearch definition.

Parameters
reducer The reducing function.
seed The initial reduction passed to the reducing function.

Usage Notes

You can pass in either a configuration object for the built-in reducer or a function reference to a custom reducer. The built-in reducer configuration object can have the following properties:

frequency
One of the string values "fragment", "item", or "none" (default). This setting controls whether or not to include the number of occurrences of each value. Fragment frequency is the number of fragments (documents) containing each value. Item frequency is the number occurrences of each value. Defaults to none.

When returning frequencies, the built-in reducer returns an object with the serialized value (or bucket name when using groupInto) as the key and the frequency as the value.

The reducer function should have the following signature:

function (prev, current, index, state)

Where the parameters have the following contents:

prev
The value returned by the previous call, or the seed value on the first call.
current
The current value.
index
The number of the current value.
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.

The return from the last call becomes the final reduced result.

You cannot use this method in conjunction with FacetDefinition.map.

See Also

Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.