KWIC module: formats query results to display <em>keywords in context</em> (KWIC). A configurable amount of text is displayed to the left and right of a matching keyword (or phrase). The module works with all indexes that support match highlighting (matches are tagged with an <exist:match> element or exist:matches attribute). This includes the old full text index, the new Lucene-based full text index, as well as the NGram index. The <b>kwic:summarize()</b> function represents the main entry point into the module. To have more control over the text extraction context, you can also call <b>kwic:get-summary()</b> instead. For example, the following snippet will only print the first match within a given set of context nodes ($ancestor): <pre> let $matches := kwic:get-matches($hit)<br/> for $ancestor in $matches/ancestor::para | $matches/ancestor::title | $matches/ancestor::td<br/> return<br/> kwic:get-summary($ancestor, ($ancestor//exist:match, $ancestor//*[
kwic:expand($hit as element()) as element()
Expand the element in $hit. Creates an in-memory copy of the element and marks all element matches with an exist:match tag and attribute matches with an exist:matches tag, which will be used by all other functions in this module. You need to call kwic:expand before kwic:get-summary. kwic:summarize will call it automatically.
$hit | $hit |
kwic:get-matches($hit as element()) as element()*
Return all matches within the specified element, $hit. Matches are returned as exist:match elements or elements with exist:matches attribute. The returned nodes are part of a new document whose root element is a copy of the specified $hit element.
$hit | an arbitrary XML element which has been selected by one of the full text operations or an ngram search. |
kwic:get-summary($root as node(), $node as element(), $config as element()?) as element()
$root | $root |
$node | $node |
$config? | $config? |
kwic:get-summary($root as node(), $node as element(), $config as element()?, $callback as function(*)?) as element()
Print a summary of the match in $node. Output a predefined amount of text to the left and the right of the match.
$root | root element which should be used as context for the match. It defines the boundaries for the text extraction. Text will be taken from this context. |
$node | the exist:match element or the element with |
$config? | configuration element which determines the behaviour of the function |
$callback? | (optional) reference to a callback function which will be called once for every text node before it is appended to the displayed text. The function should accept 2 parameters: 1) a single text node, 2) a string indicating the current direction in which text is appended, i.e. $kwic:MODE_BEFORE or $kwic:MODE_AFTER. The function may return the empty sequence if the current node should be ignore (e.g. if it belongs to a "footnote" which should not be displayed). Otherwise it should return a single string. |
kwic:summarize($hit as element(), $config as element()?) as element()*
$hit | $hit |
$config? | $config? |
kwic:summarize($hit as element(), $config as element()?, $callback as function(*)?) as element()*
Main function of the KWIC module: takes the passed element and returns an XHTML fragment containing a chunk of text before and after the first full text match in the node. The optional config parameter is used to configure the behaviour of the function: <config width="character width" table="yes|no" link="URL to which the match is linked"/> By default, kwic:summarize returns an XHTML fragment with the following structure: <p xmlns="http://www.w3.org/1999/xhtml"> <span class="previous">Text before match</span> <a href="passed URL if any" class="hi">The highlighted term</a> <span class="following">Text after match</span> </p> If table=yes is passed with the config element, a tr table row will be returned instead of a span (using the same class names).
$hit | an arbitrary XML element which has been selected by one of the full text operations or an ngram search. |
$config? | configuration element to configure the behaviour of the function |
$callback? | $callback? |