Module URI

http://exist-db.org/xquery/kwic

Module Description

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)

Variables

   

Function Summary

 

Function Detail

display-text
 
get-context

Retrieve the following and preceding text chunks for a given match.

External Functions that are used by this Function
Module URIFunction Name
  
http://www.w3.org/2005/xpath-functionsexists
 
get-matches

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.

 
get-summary

Print a summary of the match in $node. Output a predefined amount of text to the left and the right of the match.

External Functions that are used by this Function
Module URIFunction Name
  
http://www.w3.org/2005/xpath-functionsnot
Internal Functions used by this Function
Module URIFunction Name
  
http://exist-db.org/xquery/kwicstring-length
truncate-following
truncate-previous
Internal Functions that invoke this Function
Module URIFunction Name
  
http://exist-db.org/xquery/kwicsummarize
 
string-length

Computes the total string length of the nodes in the argument sequence

External Functions that are used by this Function
Module URIFunction Name
  
http://www.w3.org/2005/xpath-functionsexists
string-length
sum
Internal Functions that invoke this Function
Module URIFunction Name
  
http://exist-db.org/xquery/kwicget-summary
 
substring

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.

External Functions that are used by this Function
Module URIFunction Name
  
http://www.w3.org/2005/xpath-functionsnode-name
substring
Internal Functions that invoke this Function
Module URIFunction Name
  
http://exist-db.org/xquery/kwictruncate-following
truncate-previous
 
summarize

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).

Internal Functions used by this Function
Module URIFunction Name
  
http://exist-db.org/xquery/kwicget-summary
 
truncate-following

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.

External Functions that are used by this Function
Module URIFunction Name
  
http://www.w3.org/2005/xpath-functionsempty
string-length
Internal Functions used by this Function
Module URIFunction Name
  
http://exist-db.org/xquery/kwicsubstring
truncate-following
Internal Functions that invoke this Function
Module URIFunction Name
  
http://exist-db.org/xquery/kwicget-summary
truncate-following
 
truncate-previous

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.

External Functions that are used by this Function
Module URIFunction Name
  
http://www.w3.org/2005/xpath-functionsempty
string-length
Internal Functions used by this Function
Module URIFunction Name
  
http://exist-db.org/xquery/kwicsubstring
truncate-previous
Internal Functions that invoke this Function
Module URIFunction Name
  
http://exist-db.org/xquery/kwicget-summary
truncate-previous
 
 
Created by xqDoc-Lite version 1.0 on Wed Jul 29 22:58:02 CEST 2009