[XQZone General] returning snippets centered on matches...

Travis Raybold travis at raybold.com
Tue Oct 4 14:06:58 PDT 2005

im searching a data node, and want to return just a subset of the text, 
centered on the matching string. i've modified some code kelly sent me, 
and it works fairly well, but a search that used to take a fraction of a 
second now takes 5 seconds. has anyone coded a function to return 
snippets instead of the whole text that are reasonably efficient? i 
could code this in php, but it seems a natural place to use marklogic, 
if i can just figure out how to make it efficient.

thanks in advance for any help, the sample code follows



let $string := "totalitarian"

let $query := cts:element-word-query(xs:QName("data"),$string)


for $class in (cts:search(//class,$query))




let $scope := 5


let $hit := 


let $hit-text := cts:highlight($class,$query,<span 


let $before := 
tokenize(substring-before($hit,"<TRAVISRAYBOLDCONSTANT_END>")," ")

let $after := 
tokenize(substring-after($hit,"<TRAVISRAYBOLDCONSTANT_START>")," ")


let $before-count := count($before)

let $before-snippet := $before[($before-count - $scope) to $before-count]

let $after-snippet := $after[1 to $scope]


let $snippet := <snippet>. . . . 
")} . . . . </snippet>


let $hilight-snippet :=



return $hilight-snippet



-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3174 bytes
Desc: S/MIME Cryptographic Signature
Url : http://xqzone.marklogic.com/pipermail/general/attachments/20051004/987459fa/smime.bin

More information about the General mailing list