Loading TOC...


   $mapper as objectOrFuncRef
) as ValuesSearch


Specify a function similar to Array.prototype.map() to apply to each value within the slice, or configure the built-in mapper. Exclusive with respect to the reduce() clause.

$mapper The mapping function or configuration for the built-in mapper. For details, see the Usage Notes.

Usage Notes

You can pass in either a configuration object for the built-in mapper or a function reference to a custom mapper. The built-in mapper or your custom mapper is applied to each value in the current slice of values from a lexicon or range index.

The built-in mapper configuration object can have the following properties:

One of the string values "fragment", "item", or "none" (default). This setting controls whether to report the number of documents (that is, the fragments) containing the values, the number of occurrences of each value (that is, the items), or to omit the frequency. The default is "none".
Specify a name for the values and for the frequency (if enabled). If names is specified, the built-in mapper returns an object for each value with the names as properties. If the frequency is specified but not the name, the built-in mapper returns an array for each value. The frequency name should appear after the value name. For example: {names: [valName, freqName]}. See the example, below.

An empty configuration object causes the built-in mapper to return the values array unchanged.

A custom mapper should have the following signature:

function (currentItem)

Where the single input is the current value to act on. If the function returns a value, the value is pushed on to the results array.

You cannot use this method in conjunction with ValuesSearch.reduce.

See Also


// Built-in mapper configure to return frequency with the values
var jsearch = require('/MarkLogic/jsearch.sjs');
  .map({frequency: 'item'})

==> [["John Steinbeck", 3], ["Mark Twain", 4], ["Robert Frost", 1]]


// Built-in mapper configured with frequency and names
var jsearch = require('/MarkLogic/jsearch.sjs');
  .map({frequency: 'item', names: ['Author', 'Count']})

[{"Author":"John Steinbeck", "Count":3}, 
 {"Author":"Mark Twain", "Count":4}, 
 {"Author":"Robert Frost", "Count":1}]


// Use a custom mapper
var jsearch = require('/MarkLogic/jsearch.sjs');
var jsearch = require('/MarkLogic/jsearch.sjs');
  .map(function (value) {
     return String(value).toLowerCase() 

==> ["john steinbeck", "mark twain", "robert frost"]


    Powered by MarkLogic Server 7.0-4.1 and rundmc | Terms of Use | Privacy Policy