tf:containsText

Search for word tokens in a search string.

Top of page

Related Syntax Constructs

The following construct(s) refer to this construct:


Syntax

tf:containsText(node $input, string $searchString) => boolean

Description

This text retrieval function searches a node for a string, consisting of one or more words and returns true if the node contains the word tokens in the specified order.

With tf:containsText 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.

Arguments

$input

node in which the search takes place

$searchString

string containing a sequence of one or more words to be searched

Examples

  • Retrieve all patients who are responding to current treatment:

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

    This query returns all the names of all patients for which tf:containsText returns true. This is the case for all remarks nodes in which the word tokens "responding", "to" and "treatment" follow after one. Given the sample data, Bloggs is the only patient.

    It is equivalent to the following query formulated using tf:containsAdjacentText, which also respects the token order and searches for the three tokens following directly one after another, using the distance value "1":

    for $a in input()/patient
    where tf:containsAdjacentText($a/remarks, 1, "responding", "to", "treatment")
    return $a/name
  • Retrieve all books about TCP/IP:

    for $a in input()/bib/book
    where tf:containsText($a/title, "TCP*IP")
    return $a/title