Search word tokens within some distance, but without order.

Top of page

Related Syntax Constructs

The following construct(s) refer to this construct:


tf:containsNearText(node $input, integer $distance, token+ $word) => boolean


The function tf:containsNearText is specific to Tamino. It searches a node for a sequence of one or more word tokens within a specified proximity distance and in token order. If the argument $node evaluates to the empty sequence, false is returned.

The $distance argument determines how far apart the matched word tokens in the node may be. The distance is evaluated as the maximum number of unmatched tokens between the first matched word token and the last matched word token. The function returns true, if $distance is larger than this computed distance. For example, a value of "1" means they must follow immediately after one another, a value of 2 allows a gap of one word in between etc.

With tf:containsNearText you can perform search operations including the use of a wildcard character. The section Pattern Matching in the XQuery 4 User Guide explains this in detail.



node to be searched


integer value denoting proximity distance


a word token


  • Retrieve all patients who are responding to current treatment:

    for $a in input()/patient
    where tf:containsNearText($a/remarks, 2, "treatment", "responding")
    return $a/name

    This query returns all the names of all patients for which tf:containsNearText returns true. This is the case for all remarks nodes in which the words "treatment" and "responding" are within a distance of two word, i.e., at most one word token may be in-between. Given the sample data, Bloggs is the only patient.