grtjn / ml-snippeting

Custom MarkLogic snippeting functions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ml-snippetting

Custom MarkLogic snippeting functions

Install

Installation depends on the MarkLogic Package Manager:

$ mlpm install ml-snippeting --save
$ mlpm deploy

doc-snippet

A snippeting function that concatenates the character data of the entire document to one text node before applying the usual snippeting. This allows search matches to show more textual context on data-like documents.

Take your REST api search options, and look for the transform-result section, which could look like this:

  <transform-results apply="snippet">
    <preferred-elements>
      <element ns="" name="body"/>
    </preferred-elements>
    <max-matches>1</max-matches>
    <max-snippet-chars>150</max-snippet-chars>
    <per-match-tokens>20</per-match-tokens>
  </transform-results>

Just change the first line of it as follows:

  <transform-results apply="snippet" ns="http://marklogic.com/doc-snippet" at="/ext/mlpm_modules/ml-snippeting/doc-snippet.xqy">
    <preferred-elements>
      <element ns="" name="body"/>
    </preferred-elements>
    <max-matches>1</max-matches>
    <max-snippet-chars>150</max-snippet-chars>
    <per-match-tokens>20</per-match-tokens>
  </transform-results>

Note: perferred-elements will effectively be ignored. You can omit that.

Note also: Flattening the document would cause range- and value-queries, to no longer match and giving no highlights. To counteract this snippeting adds a word-query for all values. That might highlight too much, but better than nothing.

About

Custom MarkLogic snippeting functions

License:Apache License 2.0


Languages

Language:XQuery 100.0%