From: Jens Ø. P. <oe...@gm...> - 2013-10-26 10:21:10
|
Hi Wolfgang, OK, I think I understand. A search retrieves a node, and if that node is an attribute, there is no way of inserting <exist:match> markup into it, because attributes cannot contain markup. I guess then that there are two ways of highlighting. One is that used by the kwic module in conjunction with the full-text and ngram modules. Here every hit is wrapped up in <exist:match>, to be used for highlighting, e.g. with kwic. Now, it is a little strange (at least to me) that this markup is not visible, that is, that one can output the result of a full-text query as $result, with no <exist:match> showing anywhere, whereas $result//exist:match shows the matches. How does one access (and manipulate) this markup? Does this markup disappear when, for instance, one runs the result of a full-text query through a function (see below) that removes any <pb/> element (Ingo's problem). Is that why such an approach does not work? If one tries to remove an element that is not there, that is, when the function defaults throughout, <exist:match> persists, but if one removes an element that does exist, <exist:match> disappears. Also, if one does not intend to use <exist:match>, is there an overhead in applying it? Could there be an ft:query with an option to do without this markup? Another way of highlighting is to run the result through a transform, á la <http://joewiz.tumblr.com/post/54729725793/xquerys-missing-third-function>, but here one can obviously get false highlights, if the queried expression occurs outside the queried context. One can, however, output attributes as text nodes and highlight them. Cheers, Jens declare function local:remove-elements($nodes as node()*, $remove as xs:anyAtomicType+) as node()* { for $node in $nodes return if ($node instance of element()) then if ((local-name($node) = $remove)) then () else element {node-name($node)} {$node/@*, local:remove-elements($node/node(), $remove)} else if ($node instance of document-node()) then local:remove-elements($node/node(), $remove) else $node } ; On 25 Oct 2013, at 22:41, wol...@ex... wrote: >> kwic:summarize() can only take an element as the first parameter, >> >> http://exist-db.org/exist/apps/fundocs/view.html?uri=http://exist-db.org/xquery/kwic#summarize.3 >> >> so an attribute won't do. >> >> I thought tricking it by wrapping the attribute value in an element would do the job, > > No, the kwic module requires that all matches are highlighted. eXist’s match highlighter wraps matches into <exist:match> tags, which are then processed by kwic:summarize. For attributes this simply doesn’t work. > > For a while we marked matches in attributes using escape characters, but most of the time one doesn’t really want attributes to be modified, so the feature was removed. If several users need this we could think about a better approach. > > Wolfgang |