Loading TOC...

FacetDefinition.map

FacetDefinition.map(
   $mapper as objectOrFuncRef
) as FacetDefinition

Summary

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

Parameters
$mapper The mapping function or configuration for the built-in mapper.

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:

frequency
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".
names
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 FacetDefinition.reduce.

See Also

Example


// Use the built-in mapper to suppress the inclusion of counts 
// in returned facet data.
const jsearch = require('/MarkLogic/jsearch.sjs');
jsearch.facets(
    jsearch.facet('Author', 'author').map({frequency: 'none'}))
  .where(cts.directoryQuery('/books/'))
  .result()
   

Comments

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