KWIC module: formats query results to display keywords in context (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). This includes the old full text index, the new Lucene-based full text index, as well as the NGram index. The kwic:summarize() function represents the main entry point into the module. To have more control over the text extraction context, you can also call kwic:get-summary() instead. For example, the following snippet will only print the first match within a given set of context nodes ($ancestor):
let $matches := kwic:get-matches($hit)
for $ancestor in $matches/ancestor::para | $matches/ancestor::title | $matches/ancestor::td
return
kwic:get-summary($ancestor, ($ancestor//exist:match)[1], $config)
Retrieve the following and preceding text chunks for a given match.
Module URI | Function Name |
---|---|
http://www.w3.org/2005/xpath-functions | exists |
Return all matches within the specified element, $hit. Matches are returned as exist:match elements. The returned nodes are part of a new document whose root element is a copy of the specified $hit element.
Print a summary of the match in $node. Output a predefined amount of text to the left and the right of the match.
Module URI | Function Name |
---|---|
http://www.w3.org/2005/xpath-functions | not |
Module URI | Function Name |
---|---|
http://exist-db.org/xquery/kwic | string-length |
truncate-following | |
truncate-previous |
Module URI | Function Name |
---|---|
http://exist-db.org/xquery/kwic | summarize |
Computes the total string length of the nodes in the argument sequence
Module URI | Function Name |
---|---|
http://www.w3.org/2005/xpath-functions | exists |
string-length | |
sum |
Module URI | Function Name |
---|---|
http://exist-db.org/xquery/kwic | get-summary |
Like fn:substring, but takes a node argument. If the node is an element, a new element is created with the same node-name as the old one and the shortened text content.
Module URI | Function Name |
---|---|
http://www.w3.org/2005/xpath-functions | node-name |
substring |
Module URI | Function Name |
---|---|
http://exist-db.org/xquery/kwic | truncate-following |
truncate-previous |
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).
Module URI | Function Name |
---|---|
http://exist-db.org/xquery/kwic | get-summary |
Generate the right-hand context of the match. Returns a sequence of nodes and strings, whose total string length is less than or equal to $max characters. Note: this function calls itself recursively until $nodes is empty or the returned sequence has the desired total string length.
Module URI | Function Name |
---|---|
http://www.w3.org/2005/xpath-functions | empty |
string-length |
Module URI | Function Name |
---|---|
http://exist-db.org/xquery/kwic | substring |
truncate-following |
Module URI | Function Name |
---|---|
http://exist-db.org/xquery/kwic | get-summary |
truncate-following |
Generate the left-hand context of the match. Returns a sequence of nodes and strings, whose total string length is less than or equal to $max characters. Note: this function calls itself recursively until $nodes is empty or the returned sequence has the desired total string length.
Module URI | Function Name |
---|---|
http://www.w3.org/2005/xpath-functions | empty |
string-length |
Module URI | Function Name |
---|---|
http://exist-db.org/xquery/kwic | substring |
truncate-previous |
Module URI | Function Name |
---|---|
http://exist-db.org/xquery/kwic | get-summary |
truncate-previous |