XQuery Full Text extends XQuery with full text searches. The following examples can be run on the Shakespeare's play A Midsummer Night's Dream put in XML format by Jon Bosak.
The lines containing the word hath:
//LINE[ . contains text "hath" ]
On the other hand, the following query retrieves the lines containing the string hath:
//LINE[contains(., "hath")]
The lines containing both the words death and abjure:
//LINE[ . contains text "death" ftand "abjure" ]
The lines containing either the word death or the word abjure:
//LINE[ . contains text "death" ftor "abjure" ]
The lines containing the word death but not the word abjure:
//LINE[ . contains text "death" ftand ftnot "abjure" ]
The lines containing the word Demetrius in this case:
//LINE[ . contains text "Demetrius" using case sensitive ]
The lines containing the word Orléans with this accent:
//LINE[ . contains text "Orléans" using diacritics sensitive]
The lines containing the word hate or related words by stemming:
//LINE[ . contains text "hate" using stemming using language "en"]
The lines containing the word love at least twice:
//LINE[ . contains text "love" occurs at least 2 times ]
The lines containing both words death and abjure at a distance of at least two words:
//LINE[ . contains text "death" ftand "abjure" distance at least 2 words ]
Other distance variants are: at most, exactly, from x to y
The lines that contain the word love sorted in decreasing order of relevance:
for $hit score $score in //LINE[ . contains text "love" ] order by $score descending return <hit score="{$score}">{$hit}</hit>
The keyword score introduces a variable that receives the score value. This value is guaranteed to be between 0 and 1: a higher value means a more relevant hit. The computation of relevance is implementation-dependent. A few output lines follow:
<hit score="0.620"> <LINE>Sweet love,--</LINE> </hit> <hit score="0.452"> <LINE>my sweet love?</LINE> </hit> <hit score="0.452"> <LINE>Asleep, my love?</LINE> </hit> <hit score="0.357"> <LINE>Love takes the meaning in love's conference.</LINE> </hit>