search:snippet( $result as node(), $cts-query as schema-element(cts:query), [$options as element(search:transform-results)?] ) as element(search:snippet)
This function extracts matching text from the result node based on options, and returns the matches wrapped in a containing node, with highlights tagged.
Parameters | |
---|---|
result | A node from which to pull matching snippets from. |
cts-query | A
serialized and annotated cts:query ,
typically the result of a call to
search:parse .
|
options | Options to define the search
grammar and control the search. See description for
$options for
the function search:search . Note that
you cannot specify the apply attribute
on the transform-results option with
search:snippet ; to use a different snippetting
function, use
search:search or
search:resolve
instead.
|
xquery version "1.0-ml"; import module namespace search = "http://marklogic.com/appservices/search" at "/MarkLogic/appservices/search/search.xqy"; search:snippet( <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Page Title</title> </head> <body> <div>Query terms in this div will be ignored for snippeting.</div> <p>Text surrounding query terms is highlighted and truncated according to configuration.</p> </body> </html>, search:parse("terms"), <transform-results apply="snippet" xmlns="http://marklogic.com/appservices/search"> <per-match-tokens>30</per-match-tokens> <max-matches>4</max-matches> <max-snippet-chars>200</max-snippet-chars> <preferred-matches> <element name="p" ns="http://www.w3.org/1999/xhtml"/> </preferred-matches> </transform-results>) => <search:snippet xmlns:search="http://marklogic.com/appservices/search"> <search:match path="/*:html/*:body/*:p[1]"> Text surrounding query <search:highlight>terms</search:highlight> is highlighted and truncated according to configuration. </search:match> </search:snippet>