Loading TOC...

DocumentsSearch.map

DocumentsSearch.map(
   $mapper as objectOrFuncRef
) as DocumentsSearch

Summary

Specifies a function similar to Array.prototype.map() to apply to each document within the slice or the configuration for the built-in mapper. Exclusive with respect to the documentSearch.reduce clause.

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

Usage Notes

You cannot use this function and DocumentsSearch.reduce in the same search. You should only call DocumentSearch.withOptions or DocumentSearch.result on the result of this operation.

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 configuration object can have the following properties:

snippets
Controls selection of matching text with either a boolean value or a configuration object having the preferredMatches, maxMatches, perMatchTokens, and query properties. For details, see Including Snippets of Matching Content in Search Results in the Search Developer's Guide
extract
Controls selection by XPath with a configuration object having the selected property (an enumeration of include|include-with-ancestors |exclude|all) and the paths property. For details, see Extracting Portions of Each Matched Document in the Search Developer's Guide
namespaces
Specifies a configuration object with prefix keys and uri values for resolving XPath expressions used in extract.
returnSimilar
A boolean value controlling whether to return documents similar to each result document.

A custom mapper should have the following signature:

function (currentItem)

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

See Also

Example


// Use the built-in mapper to return snippets instead of documents
const jsearch = require('/MarkLogic/jsearch.sjs');
jsearch.documents()
  .where(jsearch.byExample({synopsis: {$word: 'california'}}))
  .map({snippet: true})
  .result()
   

Example


// Use the built-in mapper to return snippets, preferrably of
// matches in the "synopsis" property. Return at most 5 tokens around
// the match highlight.
const jsearch = require('/MarkLogic/jsearch.sjs');
jsearch.documents()
  .where(cts.wordQuery('california'))
  .map({snippet: {
    preferredMatches: ['synopsis'],
    perMatchTokens: 5
  }})
  .result()
   

Example


// Use the built-in mapper to extract just the "title" and "author"
// JSON properties from matched documents.
const jsearch = require('/MarkLogic/jsearch.sjs');
jsearch.documents()
  .where(jsearch.byExample({synopsis: {$word: 'California'}}))
  .map({extract: {paths: ['/title', '/author']}})
  .result()
   

Example


// Use a custom mapper to insert a new property in output document
// returned for each match.
const jsearch = require('/MarkLogic/jsearch.sjs');
jsearch.documents()
  .where(cts.jsonPropertyValueQuery('author','Mark Twain'))
  .map(function (value) {value.iWasHere = true; return value;})
  .result()
   

Example


// Use the built-in mapper to return both snippets and documents.
const jsearch = require('/MarkLogic/jsearch.sjs');
jsearch.documents()
  .where(jsearch.byExample({synopsis: {$word: 'California'}}))
  .map({snippet: true, extract: {selected: 'all'}})
  .result()
   

Comments

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