WordsSearch.map( mapper as objectOrFuncRef ) as WordsSearch
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. |
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
.
// 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
Stack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.