Loading TOC...

WordsSearch.map

WordsSearch.map(
   $mapper as objectOrFuncRef
) as WordsSearch

Summary

Specifies a function similar to Array.prototype.map() to apply to each word within the slice. Exclusive with respect to the reduce() clause.

Parameters
$mapper A configuration object for the built-in mapper, or a reference to a custom mapper function. See the Usage Notes for details.

Usage Notes

Your custom mapper function is invoked on each word in the current slice. Your custom mapper should have the following signature:

function (currentItem)

Where currentItem is the current word to act on. If the function returns a value, the value is added to the results array or iterator.

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

See Also

Example


// Returns true if the input is on my black list
function isInBlackList(word) {...};

const jsearch = require('/MarkLogic/jsearch.sjs');
jsearch.words('title')
  .slice(0,3)
  .map(function (word) {
    return isInBlackList(word) ? undefined : word
  })
  .result()

// Result: An array of words in the 'title' word lexicon that are not blacklisted
   

Comments

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