« Return to Thread: Full-Text Search Questions
(:
First, this runs findRoots(), which finds all the leaf elements that contain a match, and then converts that to the set of CHAPTER, PGBLK, and TASK
elements that contain matches. This is roughly equivalent to finding the matched in the virtually burst documents.
findLocalHits() then allows us to find the nodes that match within each root. This is used to provide a hit count as well as a list of matching nodes.
sort() puts the nodes in order.
This is fairly complex to create and to understand because of the way full-text search works. Full text search matches on any node where any node beneath
it contains a match. To make this work in a full AMM, we have to filter the ancestor nodes out from the leaf collection, then walk back up the ancestors to
find the closest one to the match.
Because of the complexity of the queries, we run into a performance problem at the point where we get the hit count. We have to find the number of hits and
then sort on them. The way this works, that can't be optimized into the initial search query.
:)
declare function local:findRoots($s as xs:string)
{
((collection('amm')/descendant::element()[. &= $s]) except (collection('amm')/descendant::element()[. &= $s]/ancestor::element()))/ancestor::*[name(.) = ('CHAPTER', 'PGBLK', 'TASK')][1]
};
declare function local:findLocalHits($root, $s as xs:string)
{
for $i in ($root/descendant::element()[. &= $s]) except ($root/descendant::element()[. &= $s]/ancestor::element())
where $root eq $i/ancestor::*[name(.) = ('CHAPTER', 'PGBLK', 'TASK')][1]
return $i
};
declare function local:sort($roots, $s)
{
for $i in $roots
order by count(local:findLocalHits($i, $s)) descending
return $i
};
declare function local:search($s as xs:string, $loc as xs:integer)
{
<root count="{count(local:findRoots($s))}">
{
for $i in subsequence(local:sort(local:findRoots($s), $s), $loc, 20)
let $hits := local:findLocalHits($i, $s)
return
<match tag="{name($i)}" key="{$i/@KEY}" title="{$i/TITLE}" hits="{count($hits)}">
{
for $j in $hits
return <hit>{$j}</hit>
}
</match>
}
</root>
};
local:search("information", 20)
« Return to Thread: Full-Text Search Questions
| Free Forum Powered by Nabble | Forum Help |