Hi Pradeep,
If you look in the cts:highlight chapter of the Developer's Guide in the
documentation, it shows the design pattern of using cts:highlight to
create snippets. The idea is to do your search, then do a recursive
transformation over each search result and retrieve what you are
interested in. The following query against the Shakespeare database
shows this pattern:
xquery version "1.0-ml";
declare function local:truncate($x as item()) as item()*
{
typeswitch ($x)
case element(HIGHLIGHTME) return $x/node()
case element(TITLE) return if ($x/../../PLAY) then $x else ()
default return for $z in $x/node() return local:truncate($z)
};
let $query := "to be or not to be"
for $x in cts:search(doc(), $query)
return
local:truncate(cts:highlight($x, $query,
<HIGHLIGHTME>{$cts:node/parent::element()}</HIGHLIGHTME>))
(:
returns:
<TITLE>The Tragedy of Hamlet, Prince of Denmark</TITLE>
<LINE>To be, or not to be: that is the question:</LINE>
:)
Hope that helps,
-Danny
From: [email protected]
[mailto:[email protected]] On Behalf Of Pradeep
Maddireddy
Sent: Monday, February 23, 2009 1:29 PM
To: General Mark Logic Developer Discussion
Subject: [MarkLogic Dev General] Hit Highlight Snippet
Hi..!
I need to write a xquery module to search for a string in all the
documents of a database and return the URI's and a snippet of the
element where the search string is found I tried cts:highlight but it
returns the entire document but I just need the element in which the
search string is found.
Thanks in advance
Pradeep Maddireddy
_______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general