From: Wolfgang <wol...@ex...> - 2009-02-28 20:57:53
|
The exist:match tags are added by the serializer, i.e. when your query results are written out. They are not part of the original document (we are not allowed to change that at query time) and can thus not be found by an expressions like yours: $title := $rec/header//did/unittitle/exist:match However, the trunk version of eXist - and I definitely recommend using the trunk version for this - provides a function util:expand(), which creates a copy of a given node with all fulltext matches marked. Using this, you can indeed query for exist:match tags, e.g. let $expanded := util:expand($hit) for $match in $expanded//exist:match So this would be close to what you tried to do. Our KWIC search functionality on the website uses this technique (footnote: for a description of the KWIC search stuff, see Joe's tutorial: http://en.wikibooks.org/wiki/XQuery/Keyword_Search). > The problem is that I can't use them for anything. For example, I > structure my query so that I get back the elements with the keywords, > but also several levels up in order to be able to pull other information > about the file. Another option would be to create your query bottom-up, i.e. your full text expression returns elements at the level of unittitle. From these, use the parent:: and ancestor:: axis to walk up the document tree to select the required context information. This approach doesn't require util:expand and will thus work with your 1.2.2 version. An example on the Shakespeare plays is available in the XQuery Sandbox ("Show the context of a match"): for $speech in //SPEECH[near(LINE, 'to be or not')] let $scene := $speech/ancestor::SCENE, $act := $scene/ancestor::ACT, $play := $scene/ancestor::PLAY return <hit> <play title="{$play/TITLE}"> <act title="{$act/TITLE}"> <scene title="{$scene/TITLE}">{$speech}</scene> </act> </play> Wolfgang |