xml - Search based on count of particular word -
below sample xml file.
<docs> <doc> <name>doc 1</name> <info>hurray</info> </doc> <doc> <name>doc 2</name> <info>brinjal king of vegetables.</info> </doc> <doc> <name>doc 3</name> <info>alexandar great king. desire conquer world , rule world king.</info> </doc> <doc> <name>doc 4</name> <info>i love cherries.</info> </doc> <doc> <name>doc 5</name> <info>mango king of fruits. alphonso king of mangoes. alphonso king's king.</info> </doc> </docs>
i want search tag word "king" , return output. know simple... :)
but order of should in order of word searched (here king) ie numbers come first.
doc 5 (3 times king) doc 3 (2 times king) doc 2 (1 time king)
as asked question before on basex mailing list assume using basex processor. assuming $doc
holds provided xml input, following shows desired result:
for $e in $doc//doc let $copy := copy $c := $e/info modify () return $c let $count := ft:count($copy[. contains text 'king']) order $count descending $count > 0 return <result>{$e/name}<count>{$count}</count></result>
there 2 things special here:
- the
$copy
statement simple copy , necessary, becauseft:count
expecting database node input. if fragment in database don't need this. ft:count
vendor-specific basex, unfortunately not part of full text specification.
Comments
Post a Comment