XQuery Function Documentation

Search and Browse

util:index-keys

util:index-keys($node-set as node()*, $start-value as xs:anyAtomicType?, $function-reference as function(*), $max-number-returned as xs:int?, $index as xs:string) as item()*

Can be used to query existing range indexes defined on a set of nodes. All index keys defined for the given node set are reported to a callback function. The function will check for indexes defined on path as well as indexes defined by QName.

Parameters:
$node-set* The node set
$start-value? Only index keys of the same type but being greater than $start-value will be reported for non-string types. For string types, only keys starting with the given prefix are reported.
$function-reference The function reference as created by the util:function function. It can be an arbitrary user-defined function, but it should take exactly 2 arguments: 1) the current index key as found in the range index as an atomic value, 2) a sequence containing three int values: a) the overall frequency of the key within the node set, b) the number of distinct documents in the node set the key occurs in, c) the current position of the key in the whole list of keys returned.
$max-number-returned? The maximum number of returned keys
$index The index in which the search is made
Returns:
item()* : the results of the eval of the $function-reference

Detailed Description

Get index statistics from most indexes. Statistics include index keys, frequency of the key in a data set and across documents. The function supports the following indexes: 1. Structural index (frequency of elements and attributes in data set) 2. New range index 3. Lucene full text index 4. NGram index # Usage The following code prints a summary of all element and attribute names indexed for a given collection and shows the frequency of each name in the collection and the number of documents it appears in: ```xquery <elements> { util:index-keys(collection("/db/test"), (), function($key, $count) { <element name="{$key}" count="{$count[1]}" docs="{$count[2]}"/> }, -1, "structural-index") } </elements> ``` To list all terms starting with the string "kin" in the lucene index for a given node set, use the following code: ```xquery xquery version "3.1"; declare namespace tei="http://www.tei-c.org/ns/1.0"; <terms> { util:index-keys(collection("/db/apps/shakespeare")//tei:sp, "kin", function($key, $count) { <term name="{$key}" count="{$count[1]}" docs="{$count[2]}"/> }, -1, "lucene-index") } </terms> ``` Please note that the node set passed in the first argument does need to contain elements for which an index had been defined (otherwise nothing will be returned). # Index names The default names for indexes are as follows: Name|Index ----|----- structural-index|Structural index lucene-index|Lucene-based full text index range-index|New range index