<?xml version="1.0" encoding="UTF-8"?>
<!-- note: need to add all termdefs, otherwise termrefs dont work : but XQ contains dupes of termdefs in intro --><!-- SB 2004-01-28: added entities date.day thru ndash, removed "xpath-backwards-compat", "errors", "XQ" --><!DOCTYPE spec SYSTEM "../../schema/xsl-query.dtd">
<spec xmlns:e="http://www.w3.org/1999/XSL/Spec/ElementSyntax" id="spec-top" w3c-doctype="wd">
<header>
<title>XQuery 1.0 and XPath 2.0 Full-Text</title>
<w3c-designation>WD-xquery-full-text-20060501</w3c-designation>
<w3c-doctype>W3C Working Draft</w3c-doctype>
<pubdate>
 <day>1</day>
 <month>May</month>
 <year>2006</year>
</pubdate>

<publoc>
   <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/TR/2006/WD-xquery-full-text-20060501/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">http://www.w3.org/TR/2006/WD-xquery-full-text-20060501/</loc>
</publoc>

<altlocs>
   <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/TR/2006/WD-xquery-full-text-20060501/full-text.xml" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">XML</loc>
</altlocs>

<latestloc>
  <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/TR/xquery-full-text/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">http://www.w3.org/TR/xquery-full-text/</loc>
</latestloc>

<prevlocs>
  <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/TR/2005/WD-xquery-full-text-20051103/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest"/>
  <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/TR/2005/WD-xquery-full-text-20050915/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest"/>
  <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/TR/2005/WD-xquery-full-text-20050404/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest"/>
  <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/TR/2004/WD-xquery-full-text-20040709/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest"/>
</prevlocs>

<authlist>
<author>
	<name>Sihem Amer-Yahia</name>
	<affiliation>AT&amp;T Labs - Research</affiliation>
	<email xmlns:xlink="http://www.w3.org/1999/xlink" href="mailto:sihem@research.att.com" xlink:type="simple" xlink:show="new" xlink:actuate="onRequest">sihem@research.att.com</email>
</author>
<author>
	<name>Chavdar Botev</name>
	<affiliation>Invited Expert</affiliation>
	<email xmlns:xlink="http://www.w3.org/1999/xlink" href="mailto:cbotev@cs.cornell.edu" xlink:type="simple" xlink:show="new" xlink:actuate="onRequest">cbotev@cs.cornell.edu</email>
</author>
<author>
	<name>Stephen Buxton</name>
	<affiliation>Mark Logic Corporation</affiliation>
	<email xmlns:xlink="http://www.w3.org/1999/xlink" href="mailto:stephen.buxton@marklogic.com" xlink:type="simple" xlink:show="new" xlink:actuate="onRequest">stephen.buxton@marklogic.com</email>
</author>
<author>
	<name>Pat Case</name>
	<affiliation>Library of Congress</affiliation>
	<email xmlns:xlink="http://www.w3.org/1999/xlink" href="mailto:pcase@crs.loc.gov" xlink:type="simple" xlink:show="new" xlink:actuate="onRequest">pcase@crs.loc.gov</email>
</author>
<author>
        <name>Jochen Doerre</name>
        <affiliation>IBM</affiliation>
        <email xmlns:xlink="http://www.w3.org/1999/xlink" href="mailto:doerre@de.ibm.com" xlink:type="simple" xlink:show="new" xlink:actuate="onRequest">doerre@de.ibm.com</email>
</author>
<author>
	<name>Mary Holstege</name>
	<affiliation>Mark Logic Corporation</affiliation>
	<email xmlns:xlink="http://www.w3.org/1999/xlink" href="mailto:mary.holstege@marklogic.com" xlink:type="simple" xlink:show="new" xlink:actuate="onRequest">mary.holstege@marklogic.com</email>
</author>
<author>
	<name>Darin McBeath</name>
	<affiliation>Elsevier</affiliation>
	<email xmlns:xlink="http://www.w3.org/1999/xlink" href="mailto:D.McBeath@elsevier.com" xlink:type="simple" xlink:show="new" xlink:actuate="onRequest">D.McBeath@elsevier.com</email>
</author>
<author>
	<name>Michael Rys</name>
	<affiliation>Microsoft</affiliation>
	<email xmlns:xlink="http://www.w3.org/1999/xlink" href="mailto:mrys@microsoft.com" xlink:type="simple" xlink:show="new" xlink:actuate="onRequest">mrys@microsoft.com</email>
</author>
<author>
	<name>Jayavel Shanmugasundaram</name>
	<affiliation>Invited Expert</affiliation>
	<email xmlns:xlink="http://www.w3.org/1999/xlink" href="mailto:jai@cs.cornell.edu" xlink:type="simple" xlink:show="new" xlink:actuate="onRequest">jai@cs.cornell.edu</email>
</author>
</authlist>

<abstract>
<p>This document defines the syntax and formal semantics of XQuery 1.0 and XPath 2.0 Full-Text
which is a language that extends XQuery 1.0 <bibref ref="xquery"/> and XPath 2.0 <bibref ref="xpath20"/> with full-text search capabilities.</p>
</abstract>


<status>
<p><emph>This section describes the status of this document at the
time of its publication. Other documents may supersede this
document. A list of current W3C publications and the latest revision
of this technical report can be found in the <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/TR/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">W3C technical reports index</loc> at
http://www.w3.org/TR/.</emph></p>

<p>This is a public W3C Working Draft for review by W3C members and
other interested parties. Publication as a Working Draft does not
imply endorsement by the W3C Membership. This is a draft document and
may be updated, replaced or obsoleted by other documents at any
time. It is inappropriate to cite this document as other than work in
progress.</p>

<p>
This is the fifth version of this document. Since the last version
was published, several technical and editorial changes have been made
to all the sections of the document. Among the most significant
changes are: the addition of a section describing the processing model
for full-text search and how it integrates with the XQuery Processing
Model; the reformulation of the AllMatches model so that a primitive
match (TokenInfo) now can represent an interval of token positions,
and hence, a match of a phrase (in the former version phrases were
modeled using distance constraints, which had certain unwanted
implications when distance operators were explicitly applied to
phrases); the restriction of the FTTimes operation to simple
FTSelections; and several simplifications in the semantics functions
that the latter two changes made possible, like the removal of the
AllMatches normalization. The XQuery functions that are used to
define the semantics of the full-text operations have been thoroughly
revised and are now syntax- and type-checked.</p>

<p>This document has been produced
following the procedures set out for the W3C Process. This document
was produced through the efforts of <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/XML/Query" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">XML Query Working Group</loc> and
the <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/Style/XSL/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">XSL Working Group</loc>
(both part of the <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/XML/Activity.html" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">XML
Activity</loc>). It is designed to be read in conjunction with the
following documents: W3C XQuery and XPath Full-Text Requirements
<bibref ref="xqueryft-requirements"/> and the W3C XQuery Full-Text Use
Cases <bibref ref="xmlquery-full-text-use-cases"/>.</p>


<p>Public comments on this document and its open issues are invited.
Comments should be entered into the
<loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/Bugs/Public/buglist.cgi?query_format=advanced&amp;product=XPath+%2F+XQuery+%2F+XSLT&amp;component=FT+Use+Cases&amp;component=Full+Text&amp;bug_status=NEW&amp;bug_status=ASSIGNED&amp;bug_status=REOPENED&amp;bugidtype=include&amp;cmdtype=doit&amp;order=Reuse+same+sort+as+last+time" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">issue tracking system</loc>
for this specification (instructions can be found at
<loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/XML/2005/04/qt-bugzilla" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">http://www.w3.org/XML/2005/04/qt-bugzilla</loc>). 
If access to that system is not feasible, you may send your
comments to the W3C mailing list,
<loc xmlns:xlink="http://www.w3.org/1999/xlink" href="mailto:public-qt-comments@w3.org" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">public-qt-comments@w3.org</loc>
(<loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://lists.w3.org/Archives/Public/public-qt-comments/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">
http://lists.w3.org/Archives/Public/public-qt-comments/</loc>) with
"[FT]" at the beginning of the subject field of email messages
involving such comments.</p>

<p>This document was produced by groups operating under the
<loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/Consortium/Patent-Policy-20040205/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">5
February 2004 W3C Patent Policy</loc>. W3C maintains public lists of
any patent disclosures made in connection with the deliverables
of the
<loc xmlns:xlink="http://www.w3.org/1999/xlink" role="disclosure" href="http://www.w3.org/2002/08/xmlquery-IPR-statements" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">XML
Query Working Group</loc>
and the
<loc xmlns:xlink="http://www.w3.org/1999/xlink" role="disclosure" href="http://www.w3.org/Style/XSL/Disclosures" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">XSL 
Working Group</loc>;
those pages also include instructions for disclosing a patent. An
individual who has actual knowledge of a patent which the individual
believes contains
<loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/Consortium/Patent-Policy-20040205/#def-essential" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">Essential Claim(s)</loc>
must disclose the information in accordance with
<loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/Consortium/Patent-Policy-20040205/#sec-Disclosure" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">section 6 of the W3C Patent Policy</loc>.</p>

</status>

<langusage>
		<language id="EN">English</language>
		<language id="ebnf">EBNF</language>
</langusage>
	
<revisiondesc>

<p>SA January 2004: First version of document before Feb F2F</p>
<p>SA 26 February 2004: Second version of document before Feb F2F
    meetings.</p>

</revisiondesc>

</header><body>
<!-- *********************************************************************
      Section 1. Introduction
     ********************************************************************* -->

<div1 id="introduction">
  <head>Introduction</head>

  <p>This document defines the language and the formal semantics of
  XQuery 1.0 and XPath 2.0 Full-Text. This language is designed to meet the requirements
  identified in W3C XQuery and XPath Full-Text Requirements
  <bibref ref="xqueryft-requirements"/> and to support the queries in
  the W3C XQuery Full-Text Use Cases <bibref ref="xmlquery-full-text-use-cases"/>. </p> 

  <p>XQuery 1.0 and XPath 2.0 Full-Text extends the syntax and semantics of XQuery 1.0 and
  XPath 2.0. </p>

	<div2 id="tq-ftsearch-xml">
		<head>Full-Text Search and XML</head> 

<p>As XML becomes mainstream, users expect to be able to 
search their XML documents. This requires a standard way to do
full-text search, as well as structured searches, against XML
documents.  A similar requirement for full-text search led ISO to
define the <!-- <loc
href="ftp://sqlstandards.org/SC32/WG4/Progression_Documents/CD/cd-fulltext-2001-05.pdf">SQL/MM-FT
standard</loc>.  --> SQL/MM-FT <bibref ref="sqlmm"/> standard.
SQL/MM-FT <bibref ref="sqlmm"/> defines extensions to SQL to express
full-text searches providing similar functionality as does this full-text
language extension to XQuery 1.0 and XPath 2.0.
</p>

<p>XML documents may contain highly-structured data (numbers, dates),
unstructured data (untagged free-flowing text), and semi-structured
data (text with embedded tags). Where a document contains unstructured
or semi-structured data, it is important to be able to search using
Information Retrieval techniques such as scoring and weighting.</p>

<p>Full-text search is different from substring search in many ways:</p>

<olist>
<item><p>A full-text search searches for tokens and phrases
rather than substrings. A substring search for news items that contain
the string "lease" will return a news item that contains "Foobar
Corporation releases the 20.9 version ...". A full-text search for the
token "lease" will not. </p>
</item>

<item><p>There is an expectation that a full-text search will support
language-based searches which substring search cannot. An
example of a language-based search is "find me all the news items that
contain a token with the same linguistic stem as "mouse" (finds "mouse"
and "mice"). Another example based on token proximity is "find me all
the news items that contain the tokens "XML" and
"Query" allowing up to 3 intervening words.</p>
</item>

<item>
<p>Full-text search must address the vagaries and nuances of
language. Search results  are often of varying usefulness. When
you search a web site for cameras that cost less than $100, this
is an exact search.  There is a set of cameras that matches this search,
and a set that does not.  Similarly, when you do a string search across
news items for "mouse", there is only 1 expected result set. When you
do a full-text search for all the news items that contain the
token "mouse", you probably expect to find news items containing the token
"mice", and possibly "rodents", or possibly "computers".  Not
all results are equal. Some results are more "mousey" than others.
Because full-text search may be inexact, we have the notion of score
or relevance. We generally expect to see the most relevant results at
the top of the results list.</p>
<p>As XQuery and XPath evolve, they
 may apply the notion of
score to querying structured data. For example, when making travel
plans or shopping for cameras, it is sometimes useful to get an
ordered list of near matches in addition to exact matches. If
 XQuery and XPath define a generalized 
inexact match, we expect XQuery and XPath to utilize the scoring
framework provided by XQuery and XPath Full-Text.
</p>
</item>
</olist>

<p>The following definitions apply to full-text search:</p>

<olist>

<item>
<p><termdef id="Full-TextQueriesDef" term="Full-TextQueries"><term>Full-text queries</term> are 
   performed on tokens and phrases. Tokens and phrases are produced via
   tokenization.</termdef> Informally, tokenization breaks a character string into a 
    sequence of words, units of punctuation, and spaces.</p>
</item>

<item>
<p><termdef id="TokenDef" term="Token">A <term>token</term> is defined as a character, n-gram, or sequence of
characters returned by a tokenizer as a basic unit to be
searched. Each instance of a token consists of one or more consecutive
characters.  Beyond that, tokens are implementation-defined.</termdef> Note that
consecutive tokens need not be separated by either punctuation or
space, and tokens may overlap. <termdef id="PhraseDef" term="Phrase">A <term>phrase</term> is an ordered sequence of any number of tokens. Beyond that,
 phrases are implementation-defined.</termdef></p> 

<note><p>In some natural languages, tokens and words can be used
interchangeably.</p></note>
</item>

<item>
<p>Tokenization enables functions and operators that operate on a
part or the root of the token (e.g., wildcards, stemming). </p>

<p>Tokenization enables functions and operators which work with the
relative positions of tokens (e.g., proximity operators). </p>

<p>Tokenization also
uniquely identifies sentences and paragraphs in which tokens appear. <termdef id="SentenceDef" term="Sentence">A <term>sentence</term> is an ordered sequence of any number of tokens. Beyond that,
      sentences are implementation-defined. A tokenizer is not required to support
      sentences.</termdef> <termdef id="ParagraphDef" term="Paragraph">A <term>paragraph</term> is an ordered sequence of any number of tokens. Beyond that,
      paragraphs are implementation-defined. A tokenizer is not required to support paragraphs.</termdef> Whatever a
tokenizer for a particular language chooses to do, it must preserve
the containment hierarchy: paragraphs contain sentences which contain
tokens. </p>

<p>The tokenizer has to evaluate two equal strings in the same
way, i.e., it should identify the same tokens. Everything else is 
implementation-defined.</p>
</item>


<item>
<p>
This specification focuses on functionality that serves all
languages. It also selectively includes functionalities useful within
specific families of languages. For example, searching within
sentences and paragraphs is useful to many western languages and to
some non-western languages, so that functionality is incorporated into
this specification.
</p>
</item>

<item>
<p>
Some XML elements represent semantic
markup, e.g., &lt;title&gt;. Others represent formatting markup, e.g.,
&lt;b&gt; to indicate bold.  Semantic markup serves well as token
boundaries, while formatting markup sometimes does not. Implementations
are free to provide implementation-defined ways to differentiate between 
the markup's effect on token boundaries during tokenization.
</p>
</item>


<!--<item>
<p>We use the namespace "ft" (for full-text) that corresponds to the
URL http://www.w3.org/2004/07/xquery-full-text and defines the namespace of
full-text search. We also use "fts" for definitional purposes in <loc
href="#tq-semantics">semantics Section</loc>.
</p>
</item>
-->

</olist>
</div2>

<div2 id="tq-ft-organization">
 <head>Organization of this document</head> 

<p>This document is organized as follows. We first present a <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#tq-extensions" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">high level syntax</loc> for the XQuery 1.0 and XPath 2.0 Full-Text
language along with some examples. Then, we present the <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftselections" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">syntax and examples</loc> of the
basic primitives in the XQuery 1.0 and XPath 2.0 Full-Text language. This is followed by the
<loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#tq-semantics" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">semantics</loc> of the XQuery 1.0 and XPath 2.0 Full-Text
language. The appendix contains a section that provides an <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#id-xpath-grammar" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">EBNF for the XPath 2.0 Grammar with Full-Text
extensions</loc>, an <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#id-grammar" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">EBNF for XQuery 1.0
Grammar with Full-Text extensions</loc>, <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ft-acknowledgements" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">acknowledgements</loc> and a <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ft-glossary" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">glossary</loc>.</p>

	</div2>

<div2 id="tq-ft-namespaces">
  <head>A word about namespaces</head>

<p>Certain namespace prefixes are predeclared by XQuery 1.0 and, by implication, by this specification,
and bound to fixed namespace URIs. These namespace prefixes are as follows:
</p>

<ulist>

<item>
<p>
<code>xml = http://www.w3.org/XML/1998/namespace</code>
</p>
</item>

<item>
<p>
<code>xs = http://www.w3.org/2001/XMLSchema</code>
</p>
</item>

<item>
<p>
<code>xsi = http://www.w3.org/2001/XMLSchema-instance</code>
</p>
</item>

<item>
<p>
<code>fn = http://www.w3.org/2005/xpath-functions</code>
</p>
</item>

<item>
<p>
<code>xdt = http://www.w3.org/2005/xpath-datatypes</code>
</p>
</item>

<item>
<p>
<code>local = http://www.w3.org/2005/xquery-local-functions</code>
</p>
</item>

</ulist>

<p>
In addition to the prefixes in the above list, this document uses the prefix
<code>err</code> to represent the namespace URI <code>http://www.w3.org/2005/xqt-errors</code>, 
This namespace prefix is not predeclared and its use in this document is not normative. 
Error codes that are not defined in this document are defined in other XQuery 1.0 and XPath 2.0
specifications, particularly <bibref ref="xpath20"/> and <bibref ref="xpath-functions"/>. 
</p>

<p>
Finally, this document uses the prefix <code>fts</code> to represent a namespace
containing a number of functions used in this document to describe the semantics
of XQuery 1.0 and XPath 2.0 Full-Text functions. There is no
requirement that these functions be implemented, therefore no URI is associated with that prefix. 
</p>

</div2>
  
</div1>



<!--
2. TeXQuery Expressions
2.1.  FTContainsExpr 
2.2.  Scoring
2.3   Extensions to the Static Context

-->
<div1 id="tq-extensions">
   <head>Full-Text Extensions to XQuery and XPath</head>
<p>XQuery 1.0 and XPath 2.0 Full-Text extends the languages of XQuery
1.0 and XPath 2.0 in three ways. It:</p> 

<olist>
  <item><p>Adds a new expression called FTContainsExpr;</p>

  </item>
  <item><p>Enhances the syntax of FLWOR expressions in XQuery 1.0 and
  <code>for</code> expressions in XPath 2.0 with optional score
  variables; and</p>
  </item>

  <item><p>Adds static context declarations for full-text match
  options to the query prolog.</p>
  </item>
</olist>

<p>Additionally, it extends the data model and processing models in
various ways.</p>

<div2 id="processing-model">
<head>Processing Model</head>

<p>
As part of the External Processing that is described in the XQuery
Processing Model, when an XML document is parsed into an Infoset/PSVI
and ultimately into a XQuery Data Model instance, an
implementation-defined full-text process, called tokenization is
usually executed.</p> 

<p>
Tokenization, in general terms, is the process of converting a text
string into smaller units that are used in query processing. Those
units, called tokens, are the most basic text units that a full-text
search can refer to. Full-text operators typically work on sequences
of token occurrences found in the target text (nodes) of a
search. These token occurrences are characterized by unique
identifiers that capture the relative position of the token inside the
string, the relative position of the sentence containing the token,
and the relative position of the paragraph containing the token.</p>

<p>
The tokenization process is implementation-dependent. For example, the
tokenization may differ from domain to domain and from language to
language. This specification will only impose a very few number of
constraints on the semantics of a correct tokenizer. As a consequence,
all the examples in this document are only given for explanation
purposes but they are not mandatory, i.e. the result of such full-text
queries will of course depend on the tokenizer that is being used.</p>

<p>
A full-text expression or <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#section-ftcontainsexpr" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTContainsExpr</loc>, evaluated within
the normal Query Processing (XQuery Processing Model), is composed of
several parts:</p>
<olist>
  <item><p>An XPath 2.0 or XQuery 1.0 expression (RangeExpr) that
  specifies the sequence of items to be searched. Those items are called
  the search context.</p>
  </item>
  <item><p>
  The full-text selection to be applied (<loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftselections" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTSelections</loc>). FTSelections 
  are, syntactically and semantically, fully composable and contain:
  </p>
  <ulist>
    <item><p>
    Required:</p>
    <ulist>
      <item><p>
      Words and phrases for which a search is performed (FTWords).</p>
      </item>
    </ulist>
    </item>
    <item><p>
    Optional:</p>
    <ulist>
      <item><p>
      Match options, such as indicators for case sensitivity and stop
      words (FTMatchOptions);</p>
      </item>
      <item><p>
      Boolean full-text operators, that compose an FTSelection from
      simpler FTSelections;</p>
      </item>
      <item><p>
      Other full-text operators that are constraints on the positions of
      matches, such as indicators for distance between tokens and for the
      cardinality of matches; and</p>
      </item>
      <item><p>
      The weighing information. Each individual search term in an
      FTSelection may be annotated with optional weight information. This
      information may be used during the evaluation of the FTSelections to
      calculate scoring, information that quantifies the relevance of the
      result to the given search criteria.</p>
      </item>
    </ulist>
    </item>
  </ulist>
  </item>
  <item><p>
  An optional Xpath 2.0 or XQuery 1.0 expression (UnionExpr) that
  specifies the set of nodes, descendents of the RangeExp, which
  contents may be ignored for the purpose of determining a match
  during the search (<loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftignoreoption" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTIgnoreOption</loc>).</p>
  </item>
</olist>

<p>
The results of the evaluation of the FTSelection operators are
instances of the AllMatches model, which complements the XQuery Data
Model (XDM) for processing full-text queries. An AllMatches instance
describes all possible solutions to the full-text query for a given
search context item. Each solution is described by a Match instance. A
Match instance contains the tokens from the search context that must
be included (described using StringInclude instances which model the
positive terms) and the tokens from search context item that must be
excluded (described using StringExclude instances which model the
negative terms). Each negative or positive term is modeled as a tuple:
the position of the query word or phrase in the FTSelection, and a
TokenInfo structure that describes a consecutive sequence of token
occurrences in the text string which match the query word or phrase.
</p>

<graphic xmlns:xlink="http://www.w3.org/1999/xlink" source="images/ProcMod-XQueryFT.gif" alt="Processing Model Extensions" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>

<p>Figure 1 provides a schematic overview of the XQuery 1.0 and XPath
2.0 Full-Text processing steps that are discussed in detail below. 
Some of these steps are completely outside the domain of XQuery; in
Figure 1, these are depicted outside the black line that represents
the boundaries of language. The diagram only shows the central pieces
of the XQuery Processing Model (see <xspecref spec="XQ" ref="id-processing-model"/>), however zooms in on the Execution Engine
where the processing of the Full-Text extensions takes place. The
full-text processing steps are labeled as FTn within the diagram and
are referenced within the text.</p>

<p>
Like all XQuery expressions, an FTContainsExpr returns an XDM
Instance (see Fig. 1). With the exception of FTWords, which consumes TokenInfos,
all FTSelections are closed under the AllMatches data model,
i.e., their input and output are AllMatches instances. Tokenization
normally occurs at the time of parsing of the original XML 
documents, for example, during the Data Model Generation process (see
Figure 1). But here it may also occur "on-the-fly" transforming an XDM
instance into TokenInfos, which ultimately get converted into AllMatches
instances by the evaluation of FTSelections. Thus, the evaluation of
nested full-text and XQuery expressions instances moves back and forth
between these two models.
</p>

<p>
The resulting AllMatches instance obtained by the evaluation of a Full
Text expression is converted into a Boolean value before being
returned to the enclosing XPath or XQuery operation as follows. If at
least one member of the disjunction contains only positive terms then
value returned is true. If all members of the disjunction contain
negative terms the result is false.
</p>

<p>
Weighing information, in an implementation-dependent fashion, may be
used when calculating the scoring information computed and made
available by FTContainsExpr to the optional score construct.
</p>

<p>
Section 3 describes the syntax and the informal semantics of Full Text
operators. Their formal semantics is defined in Section 4. The
AllMatches data model is formally defined in Section 4.
</p>

<p>
Given the components of a given Full Text expression, the evaluation
algorithm will proceed according to the following steps, also referenced in the processing model diagram as steps FT<emph>n</emph> (see Fig. 1):
</p>

<olist>
  <item><p>
  Evaluate the search context expression, resulting in the set of
  search context items; (FT1 provides the evaluation of any Xpath 2.0
  or XQuery 1.0 expressions that generates or modifies the search
  context, as well as the query string(s) in a partially evaluated
  FTSelection expression)</p>
  </item>
  <item><p>
  Evaluate the (optional) ignore expression, resulting in the set of ignored
  nodes and virtually delete the ignore nodes from the search context
  nodes tree. (Included in FT1)</p>
  </item>
  <item><p>
  Apply the tokenization algorithm to query string(s). (FT2.1 -- this is
  implementation-dependent)</p>
  </item>
  <item><p>
  For each search context item:</p>
  <olist>
    <item><p>
    Apply the tokenization algorithm in order to extract potentially
  matching terms
    together with their positional information. This step results in a
  sequence of token occurrences. (FT2.2 -- this is
  implementation-dependent)</p> 
    </item>
    <item><p>
    Evaluate the simple "FTWord" operators in the FTSelection against
    the tokenized input. This results in a set of AllMatches instances.
  (FT3)</p>
    </item>
    <item><p>
    Evaluate the rest of the FTSelection operator tree in a bottom up
    fashion. At each step the AllMatches instance produced by the
    previous steps are given as input, and a new instance of the
    AllMatches is obtained as output. At each step the FTMatchOptions
    are controlling the semantics of the application of the FTWords
    operator. (FT4)</p>
    </item>
  </olist>
  </item>
  <item><p>
  Convert the AllMatches instance into a Boolean value. (FT5)</p>
  </item>
</olist>

<p>
The additional scoring information (also part of FT5) that is produced
by the evaluation 
of the Full Text expression is implementation dependent and is not
specified in this document and is made available at the same time the
Boolean value is returned.
</p>
</div2>

   <div2 id="section-ftcontainsexpr">
      <head>Expression FTContainsExpr</head>
<p>As a syntactic construct an FTContainsExpr behaves similar to a
comparison expression (see <xspecref spec="XQ" ref="id-general-comparisons"/>).
This grammar rule introduces FTContainsExpr.</p>


   <scrap headstyle="show">
<head/>
<prod num="50" id="noid_N103CB.doc-xquery-ComparisonExpr"><lhs>ComparisonExpr</lhs><rhs><nt def="doc-xquery-FTContainsExpr">FTContainsExpr</nt> ( (<nt def="prod-xquery-ValueComp">ValueComp</nt><br/>|  <nt def="prod-xquery-GeneralComp">GeneralComp</nt><br/>|  <nt def="prod-xquery-NodeComp">NodeComp</nt>)  <nt def="doc-xquery-FTContainsExpr">FTContainsExpr</nt> )?</rhs></prod>

</scrap>
<p>An FTContainsExpr may be used anywhere a ComparisonExpr may be
used. FTContainsExprs have higher precedence than comparison
operators,  so the results of FTContainsExpr may be compared without
enclosing them in parentheses.</p>

<div3 id="section-ftcontainsexpr-description">
      <head>FTContainsExpr Description</head>


<scrap headstyle="show">
<head/>
<prod num="51" id="doc-xquery-FTContainsExpr"><lhs>FTContainsExpr</lhs><rhs><nt def="prod-xquery-RangeExpr">RangeExpr</nt> ( "ftcontains"  <nt def="doc-xquery-FTSelection">FTSelection</nt>  <nt def="doc-xquery-FTIgnoreOption">FTIgnoreOption</nt>? )?</rhs></prod>
</scrap><p>An FTContainsExpr returns a Boolean
value. It returns true, if there is some node in
RangeExpr that, after <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#TokenizationSec" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">tokenization</loc>, matches FTSelection. For the purpose of determining
a match, certain descendants of nodes in RangeExpr
may be ignored, as specified in 
FTIgnoreOption.</p>

   </div3>
   <div3 id="section-ftcontainsexpr-examples">
   <head>FTContainsExpr Examples</head>

<p>The following example in extended XQuery 1.0 returns the author of
each book with a title containing a token with the same root as
<code>dog</code> and the token
<code>cat</code>.

		<eg role="xquery" xml:space="preserve">
for $b in /books/book
where $b/title ftcontains ("dog" with stemming) &amp;&amp; "cat" 
return $b/author</eg>
</p>
		<p>The same example in extended XPath 2.0 is written as:

		<eg role="xpath" xml:space="preserve">

/books/book[title ftcontains ("dog" with stemming) &amp;&amp; "cat"]/author</eg>
</p>
   </div3>

	</div2>

	<div2 id="section-score-variables">
	<head>Score Variables</head>
	<p>Besides specifying a match of a full-text 
        search as a Boolean condition, full-text search applications
        typically also have the ability to associate scores with
        the results. <termdef id="Scores" term="Scores"><term>Scores</term> express the relevance of 
      those results to the full-text search conditions.</termdef></p>

        <p>XQuery 1.0 and XPath 2.0 Full-Text extends the languages of
        XQuery 1.0 and XPath 2.0 further  by adding optional 
        <code>score</code> variables to the <code>for</code> and
        <code>let</code> clauses of FLWOR expressions.</p>

        <p>The production for the extended <code>for</code> clause follows.


<scrap headstyle="show">
<head/>
<prod num="35" id="doc-xquery-ForClause"><lhs>ForClause</lhs><rhs>"for"  "$"  <nt def="prod-xquery-VarName">VarName</nt>  <nt def="prod-xquery-TypeDeclaration">TypeDeclaration</nt>?  <nt def="prod-xquery-PositionalVar">PositionalVar</nt>?  <nt def="doc-xquery-FTScoreVar">FTScoreVar</nt>?  "in"  <nt def="prod-xquery-ExprSingle">ExprSingle</nt>  (","  "$"  <nt def="prod-xquery-VarName">VarName</nt>  <nt def="prod-xquery-TypeDeclaration">TypeDeclaration</nt>?  <nt def="prod-xquery-PositionalVar">PositionalVar</nt>?  <nt def="doc-xquery-FTScoreVar">FTScoreVar</nt>?  "in"  <nt def="prod-xquery-ExprSingle">ExprSingle</nt>)*</rhs></prod>
<prod num="37" id="doc-xquery-FTScoreVar"><lhs>FTScoreVar</lhs><rhs>"score"  "$"  <nt def="prod-xquery-VarName">VarName</nt></rhs></prod>
</scrap> 
</p>

<p>When a <code>score</code> variable is present in a <code>for</code> 
clause the evaluation of the expression following the <code>in</code>
keyword not only needs to determine the result sequence of the
expression, i.e., the sequence of items which are iteratively
bound to the <code>for</code> variable. It must also determine in each
iteration the relevance "score" value of the current item
and bind the <code>score</code> variable to that value. </p> 

<p>In the following example <code>book</code> elements are determined that satisfy
the condition <code>[content ftcontains "web site" &amp;&amp; "usability" and
.//chapter/title ftcontains "testing"]</code>. The scores assigned to the
<code>book</code> elements are returned.

		<eg role="xquery" xml:space="preserve">
for $b score $s 
    in /books/book[content ftcontains "web site" &amp;&amp; "usability" 
                   and .//chapter/title ftcontains "testing"]
return $s
</eg>
</p>

<p>XPath 2.0 Full-Text extends the language of XPath
2.0 in the <code>for</code> expression in the same 
way: with optional score variables. The example above is
also a legal example of the XPath 2.0 extension.</p>

<p>Scores are typically used to order results, as in the 
following, more complete example.
		<eg role="xquery" xml:space="preserve">
for $b score $s 
    in /books/book[content ftcontains "web site" &amp;&amp; "usability"]
where $s &gt; 0.5
order by $s descending
return &lt;result&gt;  
          &lt;title&gt; {$b//title} &lt;/title&gt; 
          &lt;score&gt; {$s} &lt;/score&gt; 
       &lt;/result&gt;
</eg>
</p>

<p>The <code>score</code> variable is bound to a value which reflects
the relevance of the match criteria in the 
FTSelections to the nodes in the respective RangeExprs. The
calculation of relevance is implementation-dependent, but score
evaluation must follow these rules:</p>

<olist>
<item><p>Score values are of type xs:double in the range
[0, 1].</p></item> 
<item><p>For score values greater than 0, a higher score must imply a
higher degree of relevance </p></item>
</olist>

<p>Similar to their use in a <code>for</code> clause, score variables
may be specified in a <code>let</code> clause. A score variable in a
<code>let</code> clause is also bound to the score of the expression
evaluation, but in the <code>let</code> clause one score is determined
for the complete result. The <code>let</code> variable may be dropped
from the <code>let</code> clause, if the
<code>score</code> variable is present.</p>

<p>The production for the extended <code>let</code> clause follows.


<scrap headstyle="show">
<head/>
<prod num="38" id="doc-xquery-LetClause"><lhs>LetClause</lhs><rhs>(("let"  "$"  <nt def="prod-xquery-VarName">VarName</nt>  <nt def="prod-xquery-TypeDeclaration">TypeDeclaration</nt>?  <nt def="doc-xquery-FTScoreVar">FTScoreVar</nt>?)  |  ("let"  "score"  "$"  <nt def="prod-xquery-VarName">VarName</nt>))  ":="  <nt def="prod-xquery-ExprSingle">ExprSingle</nt>  (","  (("$"  <nt def="prod-xquery-VarName">VarName</nt>  <nt def="prod-xquery-TypeDeclaration">TypeDeclaration</nt>?  <nt def="doc-xquery-FTScoreVar">FTScoreVar</nt>?)  |  <nt def="doc-xquery-FTScoreVar">FTScoreVar</nt>)  ":="  <nt def="prod-xquery-ExprSingle">ExprSingle</nt>)*</rhs></prod>
</scrap> 
</p>

<p>While when using the score option in a <code>for</code> clause the
expression following the <code>in</code> keyword has the dual purpose
of filtering, i.e., driving the iteration, and determining the scores,
it is possible to separately specify expressions for filtering and
scoring by combining a simple <code>for</code> clause with a
<code>let</code> clause that uses scoring. The following is 
an example of this.

		<eg role="xquery" xml:space="preserve">
for $b in /books/book[.//chapter/title ftcontains "testing"]
let score $s := $b/content ftcontains "web site" &amp;&amp; "usability" 
order by $s descending
return &lt;result score="{$s}"&gt;{$b}&lt;/result&gt;
</eg>
This example returns <code>book</code> elements with chapter titles that contain "testing". Along with the <code>book</code> elements scores are returned. These scores, however, reflect whether the book content contains "web site" and "usability".</p>

<p>Note that it is not a requirement of the score of an 
FTContainsExpr to be 0, if the expression evaluates to false, nor to
be non-zero, if the expression evaluates to true.
Hence, in the example above it is not possible to infer the Boolean
value of the FTContainsExpr in the <code>let</code> clause from the
calculated score of a returned <code>result</code> element. For instance, an
implementation may want to assign a non-zero score to a book that
contained only "web site", but not "usability", as this may be
considered more relevant than a book that does not contain either of
both.
</p>




<p>The use of <code>score</code> variables introduces a second-order
aspect to the evaluation of expressions which cannot be emulated by
(first-order) XQuery functions. Consider the following replacement of
the clause <code>let score $s := FTContainsExpr</code></p>

		<eg xml:space="preserve">
let $s := score(FTContainsExpr)
</eg>

<p>where a function <code>score</code> is applied to some
FTContainsExpr. If the function <code>score</code> were first-order, it
would only be applied to the result of the evaluation of 
its argument, which is one of the Boolean constants <code>true</code>
or <code>false</code>. Hence, there would be at most two possible
values such a <code>score</code> function would be able to return and
no further differentiation would be possible. </p>


   <div3 id="section-using-weights">
      <head>Using Weights Within a Scored FTContainsExpr</head>

<p><termdef id="WeightDeclarationsDef" term="WeightDeclarations">Scoring may be influenced by adding <term>weight declarations</term> to search tokens, phrases, and expressions.</termdef>
Syntactically weight declarations are introduced in the FTSelection
production, described in <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftselections" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTSelections</loc>.
		<eg role="xquery" xml:space="preserve">
for $b in /books/book
let score $s := $b/content ftcontains ("web site" weight 0.2)
                                  &amp;&amp; ("usability" weight 0.8)
return &lt;result score="{$s}"&gt;{$b}&lt;/result&gt;
</eg>
</p>

<p>The effect of weights on the result score is
implementation-dependent. However, weight declarations must follow
these rules:</p> 
<olist>
<item><p>Weights in an FTContainsExpr are significant only in relation
to each other; and</p></item>
<item><p>When no explicit weight is specified, the default weight is 0.5.</p></item>
</olist>

<p>
Weight declarations in an FTContainsExpr for which no scores are
evaluated are ignored. 
</p>

   </div3>
	</div2>


   <div2 id="section-extensions-static-context">
      <head>Extensions to the Static Context</head>
<p>
The XQuery Static Context is extended by a component for each of the
full-text match options. Thus, the default of a match option in a
query may be changed by providing a setting in the static context using the
following declaration syntax.
<scrap headstyle="show"><head/>
	<prod num="6" id="doc-xquery-Prolog"><lhs>Prolog</lhs><rhs>((<nt def="prod-xquery-DefaultNamespaceDecl">DefaultNamespaceDecl</nt>  |  <nt def="prod-xquery-Setter">Setter</nt>  |  <nt def="prod-xquery-NamespaceDecl">NamespaceDecl</nt>  |  <nt def="prod-xquery-Import">Import</nt>)  <nt def="prod-xquery-Separator">Separator</nt>)*  ((<nt def="prod-xquery-VarDecl">VarDecl</nt>  |  <nt def="prod-xquery-FunctionDecl">FunctionDecl</nt>  |  <nt def="prod-xquery-OptionDecl">OptionDecl</nt>  |  <nt def="doc-xquery-FTOptionDecl">FTOptionDecl</nt>)  <nt def="prod-xquery-Separator">Separator</nt>)*</rhs></prod>
	<prod num="14" id="doc-xquery-FTOptionDecl"><lhs>FTOptionDecl</lhs><rhs>"declare"  "ft-option"  <nt def="doc-xquery-FTMatchOption">FTMatchOption</nt></rhs></prod>
</scrap>
Match options modify the match semantics of full-text
expressions. They are described in detail in  
Section <specref ref="ftmatchoptions"/>. When a match
option is specified explicitly in a query, that
setting overrides the setting of the respective match option in the
static context.
</p>



   </div2>
</div1>


<div1 id="ftselections">
	<head>FTSelections</head>
 <p>This section describes 
FTSelections which contain the full-text
operators in the <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#tq-extensions" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTContainsExpr</loc>, and
the match options in <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftmatchoptions" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTMatchOptions</loc>
which modify the matching semantics of the full-text selection
expressions. </p>

<p>The <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftselections" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTSelection</loc> production
specifies the possible full-text search conditions. </p>

<scrap headstyle="show">
<head/>
<prod num="144" id="doc-xquery-FTSelection"><lhs>FTSelection</lhs><rhs><nt def="doc-xquery-FTOr">FTOr</nt>  (<nt def="doc-xquery-FTMatchOption">FTMatchOption</nt>  |  <nt def="prod-xquery-FTProximity">FTProximity</nt>)*  ("weight"  <nt def="prod-xquery-RangeExpr">RangeExpr</nt>)?</rhs></prod>
</scrap>

<p>The "weight" value is the result of evaluating ExprSingle and can
be any numeric value.</p>

<p>The syntax and semantics of the individual full-text selection
operators follow.</p>


<p>This XML document fragment
is the source document for examples in this section. </p>
<p>Tokenization is implementation-defined. A sample tokenization is
used for the examples in this section. The results may be different
for other tokenizations.</p> <p>Unless stated otherwise, the results
assume a case-insensitive match.</p>

 <eg xml:space="preserve">&lt;book number="1"&gt;
  &lt;title shortTitle="Improving Web Site Usability"&gt;Improving  
      the Usability of a Web Site Through Expert Reviews and
      Usability Testing&lt;/title&gt;
   &lt;author&gt;Millicent Marigold&lt;/author&gt;
   &lt;author&gt;Montana Marigold&lt;/author&gt;
   &lt;editor&gt;Véra Tudor-Medina&lt;/editor&gt;
   &lt;content&gt;
     &lt;p&gt;The usability of a Web site is how well the  
         site supports the users in achieving specified  
         goals. A Web site should facilitate learning,  
         and enable efficient and effective task  
         completion, while propagating few errors.
     &lt;/p&gt;
     &lt;note&gt;This book has been approved by the Web Site  
         Users Association.
     &lt;/note&gt;
   &lt;/content&gt;
 &lt;/book&gt;</eg>

<div2 id="ftoperators">
      <head>Full-Text Operators</head>
      
<p>
<termdef id="Full-TextOperatorsDef" term="Full-TextOperators">
<term>Full-text operators</term> perform operations on tokens, phrases, and 
expressions. Some require that the relative positions of tokens in the document
be known (e.g., proximity operators).</termdef>
</p>
       
<div3 id="ftwords">
	<head>FTWords</head>

<p> <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftwords" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTWords</loc> specifies the tokens and phrases
that are being searched as the left-hand side argument of <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#tq-extensions" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTContainsExpr</loc>.</p>

<scrap headstyle="show">
<head/>
<prod num="150" id="doc-xquery-FTWords"><lhs>FTWords</lhs><rhs><nt def="doc-xquery-FTWordsValue">FTWordsValue</nt>  <nt def="doc-xquery-FTAnyallOption">FTAnyallOption</nt>?</rhs></prod>
<prod num="151" id="doc-xquery-FTWordsValue"><lhs>FTWordsValue</lhs><rhs><nt def="prod-xquery-Literal">Literal</nt>  |  ("{"  <nt def="prod-xquery-Expr">Expr</nt>  "}")</rhs></prod>
<prod num="166" id="doc-xquery-FTAnyallOption"><lhs>FTAnyallOption</lhs><rhs>("any"  "word"?)  |  ("all"  "words"?)  |  "phrase"</rhs></prod>
</scrap>
	

<p>An FTWords is an FTWordsValue followed by the optional modifier
FTAnyallOption.  
The right-hand side of FTWordsValue is an XQuery expression which must
evaluate to a sequence of string values or nodes of type
"xs:string". The result is 
then atomized into a sequence of strings which is tokenized into a
sequence of tokens and phrases. If the atomized sequence is not a
subtype of "xs:string*", an error is raised: <xerrorref spec="XP" class="TY" code="0004" type="type"/>. 
</p>

<p>If the "any" option is specified, a match occurs, if and only if at least
one token or phrase in the sequence has a match in the searched text.</p>

<p>If the "all" option is specified, a match occurs, if and only if
all of the tokens and phrases in the sequence are matched in the
searched text.</p>

<p>If the "phrase" option is specified, all words and phrases are used
to create a sequence of ordered words representing a new phrase. A
match occurs, if and only if the resulting phrase is matched in the
searched text.</p>

<p>If the "any word" option is specified, a match occurs, if and only
if at least one token in the sequence of tokens and phrases is matched
in the searched text.</p>

<p>If the "all word" option is specified, a match occurs, if and only
if all tokens in the sequence of tokens and phrases are matched in the
searched text.</p>

<p>If no option is specified, "any" is the default.</p>

<p>If the result is a single string, "any", "all", and "phrase" are
equivalent.</p>

<!-- <p>If Expr results in the empty sequence or the tokenization results
in a zero-length phrase, this is discussed in the issue 
<loc href="#zero-length-phrase">zero-length-phrase (Cluster G, Issue 47)</loc>.</p>
-->

<!-- <p>Note: The results assume a case-insensitive match in the following
expressions.</p>-->


<eg role="xpath" xml:space="preserve">/book[@number="1" and ./title ftcontains "Expert"]</eg>

<p>returns the <code>book</code> element whose <code>number</code> is
1, because its <code>title</code> element contains the token "Expert".</p>

<eg role="xpath" xml:space="preserve">/book[@number="1" and ./title ftcontains "Expert Reviews"]</eg>

<p>returns the <code>book</code> element whose <code>number</code> is
1, because its <code>title</code> element contains the phrase "Expert
Reviews".</p>

<eg role="xpath" xml:space="preserve">/book[@number="1" and ./title ftcontains {"Expert",
"Reviews"} all]</eg>

<p>returns the <code>book</code> element whose <code>number</code> is
1, because its <code>title</code> element contains two tokens "Expert"
and "Reviews".</p>

 
<eg role="xpath" xml:space="preserve">/book[@number="1"]//p ftcontains "Web Site Usability"</eg> 

<p>returns false, because the <code>p</code> element doesn't contain
the phrase "Web Site Usability" although it contains all of the tokens
in the phrase.</p>


<eg role="xquery" xml:space="preserve">for $book in /book[.//author ftcontains "Marigold"] 
let score $score := $book/title ftcontains "Web Site Usability" 
where $score &gt; 0.8 
order by $score descending
return $book/@number</eg> 

<p> returns <code>book</code> numbers of <code>book</code> elements by
"Marigold" with a title about "Web Site Usability" sorting them in
descending score order. </p>


</div3>
<div3 id="ftor">
	<head>FTOr</head>

<scrap headstyle="show"><head/>
<prod num="145" id="doc-xquery-FTOr"><lhs>FTOr</lhs><rhs><nt def="doc-xquery-FTAnd">FTAnd</nt> ( "||"  <nt def="doc-xquery-FTAnd">FTAnd</nt> )*</rhs></prod>
</scrap>

<p> <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftor" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTOr</loc> finds matches that satisfy at least
one of the selection criteria. </p>

<p> A match must satisfy at least one of the <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftselections" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTSelection</loc> criteria. </p>

<eg role="xpath" xml:space="preserve"> /book[.//author ftcontains "Millicent" ||
"Voltaire"] </eg>

<p>returns the <code>book</code> element written by "Millicent".</p>
	
</div3>

<div3 id="ftand">
	<head>FTAnd</head>

<scrap headstyle="show"><head/>
<prod num="146" id="doc-xquery-FTAnd"><lhs>FTAnd</lhs><rhs><nt def="doc-xquery-FTMildnot">FTMildnot</nt> ( "&amp;&amp;"  <nt def="doc-xquery-FTMildnot">FTMildnot</nt> )*</rhs></prod>
</scrap>

<p> <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftand" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTAnd</loc> finds matches that satisfy both of
the selection criteria.  </p>

<p> A match must satisfy all of the <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftselections" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTSelection</loc> criteria which are specified by
one or more <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftmildnot" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTMildNot</loc> expressions.</p>

<eg role="xpath" xml:space="preserve">/book[@number="1"]/title ftcontains ("usability" &amp;&amp; "testing")</eg>

<p> returns true, since the <code>book</code> <code>title</code> contains
"usability" and "testing".</p>

<eg role="xpath" xml:space="preserve">/book/author ftcontains "Millicent" &amp;&amp; "Montana"</eg>

<p> returns false, because "Millicent" and "Montana" are not contained
by the same <code>author</code> element in any <code>book</code>
element.</p>

</div3>

<div3 id="ftmildnot">
	<head>FTMildNot</head>

<scrap headstyle="show"><head/>
<prod num="147" id="doc-xquery-FTMildnot"><lhs>FTMildnot</lhs><rhs><nt def="doc-xquery-FTUnaryNot">FTUnaryNot</nt> ( "not"  "in"  <nt def="doc-xquery-FTUnaryNot">FTUnaryNot</nt> )*</rhs></prod>
</scrap>

<p><loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftmildnot" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTMildNot</loc> is a milder form
of &amp;&amp; ! (and not). 'a not in b' matches an expression that
contains "a", but not when it is a part of "b".  For example, a search
for "Mexico" not in "New Mexico" returns, among others, a document
which is all about "Mexico" but mentions at the end that "New Mexico
was named after Mexico", which would not be returned by an "and not"
search.</p>

<p> A match to <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftmildnot" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTMildNot</loc> must
contain at least one token occurrence that satisfies the first
condition and does not satisfy the second condition. If it contains a
token occurrence that satisfies both the first and the second
condition, the occurrence is not considered as a result.</p>

<eg role="xpath" xml:space="preserve">/book ftcontains "usability" not in "usability
testing"</eg>

<p>returns true, because "usability" appears in the <code>title</code>
and the <code>p</code> elements and the occurrence within the phrase
"Usability Testing" in the <code>title</code> element is not
considered.</p>

<p>The right-hand side of a <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftmildnot" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTMildNot</loc> may not contain an <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftselections" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTSelection</loc> that evaluates to an
<term>AllMatches</term> that contains a <term>StringExclude</term>. Such <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftselections" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTSelection</loc>s are <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftunarynot" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">
FTUnaryNot</loc> and <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#fttimes" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTTimes</loc> with at most,
from-to, and exactly occurrences ranges. </p>

</div3>


<div3 id="ftunarynot">
	<head>FTUnaryNot</head>

<scrap headstyle="show"><head/>
<prod num="148" id="doc-xquery-FTUnaryNot"><lhs>FTUnaryNot</lhs><rhs>("!")? <nt def="doc-xquery-FTWordsSelection">FTWordsSelection</nt></rhs></prod>
</scrap>

<p><loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftunarynot" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTUnaryNot</loc> finds matches that do not
satisfy the selection criteria. </p>
	
<eg role="xpath" xml:space="preserve">/book[. ftcontains ! "usability"]</eg>

<p>returns the empty sequence, because all <code>book</code> elements
contain "usability".</p>

<eg role="xpath" xml:space="preserve">/book ftcontains "information" &amp;&amp;
"retrieval" &amp;&amp; ! "information retrieval"</eg>

<p>returns true, because <code>book</code> elements contain
"information" and "retrieval" but not "information retrieval".</p>

<eg role="xpath" xml:space="preserve">/book[. ftcontains "web site usability" &amp;&amp; 
!"usability testing"]</eg>

<p>return <code>book</code> elements containing "web site usability"
but not "usability testing".</p>

</div3>

<div3 id="ftorder">
	<head>FTOrder</head>

<scrap headstyle="show"><head/>
<prod num="153" id="doc-xquery-FTOrderedIndicator"><lhs>FTOrderedIndicator</lhs><rhs>"ordered"</rhs></prod>
</scrap>

<p><loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftorder" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTOrder</loc> controls the order of tokens and
phrases to be the same as the order in which they are written in the
query.
</p>

<p> The default is unordered. Unordered is in effect when ordered is
not specified in the query. Unordered cannot be written explicitly in
the query.  </p>

<p> <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftorder" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTOrder</loc> finds matches which must
satisfy the nested selection condition and the match must contain the
tokens in the order specified in the query.</p>

<eg role="xpath" xml:space="preserve">/book/title ftcontains ("web site" &amp;&amp; "usability")
ordered </eg>

<p>returns true, because titles of <code>book</code> elements contain
"web site" and "usability" in the order in which they are written in
the query, i.e., "web site" must precede "usability".</p>

<eg role="xpath" xml:space="preserve">/book[@number="1"]/title ftcontains ("Montana" &amp;&amp;
"Millicent") ordered </eg>

<p>returns false, because although "Montana" and "Millicent" appear in
the <code>title</code> element, they do not appear in the order they
are written in the query. </p>


</div3>
<div3 id="ftscope">
	<head>FTScope</head>

<scrap headstyle="show"><head/>
<prod num="171" id="doc-xquery-FTScope"><lhs>FTScope</lhs><rhs>("same"  |  "different")  <nt def="doc-xquery-FTBigUnit">FTBigUnit</nt></rhs></prod>
<prod num="173" id="doc-xquery-FTBigUnit"><lhs>FTBigUnit</lhs><rhs>"sentence"  |  "paragraph"</rhs></prod>
</scrap>

<p> <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftscope" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTScope</loc> finds tokens and phrases
contained in the same or a different scope. </p>

<p> Possible scopes are sentences and paragraphs. </p>

<p> By default, there are no restrictions on the scope of the
matches. </p>

<p> If two tokens appear in the same sentence and in different
sentences, then both same sentence and different sentence return
true. The same is true for same paragraph and different paragraph.</p>

<eg role="xpath" xml:space="preserve">/book ftcontains "usability"
&amp;&amp; "Marigold" same sentence</eg>

<p> returns false, because the tokens "usability" and "Marigold" are not
contained within the same sentence. </p>

<eg role="xpath" xml:space="preserve">/book ftcontains "usability"
&amp;&amp; "Marigold" different sentence</eg>

<p> returns true, because the tokens "usability" and "Marigold" are
contained within different sentences. </p>

<eg role="xpath" xml:space="preserve">/book[. ftcontains "usability" &amp;&amp; "testing"
same paragraph] </eg>

<p> returns a <code>book</code> element, because it contains
"usability" and "testing" in the same paragraph.</p>

<eg role="xpath" xml:space="preserve">/book[. ftcontains "site" &amp;&amp; "errors"
same sentence] </eg>

<p> returns a <code>book</code> element, because "site" and "errors"
appear in the same sentence. </p>

<p>Some subtle relationships between <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftscope" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTScope</loc> and <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftdistance" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTDistance</loc> will be discussed in <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#tq-semantics" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">Section 4.</loc> </p>

</div3>

<div3 id="ftdistance">
	<head>FTDistance</head>

<scrap headstyle="show"><head/>
<prod num="168" id="doc-xquery-FTDistance"><lhs>FTDistance</lhs><rhs>"distance"  <nt def="doc-xquery-FTRange">FTRange</nt>  <nt def="doc-xquery-FTUnit">FTUnit</nt></rhs></prod>
<prod num="167" id="doc-xquery-FTRange"><lhs>FTRange</lhs><rhs>("exactly"  <nt def="prod-xquery-UnionExpr">UnionExpr</nt>)<br/>|  ("at"  "least"  <nt def="prod-xquery-UnionExpr">UnionExpr</nt>)<br/>|  ("at"  "most"  <nt def="prod-xquery-UnionExpr">UnionExpr</nt>)<br/>|  ("from"  <nt def="prod-xquery-UnionExpr">UnionExpr</nt>  "to"  <nt def="prod-xquery-UnionExpr">UnionExpr</nt>)</rhs></prod>
<prod num="172" id="doc-xquery-FTUnit"><lhs>FTUnit</lhs><rhs>"words"  |  "sentences"  |  "paragraphs"</rhs></prod>
</scrap>

<p> <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftdistance" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTDistance</loc> finds matches by
specifying the distance between tokens and phrases in <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftdistance" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTUnits</loc> (tokens, sentences, and
paragraphs). The number of intervening <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftdistance" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTUnit</loc>s is specified in the integer value of
<loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftdistance" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTRange</loc>. </p>
 
<p><loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftdistance" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTRange</loc> specifies a range of integer
values, providing a minimum and maximum value.  Each <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftdistance" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">UnionExpr</loc> in an <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftdistance" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTRange</loc> must evaluate (after atomization) to
a singleton sequence with an atomic value of type
"xs:integer". Otherwise, an error is raised <xerrorref spec="XP" class="TY" code="0004" type="type"/>. </p>

<p>Let the value of the first (or only) <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftdistance" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">UnionExpr</loc> be M.  If "from" is specified, let
the value of the second <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftdistance" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">UnionExpr</loc> be
N. <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftdistance" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTDistance</loc> may cross element
boundaries when computing distance.</p>

<p>The following rule applies to <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftdistance" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTDistance</loc>:</p>

<ulist>
<item><p> Zero words (sentences, paragraphs) means adjacent tokens
(sentences, paragraphs).</p></item>
</ulist>

<p>If "exactly" is specified, then the range is the closed interval [M, 
M].  If "at least" is specified, then the range is the half-closed interval 
[M, unbounded).  If "at most" is specified, then the range is the closed 
interval [0, M].  If "from-to" is specified, then the range is the closed 
interval [M, N].  </p>

<p>Here are some examples of  <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftdistance" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTRange</loc>s:</p>

<olist><item><p>'exactly 0' specifies the range [0, 0].</p></item>
    <item><p>'at least 1' specifies the range [1,unbounded].</p></item> 
    <item><p>'at most 1' specifies the range [0, 1]. </p></item>
    <item><p>'from 5 to 10' specifies the range [5, 10].</p></item>
</olist>

<p>The distances computed by FTDistance are not affected by the
presence or absence of element boundaries in the text.  Stop words are
counted in those computations whether they are ignored or not.</p>


<eg role="xpath" xml:space="preserve">/book ftcontains ("information" &amp;&amp;
"retrieval") not in ("information" &amp;&amp; "retrieval" 
distance at least 11 words)
</eg>

<p>returns false, because "information" and "retrieval" are more than
at least 11 tokens apart. </p>

<eg role="xpath" xml:space="preserve">/book ftcontains "web" &amp;&amp; "site" &amp;&amp;
"usability" distance at most 2 words</eg>

<p>returns true, because "web", "site", and "usability" have at most 2
intervening tokens between them.</p>

<eg role="xpath" xml:space="preserve">/book[. ftcontains "web site"
&amp;&amp; "usability" distance at most 1 words]/title </eg>

<p>returns the <code>book</code> title. A similar query for the
<code>p</code> element would return false because "web site" and
"usability" have two intervening tokens between them. </p>

<!-- JD, 2005-08-17: need to revise the foll. 2 examples;
<eg role="xpath">/book[@number="1" and . ftcontains ("web site"
&amp;&amp; "completion" &amp;&amp; !  "learning") distance
exactly 15 words]/title
</eg>

<p>returns the
<code>title</code> element, because the token "learning" not appears
within 15 tokens of the tokens "web site" and "completion".</p>

<eg role="xpath">/book[@number="1" and . ftcontains "web site"
&amp;&amp; "completion" distance exactly 15 words same
paragraph]/title </eg>

<p>returns the <code>title</code>
element if the tokens "web site" and "completion" appear within 15
tokens of each other and in the same paragraph.</p>
-->

</div3>

<div3 id="ftwindow">
	<head>FTWindow</head>

<scrap headstyle="show"><head/>
	<prod num="169" id="doc-xquery-FTWindow"><lhs>FTWindow</lhs><rhs>"window"  <nt def="prod-xquery-UnionExpr">UnionExpr</nt>  <nt def="doc-xquery-FTUnit">FTUnit</nt></rhs></prod>
</scrap>


<p><loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftwindow" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTWindow</loc> finds matches within a number
of <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftwindow" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTUnit</loc>s (tokens, paragraphs, and
phrases). The number of <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftwindow" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTUnit</loc>s is
specified as an integer.</p>

<p><loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftwindow" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTWindow</loc> may cross element
boundaries. The size of the window is not affected by the presence or
absence of element boundaries. Stop words are included in those
computations whether they are ignored or not.</p>

<p><loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftwindow" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">UnionExpr</loc> must evaluate to an atom of
type "xs:integer".</p>

<p>A match of an <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftselections" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTSelection</loc> is
considered a match within a window, if there exists a window of the
given number of consecutive units (tokens, sentences, or paragraphs) in
the document within which the match lies.
</p>

<eg role="xpath" xml:space="preserve">/book/title ftcontains "web" &amp;&amp; "site"
&amp;&amp; "usability" window 5 words</eg>

<p>returns true, because "web", "site", and "usability" are within a
window of 5 tokens in the <code>title</code> element.</p>

<eg role="xpath" xml:space="preserve">/book ftcontains ("web" &amp;&amp; "site" ordered)
&amp;&amp; ("usability" || "testing") window 10 words</eg>

<p>returns true, because "web" and "site" in the order they are
written in the query and either "usability" or "testing" are within a
window of at most 10 tokens. </p>

<eg role="xpath" xml:space="preserve">/book//title ftcontains "web site" &amp;&amp;
"usability" window 3 words</eg>

<p>returns true, because the <code>title</code> element contains "Web
Site Usability". A similar query on the <code>p</code> element would not 
return true, 
because its occurrences of "web site" and "usability" are not within a
window of 3.</p>

<eg role="xpath" xml:space="preserve">/book[@number="1" and . ftcontains "efficient" 
&amp;&amp; ! "and" window 3 words]</eg>

<p>returns the empty sequence, because in the selected
<code>book</code> element, there is no occurrence of "efficient"
within a window of 3 tokens which would not also contain an occurrence
of "and".</p>

</div3>

<div3 id="fttimes">
	<head>FTTimes</head>

<scrap headstyle="show"><head/>
			<prod num="170" id="doc-xquery-FTTimes"><lhs>FTTimes</lhs><rhs>"occurs"  <nt def="doc-xquery-FTRange">FTRange</nt>  "times"</rhs></prod>
</scrap>

<p><loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#fttimes" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTTimes</loc> finds matches in which an <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftselections" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTSelection</loc> occurs a specified number of
times. </p>

<p><loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#fttimes" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTTimes</loc> limits the number of different
occurrences of <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftselections" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTSelection</loc>, within the
specified range.  </p>

<p>In the document fragment "very very big":</p>

<olist>

<item>
<p>
The <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftselections" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTSelection</loc> "very big" has 1
occurrence consisting of the second "very" and "big".
</p>
</item>

<item>
<p>
The <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftselections" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTSelection</loc> "very &amp;&amp; big"
has 2 occurrences; one consisting of the first "very" and "big", and
the other containing the second "very" and "big".
</p>
</item>

<item>
<p>
The <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftselections" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTSelection</loc> "very || big" has 3
occurrences. 
</p>
</item>

<item>
<p>
The <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftselections" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTSelection</loc> ! "small" has 1
occurrence.
</p>
</item>

</olist>

<eg role="xpath" xml:space="preserve">/book[. ftcontains "usability" occurs at least 2 times]/@number</eg>

<p>returns <code>book</code> numbers because <code>book</code>
elements contain 2 or more occurrences of "usability".</p>

<eg role="xpath" xml:space="preserve">/book[@number="1" and title ftcontains "usability" ||
"testing" occurs at most 3 times] </eg>

<p>returns the empty sequence, because there are 4 occurrences of
"usability" || "testing" in the designated <code>title</code>.</p>

<eg role="xpath" xml:space="preserve">/book ftcontains "usability" occurs at least 2 times
</eg>

<p>returns true, because the <code>book</code> element contains 3
occurrences of "usability" in its <code>title</code> element although
its <code>p</code> element contains only 1 occurrence.
</p>


</div3>

<div3 id="ftcontent">
	<head>FTContent</head>

<scrap headstyle="show"><head/>
			<prod num="165" id="doc-xquery-FTContent"><lhs>FTContent</lhs><rhs>("at"  "start")  |  ("at"  "end")  |  ("entire"  "content")</rhs></prod>
</scrap>
 
<p><loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftcontent" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTContent</loc> finds matches in which the
tokens and phrases are the first, last or all of the tokens and phrases
in the tokenized form of the items being searched.</p>

<p> The "at" "start" option finds matches in which the tokens or
phrases are the first tokens or phrases in the tokenized string value
of the element being searched.</p>

<p> The "at" "end" option finds matches in which the tokens or phrases
are the last tokens or phrases in the tokenized string value of the
element being searched.</p>
 
<p>The "entire" content" option finds matches in which the tokens or
phrases are the entire content of the tokenized string value of the
element being searched.</p>
 
<eg role="xpath" xml:space="preserve">/books//title[. ftcontains "improving the usability
of a web site" at start]</eg> 

<p>returns each <code>title</code> element starting with the phrase "improving the
usability of a web site".</p>
 
<eg role="xpath" xml:space="preserve">/books//p[. ftcontains "propagat*" &amp;&amp; "few
errors" distance at most 2 words at end]</eg>

<p>returns each <code>p</code> element ending with the phrase
"propagating few errors".</p>
 
<eg role="xpath" xml:space="preserve">/books//note[. ftcontains "this site has been
approved by the web site users association" entire content]</eg>

<p>returns each <code>note</code> element whose entire content is
"this site has been approved by the web site users association".</p>

</div3>


</div2>


<div2 id="ftmatchoptions">
	<head>FTMatchOptions</head>


<p><loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftmatchoptions" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTMatchOptions</loc> modify the
operational semantics of the <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftselections" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTSelection</loc> on which they are applied. </p>

<scrap headstyle="show"><head/>
			<prod num="154" id="doc-xquery-FTMatchOption"><lhs>FTMatchOption</lhs><rhs><nt def="doc-xquery-FTCaseOption">FTCaseOption</nt><br/>|  <nt def="doc-xquery-FTDiacriticsOption">FTDiacriticsOption</nt><br/>|  <nt def="doc-xquery-FTStemOption">FTStemOption</nt><br/>|  <nt def="doc-xquery-FTThesaurusOption">FTThesaurusOption</nt><br/>|  <nt def="doc-xquery-FTStopwordOption">FTStopwordOption</nt><br/>|  <nt def="doc-xquery-FTLanguageOption">FTLanguageOption</nt><br/>|  <nt def="doc-xquery-FTWildCardOption">FTWildCardOption</nt></rhs></prod>
</scrap>

<p><loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftmatchoptions" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTMatchOptions</loc> set 
environments for the matching options of <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftselections" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTSelection</loc>. <termdef id="MatchOptionsDef" term="MatchOptions"><term>Match options</term>  modify the set of tokens and phrases
      in the query. Some of these options (e.g., stemming) have behaviors which
      depend on the language of the document, the language of the query, or both.</termdef> If a match option isn't
specified explicitly in the query, its value is given by its static
context component. Details about these context components, including
their default values, are given in
Appendix <specref ref="id-xqft-static-context-components"/>.</p>

<p>If no match options declarations are present in the prolog and the implementation does not define any overwriting of the static context components for the match options, the query:</p>

<eg role="xpath" xml:space="preserve">/book/title ftcontains "usability" </eg>

<p>is equivalent to the query </p>

<eg role="xpath" xml:space="preserve">/book/title ftcontains "usability" case insensitive 
    diacritics insensitive 
    without stemming without thesaurus  
    without stop words language "none" without wildcards</eg>

<p><loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftmatchoptions" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTMatchOptions</loc> are applied in the
order in which they are written in the query. More information on
their semantics is given in <specref ref="FTMatchOptionsSec"/>.</p>

<p> We describe each match option in more detail in the following
sections.</p>



<div3 id="ftcaseoption">
	<head>FTCaseOption</head>

<scrap headstyle="show"><head/>
			<prod num="155" id="doc-xquery-FTCaseOption"><lhs>FTCaseOption</lhs><rhs>"lowercase"<br/>|  "uppercase"<br/>|  ("case"  "sensitive")<br/>|  ("case"  "insensitive")</rhs></prod>
</scrap>

<p><loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftcaseoption" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTCaseOption</loc> modifies tokens and
phrases matching by specifying how upper and lower charcters are
considered. </p>

<p><loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftcaseoption" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTCaseOption</loc> influences the way
<loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftwords" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTWords</loc> is applied.</p>

<p>There are four possible character case options:</p>

<olist>
<item><p> The option "uppercase" matches tokens and phrases with
uppercase characters, regardless of the case of characters of the
tokens and phrases as they are written in the query.</p></item>

<item><p> The option "lowercase" matches tokens and phrases with
lowercase characters, regardless of the case of characters of the
tokens and phrases as they are written in the query.</p></item>

<item><p> The option "case" "insensitive" matches the uppercase and
lowercase characters of tokens and phrases. The case of characters as
they are written in the query is not considered.</p></item>

<item><p> The option "case" "sensitive" matches the case of the
characters in tokens and phrases as they are written in the
query.</p></item>

</olist>

<p>The default is "case insensitive". </p>

<p>The following table summarizes the interactions between 
the case match options and the use of the default collations.</p>

<p>
 <table border="1">
      <caption>Case Matrix</caption>
      <thead>
       <tr>
        <td rowspan="1" colspan="1">Default collation options/Case options</td>
        <td rowspan="1" colspan="1">UCC (Unicode Codepoint Collation)</td>
        <td rowspan="1" colspan="1">CCS (some generic case-sensitive collation)</td>
        <td rowspan="1" colspan="1">CCI (some generic case-insensitive collation) </td>
       </tr>
      </thead>
      <tbody>
       <tr>
        <td rowspan="1" colspan="1">insensitive</td>
        <td rowspan="1" colspan="1">compare as if both lower</td>
        <td rowspan="1" colspan="1">case-insensitive variant of CCS if it exists, else error</td>
        <td rowspan="1" colspan="1">CCI</td>
       </tr>
       <tr>
        <td rowspan="1" colspan="1">sensitive</td>
        <td rowspan="1" colspan="1">UCC</td>
        <td rowspan="1" colspan="1">CCS</td>
        <td rowspan="1" colspan="1">case-sensitive variant of CCI if it exists, else error</td>
       </tr>
       <tr>
        <td rowspan="1" colspan="1">uppercase</td>
        <td rowspan="1" colspan="1">uppercase(Expr) + UCC</td>
        <td rowspan="1" colspan="1">uppercase(Expr) + CSS</td>
        <td rowspan="1" colspan="1">CCI</td>
       </tr>
       <tr>
        <td rowspan="1" colspan="1">lowercase</td>
        <td rowspan="1" colspan="1">lowercase(Expr) + UCC</td>
        <td rowspan="1" colspan="1">lowercase(Expr) + CSS</td>
        <td rowspan="1" colspan="1">CCI</td>
       </tr>
      </tbody>
     </table>
</p>

<note><p>In this table, "else error" means "Otherwise, an error
is raised: <xerrorref spec="FO" class="CH" code="0002" type="dynamic"/>". 
The phrase "if it exists" is used, because
the case-sensitive collation CCS does not always have a
case-insensitive variant (and, even if one exists, it may not be
possible to determine it algorithmically), and because the
case-insensitive collation CCI does not always have a case-sensitive
variant (and, even if one exists, it may not be possible to determine
it algorithmically).</p></note>

<eg role="xpath" xml:space="preserve">/book[@number="1"]/title ftcontains "Usability" lowercase </eg>

<p>returns false, because the <code>title</code> element doesn't contain
"usability" in lower-case characters.  </p>

<eg role="xpath" xml:space="preserve">/book[@number="1"]/title ftcontains "usability" 
case insensitive
</eg>

<p>returns true, because the character case is not
considered. </p>


</div3>

<div3 id="ftdiacriticsoption">
	<head>FTDiacriticsOption</head>

<scrap headstyle="show"><head/>
			<prod num="156" id="doc-xquery-FTDiacriticsOption"><lhs>FTDiacriticsOption</lhs><rhs>("with"  "diacritics")<br/>|  ("without"  "diacritics")<br/>|  ("diacritics"  "sensitive")<br/>|  ("diacritics"  "insensitive")</rhs></prod>
</scrap>

<p><loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftdiacriticsoption" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTDiacriticsOption</loc> modifies
token and phrase matching by specifying how diacritics are considered.</p>

<p>There are four possible diacritics options:</p>

<olist>
<item><p>The option "with" "diacritics" matches tokens and phrases with
diacritics, regardless of whether the diacritics are written in the
query.</p></item>

<item><p>The option "without" "diacritics" matches tokens and phrases
without diacritics, regardless of whether the diacritics are written
in the query.</p></item>

<item><p>The option "diacritics" "insensitive" matches tokens and
phrases with and without diacritics. Whether diacritics are written in
the query or not is not considered.</p></item>

<item><p>The option "diacritics" "sensitive" matches tokens and phrases only
if they contain the diacritics as they are written in the query.</p></item>

</olist>

<p>The default is "diacritics insensitive". </p>

<p>The following table summarizes the interactions between the
diacritics match options and the use of the default collations.</p>

<p>
    <table border="1">
      <caption>Diacritics Matrix</caption>
      <thead>
       <tr>
        <td rowspan="1" colspan="1">Default collation options/Diacritics options</td>
        <td rowspan="1" colspan="1">UCC (Unicode Codepoint Collation)</td>
        <td rowspan="1" colspan="1">CDS (some generic diacritics-sensitive collation)</td>
        <td rowspan="1" colspan="1">CDI (some generic diacritics-insensitive collation) </td>
       </tr>
      </thead>
      <tbody>
       <tr>
        <td rowspan="1" colspan="1">insensitive</td>
        <td rowspan="1" colspan="1">compare as if with and without</td>
        <td rowspan="1" colspan="1">diacritics-insensitive variant of CDS
                                  if it exists, else error</td>
        <td rowspan="1" colspan="1">CDI</td>
       </tr>
       <tr>
        <td rowspan="1" colspan="1">sensitive</td>
        <td rowspan="1" colspan="1">UCC</td>
        <td rowspan="1" colspan="1">CDS</td>
        <td rowspan="1" colspan="1">diacritics-sensitive variant of CDI if it exists, else error</td>
       </tr>
       <tr>
        <td rowspan="1" colspan="1">with diacritics</td>
        <td rowspan="1" colspan="1">"resume diacritic
              insensitive" not in
              "resume"</td>
        <td rowspan="1" colspan="1">"resume diacritic insensitive" not in
                                  "resume"</td>
        <td rowspan="1" colspan="1">CDI</td>
       </tr>
       <tr>
        <td rowspan="1" colspan="1">without diacritics</td>
        <td rowspan="1" colspan="1">"resume" not in
              "resume diacritic
              sensitive" </td>
        <td rowspan="1" colspan="1">"resume" not in "resume diacritic
                                  sensitive"</td>
        <td rowspan="1" colspan="1">CDI</td>
       </tr>
      </tbody>
     </table>
</p>

<note><p>In this table, "else error" means "Otherwise, an error
is raised: <xerrorref spec="FO" class="CH" code="0002" type="dynamic"/>". 
The phrase "if it exists" is used, because
the diacritics-sensitive collation CDS does not always have a
diacritics-insensitive variant (and, even if one exists, it may not be
possible to determine it algorithmically), and because the
diacritics-insensitive collation CDI does not always have a
diacritics-sensitive variant (and, even if one exists, it may not be
possible to determine it algorithmically).</p></note>

<eg role="xpath" xml:space="preserve">/book[@number="1"]//editor ftcontains "Vera" with diacritics </eg>

<p>returns true, because the <code>editor</code> element 
contains the token "Vera" with an acute accent.</p>

<eg role="xpath" xml:space="preserve">/book[@number="1"]/editors ftcontains "Véra" without diacritics </eg>


<p>returns false, because the <code>editor</code> element does not
contain the token "Vera" without an acute accent.</p>


</div3>
<!--<div3 id="ftspecialcharoption">
	<head>FTSpecialCharOption</head>

<scrap><head></head>
			<prodrecap ref="FTSpecialcharOption"/>
</scrap>

<p><loc href="#ftspecialcharoption">FTSpecialCharOption</loc>
specifies whether special characters such as punctuation should or
should not be ignored. </p>

<p>Influences the way <loc href="#ftwords">FTWords</loc> is
applied. </p>

<p>The option "with special characters" specifies that special
characters such as punctuation must also be matched. The option
"without special characters" specifies that special characters such as
punctuation need not be matched.
</p>

<p>The default is "without special characters". </p>


<eg role="xpath">/book[@number="1"]//editor ftcontains "Tudor Medina" with 
special characters </eg> 

<p>returns true.</p>

<eg role="xpath">/book[@number="1"]/editors ftcontains "Tudor-Medina" without
special characters </eg> 

<p>returns false.</p>


</div3>
-->

<div3 id="ftstemoption">
	<head>FTStemOption</head>

<scrap headstyle="show"><head/>
			<prod num="157" id="doc-xquery-FTStemOption"><lhs>FTStemOption</lhs><rhs>("with"  "stemming")  |  ("without"  "stemming")</rhs></prod>
</scrap>

<p><loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftstemoption" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTStemOption</loc> modifies token and
phrase matching by specifying whether stemming is applied or not. </p>

<p><loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftstemoption" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTStemOption</loc> influences the way
<loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftwords" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTWords</loc> is applied. It produces a disjunction
of the query tokens by expanding the tokens into the list of tokens that
share the same stem. By definition, the query tokens are included in
that disjunction. </p>

<p>The "with stemming" option specifies that matches may contain tokens
that have the same stem as the tokens and phrases written in the
query. It is implementation-defined what a stem of a token is. </p>

<p>The "without stemming" option specifies that the tokens and
phrases are not stemmed. </p>

<p>It is implementation-defined whether the stemming is based on an
algorithm, dictionary, or mixed approach. </p>

<p>The default is "without stemming". </p>


<eg role="xpath" xml:space="preserve">/book[@number="1"]/title ftcontains "improve" with stemming </eg>

<p>returns true, because the <code>title</code> of the specified
<code>book</code> contains "improving" which has the same stem as
"improve".  </p>


</div3>
<div3 id="ftthesaurusoption">
	<head>FTThesaurusOption</head>

<scrap headstyle="show"><head/>
	<prod num="158" id="doc-xquery-FTThesaurusOption"><lhs>FTThesaurusOption</lhs><rhs>("with"  "thesaurus"  (<nt def="doc-xquery-FTThesaurusID">FTThesaurusID</nt>  |  "default"))<br/>|  ("with"  "thesaurus"  "("  (<nt def="doc-xquery-FTThesaurusID">FTThesaurusID</nt>  |  "default")  (","  <nt def="doc-xquery-FTThesaurusID">FTThesaurusID</nt>)*  ")")<br/>|  ("without"  "thesaurus")</rhs></prod>
	<prod num="159" id="doc-xquery-FTThesaurusID"><lhs>FTThesaurusID</lhs><rhs>"at"  <nt def="prod-xquery-StringLiteral">StringLiteral</nt>  ("relationship"  <nt def="prod-xquery-StringLiteral">StringLiteral</nt>)?  (<nt def="doc-xquery-FTRange">FTRange</nt>  "levels")?</rhs></prod>
</scrap>

<p><loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftthesaurusoption" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTThesaurusOption</loc> modifies
token and phrase matching by specifying whether a thesaurus is used or
not. If thesauri are used, it locates the thesauri by default or URI
reference. It also states the relationship to be applied and how many
levels within the thesaurus to be traversed.</p>

<p><loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftthesaurusoption" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTThesaurusOption</loc> influences
the way <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftwords" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTWords</loc> is applied.</p>

<p>The <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftthesaurusoption" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">StringLiteral</loc> following
the keyword <code>at</code> in <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftthesaurusoption" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTThesaurusID</loc> is of the form of a URI
Reference.</p>

<p>Thesauri add related tokens and phrases to the search.  Thus, the
user may narrow, broaden, or otherwise modify the search using
synonyms, hypernyms (more generic terms), etc. The search is performed
as though the user has specified all related search tokens and phrases
in a disjunction (FTOr). </p>


<note><p>A thesaurus may be standards-based or locally-defined. It may be a
traditional thesaurus, or a taxonomy, soundex, ontology, or topic
map. How the thesaurus is represented is implementation-dependent.</p>
</note> 

<p>FTThesaurusID specifies the relationship sought between tokens and
phrases written in the query and terms in the thesaurus and the number
of levels to be queried in hierarchical relationships by including an
FTRange "levels". If no levels are specified, the default is to query
all levels in hierarchical relationships.</p>

<p>Relationships include, but are not limited to, the relationships
and their abbreviations presented in <bibref ref="iso-2788"/> and
their equivalents in other languages:</p>
<olist>
<item><p> <emph>equivalence relationships (synoymns):</emph> PREFERRED TERM (USE), 
NONPREFERRED USED FOR TERM (UF);</p></item>
<item><p> <emph>hierarchical relationships:</emph> BROADER TERM (BT), 
NARROWER TERM (NT),  BROADER TERM GENERIC (BTG), NARROWER TERM GENERIC (NTG), 
BROADER TERM PARTITIVE (BTP), NARROWER TERM PARTITIVE (NTP), 
TOP Terms (TT); and</p></item> 
<item><p> <emph>associative relationships:</emph> RELATED TERM (RT).</p></item>
</olist>

<p>The "with thesaurus" option specifies that string matches include
tokens that can be found in one of the specified thesauri. </p>

<p>The "without thesaurus" option specifies that no thesaurus will be
used. </p>

<p>The "with default thesaurus" option specifies that a system-defined
default thesaurus with a system-defined relationship is used. The
default thesaurus may be used in combination with other explicitly
specified thesauri.</p>

<p>The default is "without thesaurus". </p>

<eg role="xpath" xml:space="preserve">count(.//book/content ftcontains "duties" with
thesaurus at "http://bstore1.example.com/UsabilityThesaurus.xml"
relationship "synonyms")&gt;0</eg>

<p>returns true, because it finds a <code>content</code> element
containing "tasks" which the thesaurus identified as a synonym for
"duties".</p>

<eg role="xpath" xml:space="preserve">doc("http://bstore1.example.com/full-text.xml")
/books/book[count(./content ftcontains "web site components" with
thesaurus at "http://bstore1.example.com/UsabilityThesaurus.xml"
relationship "narrower terms" at most 2 levels)&gt;0]</eg>

<p>returns <code>book</code> elements, because it finds a
<code>content</code> element containing "web site components", and
narrower terms "navigation" and "layout".</p>

<eg role="xpath" xml:space="preserve">doc("http://bstore1.example.com/full-text.xml")
/books/book[count(. ftcontains "Merrygould" with thesaurus at
"http://bstore1.example.com/UsabilitySoundex.xml" relationship
"sounds like")&gt;0]</eg>

<p>returns a <code>book</code> element containing "Marigold which
sounds which sound like "Merrygould".</p>


<!--
<eg role="xpath">/book[@number="1"]//p ftcontains "buttress" with
thesaurus "Synonyms"</eg>

<p>returns the true if "Synonyms" is a thesaurus for synonyms in the
English language.</p>
-->


</div3>
<div3 id="ftstopwordoption">
	<head>FTStopwordOption</head>

<scrap headstyle="show"><head/>
	<prod num="160" id="doc-xquery-FTStopwordOption"><lhs>FTStopwordOption</lhs><rhs>("with"  "stop"  "words"  <nt def="doc-xquery-FTRefOrList">FTRefOrList</nt>  <nt def="doc-xquery-FTInclExclStringLiteral">FTInclExclStringLiteral</nt>*)<br/>|  ("without"  "stop"  "words")<br/>|  ("with"  "default"  "stop"  "words"  <nt def="doc-xquery-FTInclExclStringLiteral">FTInclExclStringLiteral</nt>*)</rhs></prod>
	<prod num="161" id="doc-xquery-FTRefOrList"><lhs>FTRefOrList</lhs><rhs>("at"  <nt def="prod-xquery-StringLiteral">StringLiteral</nt>)<br/>|  ("("  <nt def="prod-xquery-StringLiteral">StringLiteral</nt>  (","  <nt def="prod-xquery-StringLiteral">StringLiteral</nt>)*  ")")</rhs></prod>
	<prod num="162" id="doc-xquery-FTInclExclStringLiteral"><lhs>FTInclExclStringLiteral</lhs><rhs>("union"  |  "except")  <nt def="doc-xquery-FTRefOrList">FTRefOrList</nt></rhs></prod>
</scrap>

<p><loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftstopwordoption" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTStopWordOption</loc> controls word
matching by specifying whether stop words are used or not. It can be
used to define a set of tokens that will be replaced with a search
on any token if used as search tokens. </p>

<p><loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftstopwordoption" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTStopWordOption</loc> influences the way <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftwords" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTWords</loc> is
applied. </p>

<p><loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftstopwordoption" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTRefOrList</loc> specifies the list
of stop words either explicitly as a comma-separated list of string
literals, or by a URI following the keyword <code>at</code>. If a URI
is used, it must point to a sequence of string atoms or nodes of type
"xs:string". In both cases, no tokenization is performed on the
strings: they are used as they occur in the sequence. </p>

<p>The "with stop words" option specifies that if a token is within the
specified collection of stop words, it is removed from the search and
any token may be substituted for it. Stop words retain their position
numbers and are counted in <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftdistance" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTDistance</loc>
and <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftwindow" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTWindow</loc> searches.</p>

<p>Multiple stop word lists may be combined using "union" or "except".
If "union" is specified, every string occurring in the lists  
specified by the left-hand side or the right-hand side is a stop 
word. If "except" is specified, only strings occurring in the list  
specified by the left-hand side but not in the list specified
by the right-hand side are stop words. </p>

<p>The "with default stop words" option specifies that an
implementation-defined collection of stop words is used. </p>

<p>The "without stop words" option specifies that no stop words are
used. This is equivalent to specifying an empty list of stop
words.</p>

<p>The default is "without stop words". </p>


<eg role="xpath" xml:space="preserve">/book[@number="1"]//p ftcontains "propagation of errors"
with stemming with stop words ("a", "the", "of") </eg>

<p>returns true, because the document contains the phrase "propagating
few errors". </p>

<p>Note the asymmetry in the stop word semantics: the property of
being a stop word is only relevant to query terms, not to document
terms. Hence, it is irrelevant for the above-mentioned match whether
"few" is a stop word or not, and on the other hand we do not want the
query above to match "propagation" followed by 2 stop words, or even a
sequence of 3 stop words in the document.</p>

<eg role="xpath" xml:space="preserve">/book[@number="1"]//p ftcontains "propagation of errors" 
with stemming without stop words</eg> 

<p>returns false, because "of" is not in the <code>p</code> element
between "propagating" and "errors". </p>

<eg role="xpath" xml:space="preserve">
doc("http://bstore1.example.com/full-text.xml")
/books/book[count(.//content ftcontains "planning then 
conducting" with stop words at 
"http://bstore1.example.com/StopWordList.xml")&gt;0]
</eg>

<p>uses the stop words list specified at the URL. Assuming that the
specified stop word list contains the "then", this query is
reduced to a query on the phrase "planning X conducting", allowing any
token as a substitute for X.  It returns a <code>book</code> element,
because its <code>content</code> element contains "planning then
conducting". It would have also returned the <code>book</code> if the
phrases "planning and conducting" and "planning before conducting"
had been in its <code>content</code>.</p>


<eg role="xpath" xml:space="preserve">
doc("http://bstore1.example.com/full-text.xml")
/books/book[count(.//content ftcontains "planning then conducting"
with stop words at "http://bstore1.example.com/StopWordList.xml"
except ("the then"))&gt;0]
</eg>

<p>returns <code>book</code>s containing "planning then conducting",
but not does not return <code>book</code>s containing "planning and
conducting", since it is exempting "then" from being a stop word. </p>


</div3>

<div3 id="ftlanguageoption">
	<head>FTLanguageOption</head>

<scrap headstyle="show"><head/>
	<prod num="163" id="doc-xquery-FTLanguageOption"><lhs>FTLanguageOption</lhs><rhs>"language"  <nt def="prod-xquery-StringLiteral">StringLiteral</nt></rhs></prod>
</scrap>

<p><loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftlanguageoption" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTLanguageOption</loc> modifies token
matching by specifying the language of search tokens and phrases. </p>

<p><loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftlanguageoption" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTLanguageOption</loc> influences the way <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftwords" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTWords</loc> is applied.  </p>

<p>The StringLiteral following the keyword <code>language</code>
designates one language. It must either be castable to "xs:language",
or be the value "none". Otherwise, an error is raised: <xerrorref spec="XP" class="TY" code="0004" type="type"/>. </p>

<p>The "language" option influences tokenization, stemming, and stop
words.</p>

<p>If the <code>language "none"</code> option is specified, no
language selected.</p>

<p> The set of valid language identifiers is
implementation-defined.</p>

<p>By default, there is no language selected. </p>


<eg role="xpath" xml:space="preserve">/book[@number="1"]//editor ftcontains "salon de the"
with default stop words language "fr"</eg> <p>This is an example where
the language option is used to select the appropriate stop word list. </p>


</div3>



<div3 id="ftwildcardoption">
	<head>FTWildCardOption</head>

<scrap headstyle="show"><head/>
	<prod num="164" id="doc-xquery-FTWildCardOption"><lhs>FTWildCardOption</lhs><rhs>("with"  "wildcards")  |  ("without"  "wildcards")</rhs></prod>
</scrap>

<p><loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftwildcardoption" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTWildCardOption</loc> modifies token and phrase matching by specifying whether wildcards are used or not.</p>
 
<p><loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftwildcardoption" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTWildCardOption</loc> influences the
way FTWords is applied.</p>

<p>In addition to specifying the "with wildcards"' option, indicators
(represented by periods (.)) and qualifiers are appended to or
inserted into tokens being searched. Zero or more characters replace
each indicator and qualifier.</p>

 
<p>Indicators are mandatory. When the "with wildcards"' option is
present, one or more periods (.) must be appended at the beginning or
end of tokens or inserted into tokens. If the period is at the beginning
of a token, the wildcard is a prefix wildcard. If the period is at the
end of a token, it is a suffix wildcard. If the period is inserted into
a token, it is an infix wildcard.</p>
 

<p>When the "with wildcards" option and one or more periods (.)
appended to or inserted into tokens are present, characters are
appended or inserted at each of the periods. Any characters may be
appended or inserted except newline characters (#xA), return
characters (#xD), and tab characters (#x9). The number of characters
depends on the qualifier.  Qualifiers available are none, question
mark, asterisk, plus sign, and two numbers separated by a comma, both
enclosed by curly braces.</p>
 
<olist>

<item> 
<p>If a period is present, but no qualifiers, one character is
appended or inserted. </p>
</item> 
 
<item> 
<p>If a period is followed by a question mark (.?), zero or one
characters are appended or inserted. </p>
</item> 

 
<item> 
<p>If a period is followed by an asterisk (.*), zero or more
characters are appended or inserted.</p>
</item> 

 
<item> 
<p>If a period is followed by a plus sign (.+), one or more characters
are appended or inserted. </p>
</item> 
 
 
<item> 
<p>If a period is followed by two numbers separated by a comma, both
enclosed by curly braces (.{n,m}), a specified range of characters is
appended or inserted. </p>
</item> 

</olist>

 
<p>The "without wildcards" option finds tokens without recognizing
wildcard indicators and qualifiers. Periods, question marks,
asterisks, plus signs, and two numbers separated by a comma, both
enclosed by curly braces recognized as regular characters.</p>
 

<p>The default is "without wildcards".</p>

 
<eg role="xpath" xml:space="preserve">/book[@number="1"]/title ftcontains "improv.*" with
wildcards</eg> <p>returns true, because the <code>title</code> element
contains "improving".</p>

 
<eg role="xpath" xml:space="preserve">/book[@number="1"]/title ftcontains ".?site" with
wildcards</eg> <p>returns true, because the <code>title</code> element
contains "site".</p>

 
<eg role="xpath" xml:space="preserve">/book[@number="1"]/p ftcontains "w.ll" with
wildcards</eg> <p>returns true, because the <code>p</code> element
contains "well".</p>



</div3>

</div2>
<div2 id="ftignoreoption">
        <head>FTIgnoreOption</head>

<scrap headstyle="show"><head/>
                        <prod num="174" id="doc-xquery-FTIgnoreOption"><lhs>FTIgnoreOption</lhs><rhs>"without"  "content"  <nt def="prod-xquery-UnionExpr">UnionExpr</nt></rhs></prod>
                </scrap>

<p><loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftignoreoption" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTIgnoreOption</loc> specifies a set of
element nodes whose content are ignored. <termdef id="IgnoredNodesDef" term="IgnoredNodes"><term>Ignored nodes</term> are the set of element nodes whose content are 
    ignored.</termdef> Ignored nodes are identified
by the XQuery expression UnionExpr. Let <code>N1, N2, ..., Nk</code>
be the sequence of nodes of the search context. The expression
UnionExpr is evaluated in the context of each node <code>Ni</code> being
searched. That is, the search context expression of the <code>ftcontains</code>
predicate creates a new focus for the evaluation of the UnionExpr
given with <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftignoreoption" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTIgnoreOption</loc>, similar
to the creation of the dynamic context of a path expression
<code>E1/E2</code> or a filter expression <code>E1[E2]</code> 
(see <xspecref spec="XQ" ref="eval_context"/>).</p>

<p>Now, let <code>I1, I2, ..., In</code> be the sequence of items that
UnionExpr evaluates to. For each <code>Ni (i=1..k)</code> a copy is
made that omits each node <code>Ij (j=1..n)</code> that is not
<code>Ni</code>. Those copies form the new search context. If
UnionExpr evaluates to an empty sequence no nodes are omitted.</p>

<p>In the following fragment, if <code>.//annotation</code> is ignored,
"Web Usability" will be found 2 times: once in the <code>title</code>
element and once in the <code>editor</code> element. The 2 occurrences
in the 2 <code>annotation</code> elements are ignored. On the other
hand, "expert" will not be found, as it appears only in an
<code>annotation</code> element.</p> 


 <eg xml:space="preserve">&lt;book&gt;
   &lt;title&gt;Web Usability and Practice&lt;/title&gt;
   &lt;author&gt;Montana &lt;annotation&gt; this author is an expert in Web Usability&lt;/annotation&gt; 
           Marigold
   &lt;/author&gt;
   &lt;editor&gt;Véra Tudor-Medina on Web &lt;annotation&gt; best editor on Web Usability&lt;/annotation&gt;
           Usability
   &lt;/editor&gt;
 &lt;/book&gt;</eg>

<p>By default, no element content is ignored. </p>

</div2>

</div1>


<div1 id="tq-semantics">
    <head>Semantics</head>
    
        <p>This section describes the formal semantics of XQuery 1.0 and XPath 2.0 Full-Text.
        The figure below shows how XQuery 1.0 and XPath 2.0 Full-Text integrates with XQuery 1.0
        and XPath 2.0.</p>
		
		<p>The following diagram represents the interaction of XQuery 1.0 and
		XPath 2.0 Full-Text with the rest of XQuery 1.0 and XPath 2.0 languages.
		It specifies how full-text expression can be nested within XQuery 1.0
		and XPath 2.0 expressions and vice versa. </p>
    
        <graphic xmlns:xlink="http://www.w3.org/1999/xlink" source="images/Composability.png" alt="Composability diagram" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
    
		<ulist>
       	<item><p>Arrow 1 represents the composability of the XQuery 1.0
        and XPath 2.0 expressions. This is outside the scope of this
        document and will not be discussed further.  </p></item>
		
		<item><p>Arrow 2 shows how XQuery 1.0 and XPath 2.0 expressions
can be nested inside FTSelections by evaluating them to a sequence of
items. If the XQuery 1.0 and XPath 2.0 expression is nested on the left-hand side of a
<term>FTContains</term> expression or within <term>FTWords</term>, the items in the sequence are converted to their tokenized form. The process is
described in <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#TokenizationSec" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">Tokenization</loc>. If the XQuery 1.0 and XPath expression is nested within another type of <term>FTSelection</term>, the items in its results sequence are
                converted to atomic values as discussed in 
                <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftselections" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTSelections</loc>.</p></item>
		
		<item><p>Arrow 3 represents the composability of <term>FTSelection</term>s. 
        The composability is achieved by evaluating the <term>FTSelection</term>s to
        <term>AllMatches</term>. Each <term>FTSelection</term> operates on zero or more
        <term>AllMatches</term> and returns <term>AllMatches</term>. The process is
        described in the <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#FTSelectionEvalSec" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">Evaluation 
        of FTSelections</loc> section. </p>	</item>
		
		<item><p>
		Arrow 4 shows how the result of the evaluation of XQuery 1.0 and XPath 2.0 Full-Text and scoring
        expressions are integrated into the XQuery 1.0 and XPath 2.0
        model. The section <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#FullTextExprSec" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">XQuery 1.0 and XPath 2.0 Full-Text and scoring
        expressions</loc> describes how this is achieved.</p></item>
		</ulist>
		
		<p>The functions and schemas defined in this section are
		considered to be within the fts: namespace. These functions and schemas
		are used only for describing the semantics. There is no requirement that 
		these functions and schemas be implemented, so there is  no URI is 
		associated with the fts: prefix. </p>

    <!-- **************************************************************
         *                            Tokenization                       *
         ************************************************************** -->
    <div2 role="xquery" id="TokenizationSec">
        <head>Tokenization</head>
        
        <p><termdef id="TokenizationDef" term="Tokenization">Formally, <term>tokenization</term> is the process of converting
        the string value of a node to a sequence of token occurrences, taking the
        structural information of the node into account
        to identify token, sentence, and paragraph boundaries.</termdef></p>

        

        <p>Tokenization is subject to the following constraint:</p>
        <olist>
           <item>
              <p>Attribute values are not tokenized.</p>
           </item>
        </olist>

        <div3 role="xquery" id="tq-ft-Tokenization-examples">
           <head>Examples</head>

		<p>The following document fragment is the source document for examples in this 
		section. Tokenization is implementation-defined. A sample tokenization 
		is used for the examples in this section. The results might be different 
		for other tokenizations.</p>

		<p>Unless stated otherwise, the results assume a case-insensitive match.</p>
	        
        <eg role="parse-text" xml:space="preserve">
&lt;offers&gt;
    &lt;offer id="1000" price="10000"&gt;
        Ford Mustang 2000, 65K, excellent condition, runs 
        great, AC, CC, power all
    &lt;/offer&gt;
    &lt;offer id="1001" price="8000"&gt;
        Honda Accord 1999, 78K, A/C, cruise control, runs 
        and looks great, excellent condition
    &lt;/offer&gt;
    &lt;offer id="1005" price="5500"&gt;
        Ford Mustang, 1995, 150K highway mileage, no rust, 
        excellent condition
    &lt;/offer&gt;
&lt;/offers&gt;
        </eg>
        
        <p>In this sample tokenization, tokens are delimited by punctuation and 
		whitespace symbols. </p>

		<ulist>
		
		<item><p>The token "Ford" is at 
		relative position 1.</p></item>

		<item><p>The token "Mustang" is at
                relative position 2.</p></item>

		<item><p>The token "2000" is at
		relative position 3.</p></item>

		<item><p>Relative position numbers are assigned sequentially through the 
		end of the document.</p></item> 

		</ulist>

		<p>Hence each token occupies exactly one position, and no overlapping of 
                tokens occurs. The relative positions of token
                occurrences are shown
                below in parentheses.</p>
        
        <eg role="parse-text" id="SampleTokenizedDoc" xml:space="preserve">
&lt;offers&gt;
    &lt;offer id="1000" price="10000"&gt;
        Ford(1) Mustang(2) 2000(3), 65K(4), excellent(5)
        condition(6), runs(7) great(8), AC(9), CC(10), 
        power(11) all(12)
    &lt;/offer&gt;
    &lt;offer id="1001" price="8000"&gt;
        Honda(13) Accord(14) 1999(15), 78K(16), A(17)/C(18),
        cruise(19) control(20), runs(21) and(22) looks(23)
        great(24), excellent(25) condition(26)
    &lt;/offer&gt;
    &lt;offer id="1005" price="5500"&gt;
        Ford(27) Mustang(28), 1995(29), 150K(30) highway(31)
        mileage(32), little(33)  rust(34), excellent(35) 
        condition(36)
    &lt;/offer&gt;
&lt;/offers&gt;
        </eg>
        
        <p>The relative positions of paragraphs are determined similarly. In
		this sample tokenization, the paragraph delimiters are start tags, end 
		tags, and end of line characters.</p>
		
		<ulist>
		
		<item><p>The tokens in the first element are assigned relative 
		paragraph number 1.</p></item>
		
		<item><p>The tokens from the next element are assigned relative  
		paragraph number 2.</p></item>
		
		<item><p>Relative paragraph numbers are assigned sequentially through 
		the end of the document.</p></item>
		
		</ulist>
        
        <p>The relative positions of sentences are determined similarly using 
        sentence delimiters.</p>


           <p>Implementations may provide for the means to ignore or side-step
           certain structural elements when performing tokenization.  In the
           following example, the implementation has decided to ignore the
           markup for <code>&lt;bold&gt;</code> and prune out the entire
           subtree headed by <code>&lt;deleted&gt;</code>.</p> 
        <eg role="parse-text" xml:space="preserve">
&lt;para&gt;&lt;deleted&gt;This sentence was deleted.&lt;/deleted&gt;
This &lt;bold&gt;entire paragraph&lt;/bold&gt; is one sentence
as far as the tokenizer is concerned.
&lt;/para&gt;
</eg>
        <p>Using the same notation as before, this sample tokenization is
        shown below. All the token occurrences marked with a
        token position also have the same sentence and paragraph relative
        positions. Note that there are no tokens marked for the 
        ignored subtree.
        </p>
        <eg role="parse-text" xml:space="preserve">
&lt;para&gt;&lt;deleted&gt;This sentence was deleted.&lt;/deleted&gt;
This(1) &lt;bold&gt;entire(2) paragraph(3)&lt;/bold&gt; is(4) one(5) sentence(6)
as(7) far(8) as(9) the(10) tokenizer(11) is(12) concerned(13).
&lt;/para&gt;
</eg>
        </div3>
        <div3 role="xquery" id="TokenizationRepresentationsSec">
           <head>Representations of Tokenized Text and Matching</head>

        <p>
        Two representations of tokenized text will be employed in the
        formal semantics functions, one for the search strings of a
        query and one for matched token occurrences of search
        context items.
        </p>

        <p>A <termdef id="SearchItemDef" term="SearchItem"><term>SearchItem</term> is a sequence of
        <term>SearchTokenInfo</term>s representing the sequence of tokens derived
        from tokenizing one search string. </termdef></p>

        <p>A <termdef id="SearchTokenInfoDef" term="SearchTokenInfo"><term>SearchTokenInfo</term> is the
        identity of a token inside a search string. </termdef>
        Each <term>SearchTokenInfo</term> is
        associated with a unique identifier that captures the relative
        position of the search string in the query in document order.</p>
        

        <p>A <termdef id="TokenInfoDef" term="TokenInfo"><term>TokenInfo</term> represents
        a sequence of consecutive token occurrences inside an XML document. </termdef>
        Each <term>TokenInfo</term> is
        associated with:</p>
        
        <ulist>
            <item>
                <p>a unique identifier that captures the relative position of 
                the first token occurrence of the sequence in the document order: <code>startPos</code></p>
            </item>
            <item>
                <p>a unique identifier that captures the relative position of 
                the last token occurrence of the sequence in the document order: <code>endPos</code></p>
            </item>
            <item>
                <p>the relative position of the sentence containing
                the first token occurrence or zero if the tokenizer does not report
                sentences: <code>startSent</code></p>
            </item>
            <item>
                <p>the relative position of the sentence containing
                the last token occurrence or zero if the tokenizer does not report
                sentences: <code>endSent</code></p>
            </item>
            <item>
                <p>the relative position of the paragraph containing
                the first token occurrence or zero if the tokenizer does not report
                paragraphs: <code>startPara</code></p>
            </item>
            <item>
                <p>the relative position of the paragraph containing
                the last token occurrence or zero if the tokenizer does not report
                paragraphs: <code>endPara</code></p>
            </item>
        </ulist>
        
        <p>The following matching function is the central
        implementation-defined primitive performing the full-text
        retrieval.</p>

<!-- file: fts.xqy -->        
        <eg role="parse-text" xml:space="preserve">
declare function fts:matchTokenInfos (
      $searchContext as item(),
      $matchOptions as element(fts:matchOptions),
      $stopWords as xs:string*,
      $searchTokens as element(fts:searchToken)* )
   as element(fts:tokenInfo)*  external;
            </eg>

        <p>The above function returns the <term>TokenInfo</term>s in items in
        <code>$searchContext</code> that match the search string represented by
        the sequence <code>$searchTokens</code>, when using the match
        options in <code>$matchOptions</code> and stop words in
        <code>$stopWords</code>. If <code>$searchTokens</code> is a
        sequence of more than one search token, each returned
        <term>TokenInfo</term> must represent a phrase matching that sequence. 
        </p>

      <note><p>While this matching function assumes a tokenized
representation of the search strings, it does not assume a tokenized
representation of the input items in <code>$searchContext</code>,
i.e. the texts in which the search happens. Hence, the tokenization of
the search context is implicit in this function and coupled to the
retrieval of matches. Of course, this does not imply that tokenization
of the search context cannot be done a priori. Because tokenization is
implementation-defined, the 
tokenization of each item in <code>$searchContext</code> does not
necessarily take into account the match options in
<code>$matchOptions</code> or the search tokens in
<code>$searchTokens</code>.  This allows implementations to tokenize
and index input data without the knowledge of particular match options
used in full-text queries.</p></note> 
         </div3>
    </div2>

    
    <!-- ***********************************************
         ***               AllMatches                ***
         *********************************************** -->
    <div2 role="xquery" id="FTSelectionEvalSec">
        <head>Evaluation of FTSelections</head>
        
        <p>The sequence of nodes in the XQuery 1.0 and XPath 2.0 Data Model is
        inadequate to support fully composable <term>FTSelection</term>s. 
        Full-text operations, such as <term>FTSelection</term>s, operate on linguistic
        units, such as positions of tokens, and which are not captured
        in the XQuery 1.0 and XPath 2.0 Data Model (XDM). </p>
		
		<p>XQuery 1.0 and XPath 2.0 Full-Text adds relative token, sentence, and 
		paragraph position numbers via <term>AllMatches</term>. <term>AllMatches</term> make 
		<term>FTSelection</term>s fully composable.</p>
        
        <!-- **********************************************************************
         *                            AllMatches                              *
         ********************************************************************** -->
        <div3 role="xquery" id="AllMatchesSec">
            <head>AllMatches</head>

            <div4 role="xquery" id="tq-ft-formalmodel">
                <head>Formal Model</head>
                
                <p><termdef id="AllMatchesDef" term="AllMatches">An <term>AllMatches</term>
                describes the possible results of an <term>FTSelection</term>.</termdef>
                The UML Static Class diagram of <term>AllMatches</term> is shown
                on the diagram given below.</p>
            
                <graphic xmlns:xlink="http://www.w3.org/1999/xlink" source="images/AllMatchesClassDiagram.png" alt="AllMatches class diagram" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
                
                <p>The <term>AllMatches</term> object contains zero or more <term>Match</term>es. </p>
                
				<p><termdef id="MatchDef" term="Match">Each  
                <term>Match</term> describes one result to the <term>FTSelection</term>.</termdef> 
				The result is described in terms of zero or more <term>StringInclude</term>s and zero
                or more <term>StringExclude</term>s.</p>
				
                <p><termdef id="StringMatchDef" term="StringMatch">A
				<term>StringMatch</term> is a
				possible match of a sequence of search
				tokens with a corresponding sequence
				of consecutive token occurrences
				in a document. A StringMatch may be a <term>StringInclude</term>
				or <term>StringExclude</term>.</termdef> The <term>queryPos</term> 
				attribute specifies the position of the search token in the 
				query. This attribute is needed for <term>FTOrder</term>s. The matched
				document token sequence is described in the <term>TokenInfo</term> associated with
				the <term>StringMatch</term>.</p>
				
				
				<p><termdef id="StringIncludeDef" term="StringInclude">A <term>StringInclude</term>
				is a <term>StringMatch</term> that describes a <term>TokenInfo</term> that must be
				contained in the document.</termdef></p>
				
				
				<p><termdef id="StringExcludeDef" term="StringExclude">A <term>StringExclude</term>
				is a <term>StringMatch</term> that describes a <term>TokenInfo</term> that must not be
				contained in the document.</termdef></p>
                
                <p>Intuitively, <term>AllMatches</term> specifies the <term>TokenInfo</term>s that a
                node contains and does not contain to satisfy an <term>FTSelection</term>.</p>
                
                <p>The <term>AllMatches</term> structure resembles the Disjunctive Normal
                Form (DNF) in propositional and first-order logic. The
                <term>AllMatches</term> is a disjunction of <term>Match</term>es. Each <term>Match</term> is a
                conjunction of <term>StringInclude</term>s, and <term>StringExclude</term>s. </p>
                
            </div4>

            <div4 role="xquery" id="tq-ft-AllMatches-examples">
                <head>Examples</head>

                <p>Since in most of the examples below the tokens span only a single 
                position, we characterize the <term>TokenInfo</term> instance by simply giving this position, 
                written as "Pos:X". This should be read as the value for both, the 
                <code>startPos</code> and the <code>endPos</code>
                attribute. Furthermore, for expository reasons, we
                include in each <term>StringMatch</term> example an attribute
                "query string", set to the original
                query string, in order to facilitate the association
                from which query string that match came from.</p>
                <p>The simplest example of an <term>FTSelection</term> is an <term>FTWords</term> such 
				as  <code>"Mustang"</code>. The
                <term>AllMatches</term> corresponding to this <term>FTWords</term> is given below. </p>
                
                <graphic xmlns:xlink="http://www.w3.org/1999/xlink" source="images/SampleAllMatches1.jpg" alt="Sample AllMatches" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
                
                <p>As shown, the <term>AllMatches</term> consists of two <term>Match</term>es. Each
                <term>Match</term> represents one possible result of the <term>FTWords</term>
                <code>"Mustang"</code>. The result represented by the first
                <term>Match</term>, represented as a <term>StringInclude</term>, contains the token
                "Mustang" at position 2. The result described by the second <term>Match</term>
                contains the token "Mustang" at position 28. </p>
                
                <p>A more complex example of an <term>FTSelection</term> is an <term>FTWords</term> 
				such as <code>"Ford Mustang"</code>. The <term>AllMatches</term> for this 
				<term>FTWords</term> is given below.</p>
                
                <graphic xmlns:xlink="http://www.w3.org/1999/xlink" source="images/SampleAllMatches2.jpg" alt="Sample AllMatches" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
                
                <p>There are two possible results for this <term>FTWords</term>, and
                these are represented by the two <term>Match</term>es. Each of the
                <term>Match</term>es requires two tokens to be matched. The first <term>Match</term> is 
				obtained by matching "Ford" at position 1 and matching "Mustang" at position 2.
                Similarly, the second <term>Match</term> is obtained by
                matching "Ford" at position 27 and "Mustang" at position 28.</p>
                
                <p>An even more complex example of an <term>FTSelection</term> is an 
				<term>FTSelection</term> such as <code>"Mustang"
                &amp;&amp; ! "rust"</code> that searches for 
                "Mustang" but not "rust". The <term>AllMatches</term> for this
                <term>FTSelection</term> is given below.</p>
                
                <graphic xmlns:xlink="http://www.w3.org/1999/xlink" source="images/SampleAllMatches3.jpg" alt="Sample AllMatches" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>

                <p>This example introduces <term>StringExclude</term>. <term>StringExclude</term> 
				corresponds to negation in DNF. It specifies that the 
                result described by the corresponding <term>Match</term> must not match the token at 
                the specified position. In this example, the first <term>Match</term> specifies 
                that "Mustang" is matched at position 2, and that the token "rust" 
                at position 34 is not matched.</p>
                
            </div4>
            
        
        <!-- **********************************************************************
             *                            XML Representation                      *
             ********************************************************************** -->
             <div4 id="tq-ft-XML-representation">
                <head>XML representation</head>
            
                <p> <term>AllMatches</term> has a well-defined hierarchical
                structure. Therefore, the <term>AllMatches</term> can be easily
                modeled in XML. 
                This XML representation and those which follow formally describe the
                semantics of <term>FTSelection</term>s. For example, 
                the XML representation of <term>AllMatches</term> formally
                specifies how an <term>FTSelection</term> operates on zero or more
                <term>AllMatches</term> to produce a resulting <term>AllMatches</term>. </p>
                
                <p>The XML schema for representing <term>AllMatches</term> is
                given below.</p>

<!-- file: AllMatches.xsd -->
                <eg role="parse-text" xml:space="preserve">
&lt;xs:schema 
     xmlns:xs="http://www.w3.org/2001/XMLSchema" 
     xmlns:fts="http://www.w3.org/2006/xquery-full-text"
     targetNamespace="http://www.w3.org/2006/xquery-full-text"
     elementFormDefault="qualified" 
     attributeFormDefault="unqualified"&gt;

  &lt;xs:complexType name="AllMatches"&gt;
    &lt;xs:sequence&gt;
      &lt;xs:element ref="fts:match" 
                  minOccurs="0" 
                  maxOccurs="unbounded"/&gt;
    &lt;/xs:sequence&gt;
    &lt;xs:attribute name="stokenNum" type="xs:integer" use="required" /&gt;
  &lt;/xs:complexType&gt;

  &lt;xs:element name="allMatches" type="fts:AllMatches"/&gt;

  &lt;xs:complexType name="Match"&gt;
    &lt;xs:sequence&gt;
      &lt;xs:element ref="fts:stringInclude" 
                  minOccurs="0" 
                  maxOccurs="unbounded"/&gt;
      &lt;xs:element ref="fts:stringExclude" 
                  minOccurs="0" 
                  maxOccurs="unbounded"/&gt;
   &lt;/xs:sequence&gt;
  &lt;/xs:complexType&gt;
  
  &lt;xs:element name="stringInclude" 
              type="fts:StringMatch" /&gt;

  &lt;xs:element name="stringExclude" 
              type="fts:StringMatch" /&gt;

  &lt;xs:element name="match" type="fts:Match"/&gt;

  &lt;xs:complexType name="StringMatch"&gt;
    &lt;xs:sequence&gt;
      &lt;xs:element ref="fts:tokenInfo"/&gt;
    &lt;/xs:sequence&gt;
    &lt;xs:attribute name="queryPos" 
                  type="xs:integer" 
                  use="required"/&gt;
  &lt;/xs:complexType&gt;

  &lt;xs:complexType name="TokenInfo"&gt;
    &lt;xs:attribute name="startPos" 
                  type="xs:integer" 
                  use="required"/&gt;
    &lt;xs:attribute name="endPos" 
                  type="xs:integer" 
                  use="required"/&gt;
    &lt;xs:attribute name="startSent" 
                  type="xs:integer" 
                  use="required"/&gt;
    &lt;xs:attribute name="endSent" 
                  type="xs:integer" 
                  use="required"/&gt;
    &lt;xs:attribute name="startPara" 
                  type="xs:integer" 
                  use="required"/&gt;
    &lt;xs:attribute name="endPara" 
                  type="xs:integer" 
                  use="required"/&gt;
  &lt;/xs:complexType&gt;

  &lt;xs:element name="tokenInfo" type="fts:TokenInfo"/&gt;

  &lt;xs:complexType name="SearchItem"&gt;
    &lt;xs:sequence&gt;
      &lt;xs:element ref="fts:searchToken" 
                  minOccurs="0" 
                  maxOccurs="unbounded"/&gt;
   &lt;/xs:sequence&gt;
  &lt;/xs:complexType&gt;

  &lt;xs:complexType name="SearchTokenInfo"&gt;
    &lt;xs:attribute name="word" 
                  type="xs:string" 
                  use="required"/&gt;
    &lt;xs:attribute name="queryPos" 
                  type="xs:integer" 
                  use="required"/&gt;
  &lt;/xs:complexType&gt;

  &lt;xs:element name="searchToken" type="fts:SearchTokenInfo"/&gt;
&lt;/xs:schema&gt;
                </eg>
		
	<p>The <code>stokenNum</code> attribute in 
	<term>AllMatches</term> is related to the representation of the semantics as XQuery functions. 
	Therefore, it is not considered part of the <term>AllMatches</term> model.
	The <code>stokenNum</code> attribute stores
	the number of search tokens used when evaluating the <term>AllMatches</term>. This 
	value is used to compute the correct value for the <code>queryPos</code>
	attribute in new <term>StringMatch</term>es. </p> 
		
            </div4>
  
        </div3>

        
        
    <!-- *************************************************************
         ***                       FTSelections                    ***
         ************************************************************* -->
    <div3 role="xquery" id="FTSelectionsSec">
        <head>FTSelections</head>
        
        <p><term>FTSelection</term>s are fully composable and may be nested arbitrarily under
        other <term>FTSelection</term>s. Each <term>FTSelection</term> may be associated with
        match options (such as stemming and stop words) and score weights.
        Since score weights are solely interpreted by the formal semantics
        scoring function, they do not influence the semantics of
        <term>FTSelection</term>s. Therefore, score weights are not considered in
        the formal semantics.</p>

        <div4 role="xquery" id="FTSelectionsXMLSec">
            <head>XML Representation</head>
            
            <p>The XML representation of the
            <term>FTSelection</term>s used in the 
            <function>fts:evaluate</function> function 
	    closely follows the grammar of the language. It can be viewed as
	    an XML representation of an abstract syntax tree (AST) of a
	    parsed full-text query. Every <term>FTSelection</term>
	    is represented as an XML element. Every nested <term>FTSelection</term> is
	    represented as a nested descendant element. 
	    For binary <term>FTSelection</term>s, e.g., <term>FTAnd</term>, the nested <term>FTSelection</term>s
	    are represented in <code>&lt;left&gt;</code> and <code>&lt;right&gt;
	    </code> descendant elements. For unary <term>FTSelection</term>s, a 
	    <code>&lt;selection&gt;</code> descendant element is used. Additional
	    characteristics of <term>FTSelection</term>s, e.g., the distance unit for
	    <term>FTDistance</term>, are stored in attributes. </p>

<!-- file: FTSelection.xsd -->            
            <eg role="parse-text" xml:space="preserve">
&lt;xs:schema
     xmlns:xs="http://www.w3.org/2001/XMLSchema" 
     xmlns:fts="http://www.w3.org/2006/xquery-full-text"
     targetNamespace="http://www.w3.org/2006/xquery-full-text"
     elementFormDefault="qualified" 
     attributeFormDefault="unqualified"&gt;
           
  &lt;xs:include schemaLocation="AllMatches.xsd" /&gt;
  &lt;xs:include schemaLocation="MatchOptions.xsd" /&gt;

  &lt;xs:complexType name="FTSelection"&gt;
    &lt;xs:sequence&gt;
      &lt;xs:choice&gt;
        &lt;xs:element name="FTWords" type="fts:FTWords"/&gt;
        &lt;xs:element name="FTAnd" type="fts:FTAnd"/&gt;
        &lt;xs:element name="FTOr" type="fts:FTOr"/&gt;
        &lt;xs:element name="FTUnaryNot" type="fts:FTUnaryNot"/&gt;
        &lt;xs:element name="FTMildNot" type="fts:FTMildNot"/&gt;
        &lt;xs:element name="FTOrder" type="fts:FTOrder"/&gt;
        &lt;xs:element name="FTScope" type="fts:FTScope"/&gt;
        &lt;xs:element name="FTContent" type="fts:FTContent"/&gt;
        &lt;xs:element name="FTDistance" type="fts:FTDistance"/&gt;
        &lt;xs:element name="FTWindow" type="fts:FTWindow"/&gt;
        &lt;xs:element name="FTTimes" type="fts:FTTimes"/&gt;
      &lt;/xs:choice&gt;
      &lt;xs:element ref="fts:matchOptions" 
                  minOccurs="0"/&gt;
      &lt;xs:element name="weight" 
                  type="xs:double" 
                  minOccurs="0"/&gt;
    &lt;/xs:sequence&gt;
  &lt;/xs:complexType&gt;

  &lt;xs:element name="selection" type="fts:FTSelection"/&gt;

  &lt;xs:complexType name="FTWords"&gt;
    &lt;xs:sequence&gt;
      &lt;xs:element ref="searchItem" 
                  minOccurs="0" 
                  maxOccurs="unbounded"/&gt;
    &lt;/xs:sequence&gt;
    &lt;xs:attribute name="type" 
                  type="fts:FTWordsType" 
                  use="required"/&gt;
  &lt;/xs:complexType&gt;

  &lt;xs:element name="searchItem" type="fts:SearchItem"/&gt;
  
  &lt;xs:complexType name="FTAnd"&gt;
    &lt;xs:sequence&gt;
      &lt;xs:element name="left" type="fts:FTSelection"/&gt;
      &lt;xs:element name="right" type="fts:FTSelection"/&gt;
    &lt;/xs:sequence&gt;
  &lt;/xs:complexType&gt;
  
  &lt;xs:complexType name="FTOr"&gt;
    &lt;xs:sequence&gt;
      &lt;xs:element name="left" type="fts:FTSelection"/&gt;
      &lt;xs:element name="right" type="fts:FTSelection"/&gt;
    &lt;/xs:sequence&gt;
  &lt;/xs:complexType&gt;
  
  &lt;xs:complexType name="FTUnaryNot"&gt;
    &lt;xs:sequence&gt;
      &lt;xs:element name="selection" type="fts:FTSelection"/&gt;
    &lt;/xs:sequence&gt;
  &lt;/xs:complexType&gt;
  
  &lt;xs:complexType name="FTMildNot"&gt;
    &lt;xs:sequence&gt;
      &lt;xs:element name="selection" type="fts:FTSelection"/&gt;
    &lt;/xs:sequence&gt;
  &lt;/xs:complexType&gt;
  
  &lt;xs:complexType name="FTOrder"&gt;
    &lt;xs:sequence&gt;
      &lt;xs:element name="selection" type="fts:FTSelection"/&gt;
    &lt;/xs:sequence&gt;
  &lt;/xs:complexType&gt;
  
  &lt;xs:complexType name="FTScope"&gt;
    &lt;xs:sequence&gt;
      &lt;xs:element name="selection" type="fts:FTSelection"/&gt;
    &lt;/xs:sequence&gt;
    &lt;xs:attribute name="type" 
                  type="fts:ScopeType" 
                  use="required"/&gt;
    &lt;xs:attribute name="scope" 
                  type="fts:ScopeSelector" 
                  use="required"/&gt;
  &lt;/xs:complexType&gt;
  
  &lt;xs:complexType name="FTContent"&gt;
    &lt;xs:sequence&gt;
      &lt;xs:element name="selection" type="fts:FTSelection"/&gt;
    &lt;/xs:sequence&gt;
    &lt;xs:attribute name="type" 
                  type="fts:ContentMatchType" 
                  use="required"/&gt;
  &lt;/xs:complexType&gt;
  
  &lt;xs:complexType name="FTDistance"&gt;
    &lt;xs:sequence&gt;
      &lt;xs:element name="range" type="fts:FTRangeSpec"/&gt;
      &lt;xs:element name="selection" type="fts:FTSelection"/&gt;
    &lt;/xs:sequence&gt;
    &lt;xs:attribute name="type" 
                  type="fts:DistanceType" 
                  use="required"/&gt;
  &lt;/xs:complexType&gt;
  
  &lt;xs:complexType name="FTWindow"&gt;
    &lt;xs:sequence&gt;
      &lt;xs:element name="selection" type="fts:FTSelection"/&gt;
    &lt;/xs:sequence&gt;
    &lt;xs:attribute name="size" 
                  type="xs:integer" 
                  use="required"/&gt;
    &lt;xs:attribute name="type" 
                  type="fts:DistanceType" 
                  use="required"/&gt;
  &lt;/xs:complexType&gt;
  
  &lt;xs:complexType name="FTTimes"&gt;
    &lt;xs:sequence&gt;
      &lt;xs:element name="range" type="fts:FTRangeSpec"/&gt;
      &lt;xs:element name="selection" type="fts:FTWords"/&gt;
    &lt;/xs:sequence&gt;
  &lt;/xs:complexType&gt;
    
  &lt;xs:simpleType name="FTWordsType"&gt;
    &lt;xs:restriction base="xs:string"&gt;
      &lt;xs:enumeration value="any"/&gt;
      &lt;xs:enumeration value="all"/&gt;
      &lt;xs:enumeration value="phrase"/&gt;
      &lt;xs:enumeration value="any word"/&gt;
      &lt;xs:enumeration value="all word"/&gt;
    &lt;/xs:restriction&gt;
  &lt;/xs:simpleType&gt;
  
  &lt;xs:simpleType name="ScopeType"&gt;
    &lt;xs:restriction base="xs:string"&gt;
      &lt;xs:enumeration value="same"/&gt;
      &lt;xs:enumeration value="different"/&gt;
    &lt;/xs:restriction&gt;
  &lt;/xs:simpleType&gt;
  
  &lt;xs:simpleType name="ScopeSelector"&gt;
    &lt;xs:restriction base="xs:string"&gt;
      &lt;xs:enumeration value="paragraph"/&gt;
      &lt;xs:enumeration value="sentence"/&gt;
    &lt;/xs:restriction&gt;
  &lt;/xs:simpleType&gt;
  
  &lt;xs:simpleType name="DistanceType"&gt;
    &lt;xs:restriction base="xs:string"&gt;
      &lt;xs:enumeration value="paragraph"/&gt;
      &lt;xs:enumeration value="sentence"/&gt;
      &lt;xs:enumeration value="word"/&gt;
    &lt;/xs:restriction&gt;
  &lt;/xs:simpleType&gt;
  
  &lt;xs:simpleType name="ContentMatchType"&gt;
    &lt;xs:restriction base="xs:string"&gt;
      &lt;xs:enumeration value="at start"/&gt;
      &lt;xs:enumeration value="at end"/&gt;
      &lt;xs:enumeration value="entire content"/&gt;
    &lt;/xs:restriction&gt;
  &lt;/xs:simpleType&gt;
&lt;/xs:schema&gt;
            </eg>
        
        </div4>


        
        <!-- **********************************************************************
             *                       The evaluate function                        *
             ********************************************************************** -->
        <div4 role="xquery" id="tq-ft-evaluate-function">
            <head>The <function>evaluate</function> function</head>
            
            <p>The denotational semantics for the evaluation of
            <term>FTSelection</term>s is defined using the <function>fts:evaluate</function> 
			function. The function takes three
            parameters: (1) an <term>FTSelection</term>, 2) a search
            context node, and 3) the default set of match options
            that apply to the evaluation of the <term>FTSelection</term>.</p>
			<p>The <function>fts:evaluate</function> function returns the
            <term>AllMatches</term> that is the result of evaluating the
            <term>FTSelection</term>. When <function>fts:evaluate</function> is applied to some
            <term>FTSelection</term> X, it calls the function
            <function>fts:ApplyX</function> to build the resulting <term>AllMatches</term>.
            If X is applied on nested <term>FTSelection</term>s, the 
            <function>fts:evaluate</function> function is recursively called on these nested
            <term>FTSelection</term>s and the returned <term>AllMatches</term> are used in the evaluation of
            <function>fts:ApplyX</function>.
            </p>
            
            <p>The semantics for the <function>fts:evaluate</function> function 
            is given below.</p>
<!-- file: fts.xqy -->            
            <eg role="parse-text" xml:space="preserve">
declare function fts:evaluate (
      $ftSelect as element(*, fts:FTSelection), 
      $searchContext as item(),
      $matchOptions as element(fts:matchOptions),
      $searchTokenNum as xs:integer )
   as element(fts:allMatches)
{
   if (fn:count($ftSelect/fts:matchOptions) &gt; 0) then 
      (: First we deal with all match options that the    :)
      (: FTSelection might bear: we add the match options :)
      (: in front of the current match options sequence   :)
      (: and pass the new sequence to the recursive call  :)
      let $newFTSelection := 
         &lt;fts:selection&gt;{$ftSelect/*[fn:not(self::fts:matchOptions)]}&lt;/fts:selection&gt;
      return fts:evaluate($newFTSelection, 
                          $searchContext, 
                          element fts:matchOptions {
                             $ftSelect/fts:matchOptions/*, 
                             $matchOptions/*
                          },
                          $searchTokenNum)
   else if (fn:count($ftSelect/fts:weight) &gt; 0) then
      (: Weight has no bearing on semantics -- just :)
      (: call "evaluate" on nested FTSelection     :)
      let $newFTSelection := $ftSelect/*[fn:not(self::fts:weight)]
      return fts:evaluate($newFTSelection, 
                          $searchContext, 
                          $matchOptions,
                          $searchTokenNum)
   else
      typeswitch ($ftSelect/*[1]) 
         case $nftSelection as element(fts:FTWords) return
            (: Apply the FTWords in the search context :)
            fts:ApplyFTWords($searchContext,
                             $matchOptions,
                             $nftSelection/@type,
                             $nftSelection/fts:searchItem,
                             $searchTokenNum + 1)
         case $nftSelection as element(fts:FTAnd) return
            let $left := fts:evaluate($nftSelection/fts:left,
                                     $searchContext,
                                     $matchOptions,
                                     $searchTokenNum)
            let $newSearchTokenNum := $left/@stokenNum
            let $right := fts:evaluate($nftSelection/fts:right,
                                      $searchContext,
                                      $matchOptions,
                                      $newSearchTokenNum)
            return fts:ApplyFTAnd($left, $right)
         case $nftSelection as element(fts:FTOr) return
            let $left := fts:evaluate($nftSelection/fts:left,
                                     $searchContext,
                                     $matchOptions,
                                     $searchTokenNum)
            let $newSearchTokenNum := $left/@stokenNum
            let $right := fts:evaluate($nftSelection/fts:right,
                                      $searchContext,
                                      $matchOptions,
                                      $newSearchTokenNum)
            return fts:ApplyFTOr($left, $right)
         case $nftSelection as element(fts:FTUnaryNot) return
            let $nested := fts:evaluate($nftSelection/fts:selection,
                                        $searchContext,
                                        $matchOptions,
                                        $searchTokenNum)
            return fts:ApplyFTUnaryNot($nested)
         case $nftSelection as element(fts:FTMildNot) return
            let $left := fts:evaluate($nftSelection/fts:left,
                                     $searchContext,
                                     $matchOptions,
                                     $searchTokenNum)
            let $newSearchTokenNum := $left/@stokenNum
            let $right := fts:evaluate($nftSelection/fts:right,
                                      $searchContext,
                                      $matchOptions,
                                      $newSearchTokenNum)
            return fts:ApplyFTMildNot($left, $right)
         case $nftSelection as element(fts:FTOrder) return
            let $nested := fts:evaluate($nftSelection/fts:selection,
                                        $searchContext,
                                        $matchOptions,
                                        $searchTokenNum)
            return fts:ApplyFTOrder($nested)
         case $nftSelection as element(fts:FTScope) return
            let $nested := fts:evaluate($nftSelection/fts:selection,
                                        $searchContext,
                                        $matchOptions,
                                        $searchTokenNum)
            return fts:ApplyFTScope($nftSelection/@type, 
                                    $nftSelection/@scope,
                                    $nested)
         case $nftSelection as element(fts:FTContent) return
            let $nested := fts:evaluate($nftSelection/fts:selection,
                                        $searchContext,
                                        $matchOptions,
                                        $searchTokenNum)
            return fts:ApplyFTContent($searchContext,
                                      $matchOptions,
                                      $nftSelection/@type, 
                                      $nested)
         case $nftSelection as element(fts:FTDistance) return
            let $nested := fts:evaluate($nftSelection/fts:selection,
                                        $searchContext,
                                        $matchOptions,
                                        $searchTokenNum)
            return fts:ApplyFTDistance($matchOptions,
                                       $nftSelection/@type,
                                       $nftSelection/fts:range,
                                       $nested)
         case $nftSelection as element(fts:FTWindow) return
            let $nested := fts:evaluate($nftSelection/fts:selection,
                                        $searchContext,
                                        $matchOptions,
                                        $searchTokenNum)
            return fts:ApplyFTWindow($matchOptions,
                                     $nftSelection/@type,
                                     $nftSelection/@size,
                                     $nested)
         case $nftSelection as element(fts:FTTimes) return
            let $nested := fts:evaluate($nftSelection/fts:selection,
                                        $searchContext,
                                        $matchOptions,
                                        $searchTokenNum)
            return fts:ApplyFTTimes($nftSelection/fts:range,
                                    $nested)
         default return ()
};
            </eg>
            
            <p>For
            concreteness, assume that the <term>FTSelection</term> was
            invoked inside an <code>ftcontains</code> expression such
            as <code>searchContext ftcontains ftselection</code>. In order to 
	    determine the
            <term>AllMatches</term> result of <code>ftselection</code>, the
            <function>fts:evaluate</function> function is invoked as
            follows: <code>fts:evaluate($ftselection,
            $searchContext, $matchOptions, 0)</code>, where
            <code>$ftselection</code> is the XML representation of the
            <code>ftselection</code> and
            <code>$searchContext</code> is bound to the result of
            the evaluation of the XQuery expression
            <code>searchContext</code>. </p>
            
            <p>Initially, the
            <code>$searchTokensNum</code> is 0, i.e., no
            search tokens have been processed.</p>
            
            <p>The variable <code>$matchOptions</code> is bound to the 
            list of match options as defined in the static context (see
            Appendix <specref ref="id-xqft-static-context-components"/>).
			Match options embedded in
            <code>ftselection</code> modify the match options collection as
            evaluation proceeds. </p>
			<p>Match options are applied to an <term>FTSelection</term>, 
            organized in a stack. </p>
			
			<ulist>
			
			<item><p>The top match option in the stack is 
            applied first. </p></item>
			<item><p>The second match option is applied next. </p></item> 
			<item><p>Match 
			options are applied sequentially down to the bottom of the stack. 
			</p></item>
			
			</ulist>
			
			<p>Ordering among match options is necessary because match
            options are not always commutative. For example,
            synonym(stem(word)) is not always the same as stem(synonym(word)).
            Naturally, match options may be reordered when they commute, but
            this is an optimization issue and is beyond the scope of this
            document.</p>
			
            <p>Given the invocation of: <code>fts:evaluate($ftselection,
            $searchContext, $matchOptions)</code>, evaluation proceeds as
            follows. First, <code>$ftselection</code> is checked to see whether
            a match option is applied 1) on a nested <term>FTSelection</term>, 2) on a
            weight specification, 3) on an <term>FTWords</term>, or 4) on some other
            <term>FTSelection</term> (case 4). </p>
            
			<olist>
			
			<item>
            <p>If <code>$ftselection</code> contains a match option,
            then it modifies the context for the nested <term>FTSelection</term>.
            Consequently, a new match option element is created and pushed onto
            the top of the stack of match options. The
            <function>createOptionElement</function> function used to create a
            stack element corresponding to the match option creates a
            data structure that stores the type of match option, such as
            stemming, thesaurus,  and the details
            relating to the match option, such as the name of the thesaurus, the
            stop words for which other tokens may be substituted. The context 
			match option created is added to
            the top of the stack because, in the <term>FTSelection</term>, it was applied
            before the other match options in the current match options stack.
            The <function>evaluate</function> function is then invoked on the
            nested <term>FTSelection</term> with the new match options stack. When the
            function returns, the match option is popped from the stack, and the
            result of the nested <function>evaluate</function> function is
            returned. The match option is popped because the match options
            do not apply to <term>FTSelection</term>s outside its scope. </p></item>
            
            <item><p>If <code>$ftselection</code> contains a weight
            specification, then the specification is ignored because it
            does not alter the semantics. The <function>evaluate</function>
            function is recursively called on the nested <term>FTSelection</term> and the
            resulting <term>AllMatches</term> is returned. </p></item>
            
            <item><p>If <code>$ftselection</code> is an <term>FTWords</term>, then 
			it does
            not have any nested <term>FTSelection</term>s. Consequently, this is the base
            of the recursive call, and the <term>AllMatches</term> result of the <term>FTWords</term>
            is computed and returned. The <term>AllMatches</term> is computed by invoking
            the <function>ApplyFTWords</function> function with the current
            search context and other necessary information. </p></item>
            
            <item><p>If <code>$ftselection</code> contains neither a match
            option nor a weight specification and is not an <term>FTWords</term>, the
            <term>FTSelection</term> performs a full-text operation, such as
            <code>&amp;&amp;</code>, <code>||</code>, <code>window</code>.
            These operations are fully-compositional and may be
            invoked on nested <term>FTSelection</term>s. Consequently, evaluation proceeds
            as follows. </p>
				<ulist>
				<item><p>First, the <function>evaluate</function> function is
            recursively invoked on each nested <term>FTSelection</term>.
				The result of
            evaluating each nested <term>FTSelection</term> is an <term>AllMatches</term>. </p></item>
			<item><p>The <term>AllMatches</term> are transformed into the resulting 
			<term>AllMatches</term> by applying the full-text operation corresponding to 
			<code>FTSelection1</code> which is
            generically named <function>applyX</function> for some type of
            <term>FTSelection</term> X in the code.  </p></item>
				</ulist>
				<p>For example, let
            <code>FTSelection1</code> be <code>FTSelection2 &amp;&amp;
            FTSelection3 </code>. Here <code>FTSelection2</code> and
            <code>FTSelection3</code> may themselves be arbitrarily nested
            <term>FTSelection</term>s. Thus, <function> evaluate</function> is invoked on
            <code>FTSelection2</code> and <code> FTSelection3</code>, and the
            resulting <term>AllMatches</term> are transformed to the final <term>AllMatches</term>
            using the <function> ApplyFTAnd</function> function corresponding to
            <code>&amp;&amp; </code>.</p>
			</item>
            </olist>
            
            <p>The semantics of the <function>ApplyX</function> function for
            each <term>FTSelection</term> kind X is given below.</p>
        </div4>
        
        
        
        <!-- **********************************************************************
             *                     Formal semantics functions                     *
             ********************************************************************** -->
        <div4 role="xquery" id="tq-ft-formal-semantics-functions">
            <head>Formal semantics functions</head>
            
            <p>The formal semantics of the <function>applyX</function>
            functions for each <term>FTSelection</term> kind X is specified by
            six functions. How these six functions are computed is
            implementation-dependent, but the functions must satisfy some
            well-defined properties. </p>
            
            <p>The <function>getTokenInfo</function> function is
            described in <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#TokenizationSec" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">Section 4.1
			Tokenization</loc>.</p>
            
            <p>The <function>wordDistance</function> function returns the
            number of tokens that occur between the positions of the
            <term>TokenInfo</term>s <code>$tokenInfo1</code> and
            <code>$tokenInfo2</code>. For example, two consecutive
            tokens have a distance of 0 tokens. </p>

<!-- file: fts.xqy -->            
            <eg role="parse-text" xml:space="preserve">
declare function fts:wordDistance (
             $tokenInfo1 as element(fts:tokenInfo),
             $tokenInfo2 as element(fts:tokenInfo),
             $matchOptions as element(fts:matchOptions) ) 
   as xs:integer external;
            </eg>
            
            <p>The <function>getParaDistance</function> function returns the number of
            paragraphs between the <term>TokenInfo</term>s
            <code>$tokenInfo1</code> and <code>$tokenInfo2</code>.</p>
            
<!-- file: fts.xqy -->            
            <eg role="parse-text" xml:space="preserve">
declare function fts:paraDistance (
             $tokenInfo1 as element(fts:tokenInfo),
             $tokenInfo2 as element(fts:tokenInfo),
             $matchOptions as element(fts:matchOptions) ) 
   as xs:integer external;
            </eg>
            
            <p>The <function>sentenceDistance</function> function 
            returns the number of sentences between the
            <term>TokenInfo</term>s <code>$tokenInfo1</code> and
            <code>$tokenInfo2</code>. </p>
            
<!-- file: fts.xqy -->            
            <eg role="parse-text" xml:space="preserve">
declare function fts:sentenceDistance (
             $tokenInfo1 as element(fts:tokenInfo),
             $tokenInfo2 as element(fts:tokenInfo),
             $matchOptions as element(fts:matchOptions) ) 
   as xs:integer external;
            </eg>

            <p>The <function>isStartToken</function> function
            returns true if the <term>TokenInfo</term> <code>$tokenInfo</code> 
            describes a token whose start position is the first position of
            the node <code>$searchContext</code>. </p>

<!-- file: fts.xqy -->            
            <eg role="parse-text" xml:space="preserve">
declare function fts:isStartToken (
             $searchContext as item(),
             $tokenInfo as element(fts:tokenInfo) ) 
   as xs:boolean external;
            </eg>

            <p>The <function>isEndToken</function> function
            returns true if the <term>TokenInfo</term> <code>$tokenInfo</code> 
            describes a token whose end position is the last position of
            the node <code>$searchContext</code>. </p>

<!-- file: fts.xqy -->            
            <eg role="parse-text" xml:space="preserve">
declare function fts:isEndToken (
             $searchContext as item(),
             $tokenInfo as element(fts:tokenInfo) ) 
   as xs:boolean external;
            </eg>
            
        </div4>
        
        
        <!-- **********************************************************************
             *                            FTWords                       *
             ********************************************************************** -->
        <div4 role="xquery" id="tq-ft-fs-FTWords">
            <head>FTWords</head>
            
            <p>An <term>FTWords</term> that consists of a single
            search string consisting of a sequence of token to be
            matched as a phrase is evaluated by 
            the <function>applySearchTokensAsPhrase</function> function. Its parameters 
            are 1) the search context, 2) the list of match options, 3) the search
            string to be matched as a sequence of <code>fts:searchToken</code>
            items, and 4) the position where the latter search string occurs in the
            query. 
            </p>
            
<!-- file: fts-simple.xqy -->            
            <eg role="parse-text" xml:space="preserve">
(: simplified version not dealing with special match options :)
declare function fts:applySearchTokensAsPhrase (
      $searchContext as item(),
      $matchOptions as element(fts:matchOptions),
      $searchTokens as element(fts:searchToken)*,
      $queryPos as xs:integer )
   as element(fts:allMatches)
{
   &lt;fts:allMatches stokenNum="{$queryPos}"&gt; 
   {
      for $tokenInfo in
         fts:matchTokenInfos( 
            $searchContext,
            $matchOptions,
            (),
            $searchTokens )
      return  
         &lt;fts:match&gt;  
            &lt;fts:stringInclude queryPos="{$queryPos}"&gt; 
            {$tokenInfo}
            &lt;/fts:stringInclude&gt; 
         &lt;/fts:match&gt;
   } 
   &lt;/fts:allMatches&gt;
};
</eg>

            
            <p>If after the application of all the match options, the sequence 
			of search tokens returned for an <term>FTWords</term> is empty, an empty
            <term>AllMatches</term> is returned. </p>

            <p>The <term>AllMatches</term> corresponding to an
            <term>FTWords</term> is a set of <term>Match</term>es. Each of the <term>Match</term>es
            is associated with a start and an end position indicating where the corresponding
            search tokens were found. For example, the <term>AllMatches</term>
            result for the <term>FTWords</term> "Mustang" is given
            below. To simplify the presentation in the figures we write
            <code>Pos: N</code>, if the attributes
            <code>startPos</code> and <code>endPos</code> are the same
            with <code>N</code> being that position.</p>
            
            <graphic xmlns:xlink="http://www.w3.org/1999/xlink" source="images/FTWordEx.jpg" alt="FTWords example" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
        
			<p>There are five variations of <term>FTWords</term> depending on how the 
			tokens and phrases in the nested XQuery 1.0 and XPath 2.0 
			expression are matched. </p>
			
			<ulist>
			<item><p>When <code>any word</code> is specified, at 
			least one token in the tokenization of the nested expression must be 
			matched. </p></item>
			<item><p>When <code>all word</code> is specified, all 
			tokens in the tokenization of the nested expression must be 
			matched.</p></item>
			<item><p>When <code>phrase</code> is specified, all 
			tokens in the tokenization of the nested expression must be 
			matched as a phrase.</p></item>
			<item><p>When <code>any</code> is specified, at least one 
			string atomic value in the nested expression must be 
			matched as a phrase.</p></item>
			<item><p>When <code>all</code> is specified, all 
			string atomic values in the nested expression must be 
			matched as a phrase.</p></item>
			</ulist>
           
            <p>The semantics for <term>FTWords</term> when <code>any word</code> is specified 
			is given below. Since <term>FTWords</term>
            does not have nested <term>FTSelection</term>s, the
            <function>ApplyFTWords</function> function does not take 
            <term>AllMatches</term> parameters corresponding to nested
            <term>FTSelection</term> results.</p>

<!-- file: fts.xqy -->            
            <eg role="parse-text" xml:space="preserve">
declare function fts:MakeDisjunction (
      $curRes as element(fts:allMatches),
      $rest as element(fts:allMatches)* ) 
   as element(fts:allMatches) 
{
   if (fn:count($rest) = 0)
   then $curRes
   else 
      let $firstAllMatches := $rest[1]
      let $restAllMatches := fn:subsequence($rest, 2)
      let $newCurRes := fts:ApplyFTOr($curRes, 
                                      $firstAllMatches)
      return fts:MakeDisjunction($newCurRes, 
                                 $restAllMatches)
};

declare function fts:ApplyFTWordsAnyWord (
      $searchContext as item(), 
      $matchOptions as element(fts:matchOptions), 
      $searchItems as element(fts:searchItem)*,
      $queryPos as xs:integer ) 
   as element(fts:allMatches) 
{
   (: Tokenization of search string has already occurred. :)
   (: Get sequence of SearchTokens over all search items. :)
   let $searchTokens := $searchItems/fts:searchToken
   return
      if (fn:count($searchItems) eq 0) 
      then &lt;fts:allMatches stokenNum="0" /&gt;
      else
         let $allAllMatches := 
            for $searchToken at $pos in $searchTokens
            return fts:applySearchTokensAsPhrase($searchContext,
                                                 $matchOptions,
                                                 $searchToken,
                                                 $queryPos + $pos - 1)
         let $firstAllMatches := $allAllMatches[1]
         let $restAllMatches := fn:subsequence($allAllMatches, 2)
         return fts:MakeDisjunction($firstAllMatches, $restAllMatches)
};
</eg>

            <p>The tokenized search strings are passed to
            ApplyFTWordsAnyWord as a sequence of
            <code>fts:searchItem</code>, each containing the tokens of
            a single search string. A single flattened sequence of all
            tokens (of type <code>fts:searchToken</code>) over all
            search items is constructed. For each of these,
            the result of <term>FTWords</term> is computed using
            <function>applySearchTokensAsPhrase</function>. Finally, the
            disjunction of all resulting <term>AllMatches</term> is computed.</p>
            
            <p>The semantics for <term>FTWords</term> when <code>all word</code>
            is specified is similar to the above, however composes a
            conjunction. It is given below.</p>

<!-- file: fts.xqy -->            
            <eg role="parse-text" xml:space="preserve">
declare function fts:MakeConjunction ( 
      $curRes as element(fts:allMatches),
      $rest as element(fts:allMatches)* ) 
   as element(fts:allMatches)
{
   if (fn:count($rest) = 0)
   then $curRes
   else 
      let $firstAllMatches := $rest[1]
      let $restAllMatches := fn:subsequence($rest, 2)
      let $newCurRes := fts:ApplyFTAnd($curRes, 
                                       $firstAllMatches)
      return fts:MakeConjunction($newCurRes, 
                                 $restAllMatches)
};

declare function fts:ApplyFTWordsAllWord (
      $searchContext as item(), 
      $matchOptions as element(fts:matchOptions), 
      $searchItems as element(fts:searchItem)*,
      $queryPos as xs:integer ) 
   as element(fts:allMatches) 
{
   (: Tokenization of search strings has already occurred. :)
   (: Get sequence of SearchTokens over all search items :)
   let $searchTokens := $searchItems/fts:searchToken
   return
      if (fn:count($searchTokens) eq 0) 
      then &lt;fts:allMatches stokenNum="0" /&gt;
      else
         let $allAllMatches := 
            for $searchToken at $pos in $searchTokens
            return fts:applySearchTokensAsPhrase($searchContext,
                                                 $matchOptions,
                                                 $searchToken,
                                                 $queryPos + $pos - 1)
            let $firstAllMatches := $allAllMatches[1]
            let $restAllMatches := fn:subsequence($allAllMatches, 2)
            return fts:MakeConjunction($firstAllMatches, $restAllMatches)
};
</eg>

            <p>The semantics for <term>FTWords</term> if <code>phrase</code> is specified 
			is given below.</p>

<!-- file: fts.xqy -->            
            <eg role="parse-text" xml:space="preserve">
declare function fts:ApplyFTWordsPhrase (
      $searchContext as item(), 
      $matchOptions as element(fts:matchOptions), 
      $searchItems as element(fts:searchItem)*,
      $queryPos as xs:integer ) 
   as element(fts:allMatches) 
{
   (: Get sequence of SearchTokenInfos over all search items :)
   let $searchTokens := $searchItems/fts:searchToken
   return
      if (fn:count($searchTokens) eq 0) 
      then &lt;fts:allMatches stokenNum="0" /&gt;
      else
         fts:applySearchTokensAsPhrase($searchContext,
                                       $matchOptions,
                                       $searchTokens,
                                       $queryPos)
};
</eg>
            
            <p>The <function>ApplyFTWordsPhrase</function> function
            also flattens the sequence of search items to a sequence of
            search tokens, but then calls
            <function>applySearchTokensAsPhrase</function> on that
            entire sequence, instead of calling it on each search token
            individually. Hence, the sequence of all search tokens is
            matched as a single phrase and the computed <term>TokenInfo</term>s
            are returned.</p>

            <p>The semantics for <term>FTWords</term> when <code>any</code> is specified is 
			given below.</p>
            
<!-- file: fts.xqy -->            
            <eg role="parse-text" xml:space="preserve">
declare function fts:ApplyFTWordsAny (
      $searchContext as item(), 
      $matchOptions as element(fts:matchOptions), 
      $searchItems as element(fts:searchItem)*,
      $queryPos as xs:integer ) 
   as element(fts:allMatches) 
{
   if (fn:count($searchItems) eq 0) 
   then &lt;fts:allMatches stokenNum="0" /&gt;
   else 
      let $firstSearchItem := $searchItems[1]
      let $restSearchItem := fn:subsequence($searchItems, 2)
      let $firstAllMatches := 
         fts:ApplyFTWordsPhrase($searchContext,
                                $matchOptions,
                                $firstSearchItem,
                                $queryPos)
      let $newQueryPos := 
         if ($firstAllMatches//@queryPos) 
         then fn:max($firstAllMatches//@queryPos) + 1
         else $queryPos
      let $restAllMatches :=
         fts:ApplyFTWordsAny($searchContext,
                             $matchOptions,
                             $restSearchItem,
                             $newQueryPos)
      return fts:ApplyFTOr($firstAllMatches, $restAllMatches)
};
</eg>

            <p>The <term>FTWords</term> with <code>any</code>
            specified forms the disjunction of the <term>AllMatches</term> that
            are the result of the matching of each search item as a phrase.</p>
            
            <p>The semantics for <term>FTWords</term> when <code>all </code> is specified 
			is given below.</p>
			
<!-- file: fts.xqy -->            
            <eg role="parse-text" xml:space="preserve">
declare function fts:ApplyFTWordsAll (
      $searchContext as item(), 
      $matchOptions as element(fts:matchOptions), 
      $searchItems as element(fts:searchItem)*,
      $queryPos as xs:integer ) 
   as element(fts:allMatches) 
{
   if (fn:count($searchItems) = 0) 
   then &lt;fts:allMatches stokenNum="0" /&gt;
   else 
      let $firstSearchItem := $searchItems[1]
      let $restSearchItem := fn:subsequence($searchItems, 2)
      let $firstAllMatches := 
         fts:ApplyFTWordsPhrase($searchContext,
                                $matchOptions,
                                $firstSearchItem,
                                $queryPos)
      return
         if ($restSearchItem) then
            let $newQueryPos := 
               if ($firstAllMatches//@queryPos) 
               then fn:max($firstAllMatches//@queryPos) + 1
               else $queryPos
            let $restAllMatches :=
               fts:ApplyFTWordsAll($searchContext,
                                   $matchOptions,
                                   $restSearchItem,
                                   $newQueryPos)
            return 
               fts:ApplyFTAnd($firstAllMatches, $restAllMatches)
         else $firstAllMatches
};
</eg>

            <p>The difference between <code>all</code> and 
            <code>any</code> is the use of conjunction instead of
            disjunction.</p>
            
            <p>The <function>ApplyFTWords</function> function combines
            all of these functions.</p>
            
<!-- file: fts.xqy -->            
            <eg role="parse-text" xml:space="preserve">
declare function fts:ApplyFTWords ( 
      $searchContext as item(),
      $matchOptions as element(fts:matchOptions),
      $type as fts:FTWordsType,
      $searchItems as element(fts:searchItem)*, 
      $queryPos as xs:integer )
   as element(fts:allMatches) 
{
   if ($type eq "any word")
   then fts:ApplyFTWordsAnyWord($searchContext,
                                $matchOptions,
                                $searchItems,
                                $queryPos)
   else if ($type eq "all word")
   then fts:ApplyFTWordsAllWord($searchContext,
                                $matchOptions,
                                $searchItems,
                                $queryPos)
   else if ($type eq "phrase")
   then fts:ApplyFTWordsPhrase($searchContext,
                               $matchOptions,
                               $searchItems,
                               $queryPos)
   else if ($type eq "any")
   then fts:ApplyFTWordsAny($searchContext,
                            $matchOptions,
                            $searchItems,
                            $queryPos)
   else fts:ApplyFTWordsAll($searchContext,
                            $matchOptions,
                            $searchItems,
                            $queryPos)
};
                </eg>
        </div4>
        
        
        
        <div4 role="xquery" id="tq-ft-fs-FTOr">
            <!-- **********************************************************************
             *                            FTOr                          *
             ********************************************************************** -->
            <head>FTOr</head>
            <p>The parameters of the <function>ApplyFTOr</function> 
            function are the two <term>AllMatches</term> parameters 
            corresponding to the results of the two nested 
            <term>FTSelection</term>s. The search context and the match
            options stack are not used by this function. The semantics is given 
			below.</p>
            
<!-- file: fts.xqy -->            
            <eg role="parse-text" xml:space="preserve">
declare function fts:ApplyFTOr (
      $allMatches1 as element(fts:allMatches),
      $allMatches2 as element(fts:allMatches) ) 
   as element(fts:allMatches) 
{
   &lt;fts:allMatches stokenNum="{fn:max(($allMatches1/@stokenNum, 
                                       $allMatches2/@stokenNum))}"&gt;
   {$allMatches1/fts:match,$allMatches2/fts:match}
   &lt;/fts:allMatches&gt;
};
            </eg>
            
            <p>The <function>ApplyFTOr</function> function creates a new <term>AllMatches</term> 
			in which 
            <term>Match</term>es are the union of those found 
            in the input <term>AllMatches</term>. 
			Each <term>Match</term> represents one possible result of the corresponding 
            <term>FTSelection</term>. Thus, a <term>Match</term> from either 
            of the <term>AllMatches</term> is a result. </p>
			
            <p>For example, consider the <term>FTSelection</term>
            <code>"Mustang" || "Honda"</code>. The 
			<term>AllMatches</term> corresponding to 
            "Mustang" and "Honda" are given below.</p>
            
            <graphic xmlns:xlink="http://www.w3.org/1999/xlink" source="images/FTOrEx1.jpg" alt="FTOr input AllMatches 1" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
            <graphic xmlns:xlink="http://www.w3.org/1999/xlink" source="images/FTOrEx2.jpg" alt="FTOr input AllMatches 2" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
            
            <p>The <term>AllMatches</term> produced by <function>
            ApplyFTOr</function> is given below.</p>
            
            <graphic xmlns:xlink="http://www.w3.org/1999/xlink" source="images/FTOrEx3.jpg" alt="FTOr result AllMatches" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
        </div4>
        
        
        
        <div4 role="xquery" id="tq-ft-fs-FTAnd">
            <!-- **********************************************************************
             *                            FTAnd                         *
             ********************************************************************** -->
            <head>FTAnd</head>
            <p>The parameters of the <function>ApplyFTAnd</function> 
            function are the two <term>AllMatches</term>  
            corresponding to the results of the two nested 
            <term>FTSelection</term>s. The search context and the match 
            options are not used by this function. The semantics is given below.</p>
            
<!-- file: fts.xqy -->            
            <eg role="parse-text" xml:space="preserve">
declare function fts:ApplyFTAnd (
      $allMatches1 as element(fts:allMatches),
      $allMatches2 as element(fts:allMatches) ) 
   as element(fts:allMatches) 
{
   &lt;fts:allMatches stokenNum="{fn:max(($allMatches1/@stokenNum, 
                                       $allMatches2/@stokenNum))}" &gt;
   {
      for $sm1 in $allMatches1/fts:match
      for $sm2 in $allMatches2/fts:match
      return &lt;fts:match&gt;
             {$sm1/*, $sm2/*}
             &lt;/fts:match&gt;
   }
   &lt;/fts:allMatches&gt;
};
            </eg>
            
            <p>The result of the conjunction is a new 
            <term>AllMatches</term> that contains the "Cartesian 
            product" of the matches of the participating 
            <term>FTSelection</term>s. Every resulting <term>Match</term> 
            is formed by the combination of the <term>StringInclude</term> components 
            and <term>StringExclude</term> from the 
            <term>AllMatches</term> of the nested <term>FTSelection</term> 
            . Thus every match contains the positions 
            to satisfy a <term>Match</term> from both original 
            <term>FTSelection</term>s and excludes the positions that 
            violate the same <term>Match</term>es. </p>
            <p>For example, consider the <term>FTSelection</term>
            <code>"Mustang" &amp;&amp; "rust"</code>. The 
			source <term>AllMatches</term> are give below.</p>
            
            <graphic xmlns:xlink="http://www.w3.org/1999/xlink" source="images/FTAndEx1.jpg" alt="FTAnd input AllMatches 1" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
            <graphic xmlns:xlink="http://www.w3.org/1999/xlink" source="images/FTAndEx2.jpg" alt="FTAnd input AllMatches 2" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
            
            <p>The <term>AllMatches</term> produced by <function>ApplyFTAnd</function> is
			given below.</p>
            
            <graphic xmlns:xlink="http://www.w3.org/1999/xlink" source="images/FTAndEx3.jpg" alt="FTAnd result AllMatches" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
        </div4>
        
        
        
        <div4 role="xquery" id="tq-ft-fs-FTUnaryNot">
        <!-- **************************************************
             *                  FTUnaryNot                    *
             ************************************************** --> 
        <head>FTUnaryNot</head> 
        
        <p>The parameters of the <function>ApplyFTUnaryNot</function>
        function are 1) the search context, 2) the list of match
        options, and 3) one <term>AllMatches</term> parameter corresponding to the
        result of the nested <term>FTSelection</term> to be negated. The
        search context and the match options are not used by this function. The 
		semantics is given below.</p>
            
<!-- file: fts.xqy -->            
            <eg role="parse-text" xml:space="preserve">
declare function fts:InvertStringMatch ( $strm as element(*,fts:StringMatch) ) 
   as element(*,fts:StringMatch)
{
   if ($strm instance of element(fts:stringExclude)) then
      &lt;fts:stringInclude queryPos="{$strm/@queryPos}"&gt;
      {$strm/fts:tokenInfo}
      &lt;/fts:stringInclude&gt;
   else
      &lt;fts:stringExclude queryPos="{$strm/@queryPos}"&gt;
      {$strm/fts:tokenInfo}
      &lt;/fts:stringExclude&gt;
};

declare function fts:UnaryNotHelper ( $matches as element(fts:match)* )
   as element(fts:match)*
{
   if (fn:count($matches) = 0 
   then &lt;match/&gt;
   else
      for $sm in $matches[1]/*
      for $rest in fts:UnaryNotHelper( fn:subsequence($matches, 2) )
      return 
         &lt;fts:match&gt;
         {
            fts:InvertStringMatch($sm),
            $rest/*
         }
         &lt;/fts:match&gt;
};

declare function fts:ApplyFTUnaryNot (
      $allMatches as element(fts:allMatches) )
   as element(fts:allMatches) 
{
   &lt;fts:allMatches stokenNum="{$allMatches/@stokenNum}"&gt;
   {
      fts:UnaryNotHelper($allMatches/fts:match)
   }
   &lt;/fts:allMatches&gt;
};
            </eg>
            
            <p>The generation of the resulting
            <term>AllMatches</term> of an <term>FTUnaryNot</term> resembles the transformation
            of a negation of prepositional formula in DNF back to DNF.
            The negation of <term>AllMatches</term> requires
            the inversion of all the conditions on the nodes encoded
            by the <term>AllMatches</term>.</p>
            
            <p>In the <function>InvertStringMatch</function> function  above, 
			this inversion occurs as follows. </p>
			<olist>
			
			<item><p>The function <function>fts:invertStringMatch</function>
			inverts a <term>stringInclude </term> into a <term>stringExclude</term> and
			vice versa. </p></item>
			
			<item><p>The function <function>fts:UnaryNotHelper</function> transforms
			the source <term>Match</term>es into the resulting
			<term>Match</term>es by forming the combinations of the
			inversions of a <term>StringInclude</term> or <term>StringExclude</term>
			component over the source <term>Match</term>es into new <term>Match</term>es.</p></item>
			
            </olist>
			
            <p>For example, consider the <term>FTSelection</term>
            <code>! ("Mustang" || "Honda")</code>. The 
			source <term>AllMatches</term> is given below:</p>
            
            <graphic xmlns:xlink="http://www.w3.org/1999/xlink" source="images/FTNegationEx1.jpg" alt="FTUnaryNot input AllMatches" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
                     
            <p>The <term>FTUnaryNot</term> transforms the <term>StringInclude</term>s to 
			<term>StringExclude</term>s as illustrated below.</p>
            
            <graphic xmlns:xlink="http://www.w3.org/1999/xlink" source="images/FTNegationEx2.jpg" alt="FTUnaryNot result AllMatches" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
        </div4>
        
        
        
        <!-- **********************************************************************
             *                            FTMildNot                          *
             ********************************************************************** -->
        <div4 role="xquery" id="tq-ft-fs-FTMildNot">
            <head>FTMildNot</head>
            
            <p>The parameters of the <function>ApplyFTMildNot</function>
            function are the two <term>AllMatches</term> parameters corresponding
            to the results of the two nested <term>FTSelection</term>s. The
            search context and the match options stack are not
            used by this function. The semantics is given below.</p>
            
<!-- file: fts.xqy -->            
            <eg role="parse-text" xml:space="preserve">
declare function fts:ApplyFTMildNot (
      $allMatches1 as element(fts:allMatches),
      $allMatches2 as element(fts:allMatches) ) 
   as element(fts:allMatches)
{
   if (fn:count($allMatches2//fts:stringExclude) gt 0) then
      fn:error("Invalid expression on the right-hand side of a not-in")
   else
      &lt;fts:allMatches stokenNum="{$allMatches1/@stokenNum}"&gt;
      {
         let $posSet2 := $allMatches2/fts:match/fts:stringInclude/@queryPos
         return 
            $allMatches1/fts:match[
               every $pos1 in ./fts:stringInclude/@queryPos, 
                     $pos2 in $posSet2
               satisfies $pos1 ne $pos2]
      }
      &lt;/fts:allMatches&gt;
};
            </eg>
            
            <p>The resulting <term>AllMatches</term> contains <term>Match</term>es
            of the first operand that do not mention in their
            <term>stringInclude</term> components positions in a <term>StringInclude</term> component 
			in the <term>AllMatches</term> of the second operand.</p> 
            
            <p>For example, consider the <term>FTSelection</term>
            <code>("Ford" mildnot "Ford
            Mustang")</code>. The
            source <term>AllMatches</term> for the left-hand side argument is given below.</p>
            
            <graphic xmlns:xlink="http://www.w3.org/1999/xlink" source="images/FTMildNegationEx1.jpg" alt="FTMildnot input AllMatches 1" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
			<p>The
            source <term>AllMatches</term> for the right-hand side argument is given below.</p>
            <graphic xmlns:xlink="http://www.w3.org/1999/xlink" source="images/FTMildNegationEx2.jpg" alt="FTMildnot input AllMatches 2" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
                     
            <p>The <term>FTMildNot</term> will transform these to an empty
            <term>AllMatches</term> because both position 1 and position 27 from
            the first <term>AllMatches</term> contain only <term>TokenInfo</term>s from
            <term>stringInclude</term> components of the second
            <term>AllMatches</term>.</p>
            
        </div4>
        
        
        
        <!-- **********************************************************************
             *                                FTOrder                             *
             ********************************************************************** -->
        <div4 role="xquery" id="tq-ft-fs-FTOrder">
            <head>FTOrder</head>
            
            <p>The parameters of the <function>ApplyFTOrder</function>
            function are 1) the search context, 2) the list of match
            options, and 3) one <term>AllMatches</term> parameter corresponding to
            the result of the nested <term>FTSelection</term>s. The evaluation
            context and the match options are not used by this function.
            The semantics is given below.</p>
            
<!-- file: fts.xqy -->            
            <eg role="parse-text" xml:space="preserve">
declare function fts:ApplyFTOrder (
      $allMatches as element(fts:allMatches) )
   as element(fts:allMatches) 
{
   &lt;fts:allMatches stokenNum="{$allMatches/@stokenNum}"&gt;
   {
      for $match in $allMatches/fts:match
      where every $stringInclude1 in $match/fts:stringInclude,
                  $stringInclude2 in $match/fts:stringInclude
            satisfies (($stringInclude1/fts:tokenInfo/@startPos &lt;= 
                        $stringInclude2/fts:tokenInfo/@startPos)
                       and
                       ($stringInclude1/@queryPos &lt;= 
                        $stringInclude2/@queryPos))
                      or
                       (($stringInclude1/fts:tokenInfo/@startPos&gt;= 
                         $stringInclude2/fts:tokenInfo/@startPos)
                        and
                        ($stringInclude1/@queryPos &gt;= 
                         $stringInclude2/@queryPos))
      return 
         &lt;fts:match&gt;
         {
            $match/fts:stringInclude,
            for $stringExcl in $match/fts:stringExclude
            where every $stringIncl in $match/fts:stringInclude
                  satisfies (($stringExcl/fts:tokenInfo/@startPos &lt;= 
                              $stringIncl/fts:tokenInfo/@startPos)
                             and
                              ($stringExcl/@queryPos &lt;= 
                               $stringIncl/@queryPos))
                            or
                             (($stringExcl/fts:tokenInfo/@startPos &gt;= 
                               $stringIncl/fts:tokenInfo/@startPos)
                              and
                              ($stringExcl/@queryPos &gt;= 
                               $stringIncl/@queryPos))
            return $stringExcl
         }
         &lt;/fts:match&gt;
   }         
   &lt;/fts:allMatches&gt;
};
            </eg>
            
            <p>The resulting <term>AllMatches</term> contains the <term>Match</term>es for which the start positions 
			in the <term>StringInclude</term> elements are in the order of the
            query positions of their query strings.  
			<term>StringExclude</term>s that preserve the order (with respect to their start positions) are also retained.</p>
            
            <p>For example, consider the <term>FTSelection</term>
            <code>("great" &amp;&amp; "condition")
            ordered</code>. The source <term>AllMatches</term> is given below.</p>
            
            <graphic xmlns:xlink="http://www.w3.org/1999/xlink" source="images/FTOrderEx1.jpg" alt="FTOrder input AllMatches" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
            <graphic xmlns:xlink="http://www.w3.org/1999/xlink" source="images/FTOrderEx2.jpg" alt="FTOrder input AllMatches" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
            <graphic xmlns:xlink="http://www.w3.org/1999/xlink" source="images/FTOrderEx3.jpg" alt="FTOrder input AllMatches" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
                     
            <p>The <term>AllMatches</term> for <term>FTOrder</term> are given below.</p>
            
            <graphic xmlns:xlink="http://www.w3.org/1999/xlink" source="images/FTOrderEx4.jpg" alt="FTOrder result AllMatches" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
            <graphic xmlns:xlink="http://www.w3.org/1999/xlink" source="images/FTOrderEx5.jpg" alt="FTOrder result AllMatches" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
        </div4>
        
        
        
        <!-- **********************************************************************
             *                            FTScope                        *
             ********************************************************************** -->
        <div4 role="xquery" id="tq-ft-fs-FTScope">
            <head>FTScope</head>
            
            <p>The parameters of the <function>ApplyFTScope</function>
            function are 1) the search context, 2) the list of match
            options, 3) the type of the scope (same or different), 4) the
            linguistic unit (sentence or paragraph), and 5) one
            <term>AllMatches</term> parameter corresponding to the result of the
            nested <term>FTSelection</term>s. The search context and the
            match options are not used by this function. The function
            definitions depend on the type of the scope (paragraph,
            sentence) and the scope predicate (same, different).</p>
            
            <p>The semantics of <code>same sentence</code> is given below.</p>
            
<!-- file: fts.xqy -->            
            <eg role="parse-text" xml:space="preserve">
declare function fts:ApplyFTScopeSameSentence (
      $allMatches as element(fts:allMatches) ) 
   as element(fts:allMatches) 
{
   &lt;fts:allMatches stokenNum="{$allMatches/@stokenNum}"&gt;
   {
      for $match in $allMatches/fts:match
      where every $stringInclude1 in $match/fts:stringInclude,
                  $stringInclude2 in $match/fts:stringInclude 
            satisfies $stringInclude1/fts:tokenInfo/@startSent = 
                      $stringInclude2/fts:tokenInfo/@startSent
                  and $stringInclude1/fts:tokenInfo/@startSent = 
                      $stringInclude1/fts:tokenInfo/@endSent
                  and $stringInclude2/fts:tokenInfo/@startSent = 
                      $stringInclude2/fts:tokenInfo/@endSent
                  and $stringInclude1/fts:tokenInfo/@startSent &gt; 0
                  and $stringInclude2/fts:tokenInfo/@startSent &gt; 0
      return 
        &lt;fts:match&gt;
        {
           $match/fts:stringInclude,
           for $stringExcl in $match/fts:stringExclude
           where
              $stringExcl/fts:tokenInfo/@startSent = 0
              or
              ($stringExcl/fts:tokenInfo/@startSent = 
               $stringExcl/fts:tokenInfo/@endSent
               and 
                  (every $stringIncl in $match/fts:stringInclude
                   satisfies $stringIncl/fts:tokenInfo/@startSent = 
                             $stringExcl/fts:tokenInfo/@startSent) )
           return $stringExcl
        }
        &lt;/fts:match&gt;
   }
   &lt;/fts:allMatches&gt;
};
</eg>

             <p>An <term>AllMatches</term> returned by the scope <code>same sentence</code> 
             contains those <term>Match</term>es whose <term>StringInclude</term>s span only a single 
             sentence and all span the same sentence. In these <term>Match</term>es only 
             those <term>StringExclude</term>s are retained that also only span a single 
             sentence, which is, in case there are <term>StringInclude</term>s in that <term>Match</term>, 
             the same as the one spanned by the <term>StringInclude</term>s.</p> 

           <p>The semantics of <code>different sentence
            </code> is given below.</p>
            
<!-- file: fts.xqy -->            
            <eg role="parse-text" xml:space="preserve">
declare function fts:ApplyFTScopeDifferentSentence (
      $allMatches as element(fts:allMatches) ) 
   as element(fts:allMatches) 
{
   &lt;fts:allMatches stokenNum="{$allMatches/@stokenNum}"&gt;
   {
      for $match in $allMatches/fts:match
      where every $stringInclude1 in $match/fts:stringInclude,
                  $stringInclude2 in $match/fts:stringInclude  
            satisfies $stringInclude1 = $stringInclude2
                  or $stringInclude1/fts:tokenInfo/@endSent &lt;
                     $stringInclude2/fts:tokenInfo/@startSent
                  or $stringInclude2/fts:tokenInfo/@endSent &lt;
                     $stringInclude1/fts:tokenInfo/@startSent
      return 
         &lt;fts:match&gt;
         {
            $match/fts:stringInclude,
            for $stringExcl in $match/fts:stringExclude
            where every $stringIncl in $match/fts:stringInclude
                  satisfies $stringExcl/fts:tokenInfo/@endSent &lt;  
                            $stringIncl/fts:tokenInfo/@startSent
                         or $stringIncl/fts:tokenInfo/@endSent &lt;
                            $stringExcl/fts:tokenInfo/@startSent
            return $stringExcl
         }
         &lt;/fts:match&gt;
   }
   &lt;/fts:allMatches&gt;
};
</eg>
            
            <p>An <term>AllMatches</term> returned by the scope <code>different sentence</code> 
            contains those <term>Match</term>es that have no two <term>StringInclude</term>s covering 
            the same sentence.
            In these <term>Match</term>es only those <term>StringExclude</term>s are retained that also do not 
            cover a common sentence with one of the <term>StringInclude</term>s.</p> 

            <p>The semantics of <code>same paragraph</code> is analogous to <code>same
            sentence</code> and is given below.</p>
            
<!-- file: fts.xqy -->            
            <eg role="parse-text" xml:space="preserve">
declare function fts:ApplyFTScopeSameParagraph (
      $allMatches as element(fts:allMatches) ) 
   as element(fts:allMatches) 
{
   &lt;fts:allMatches stokenNum="{$allMatches/@stokenNum}"&gt;
   {
      for $match in $allMatches/fts:match
      where every $stringInclude1 in $match/fts:stringInclude,
                  $stringInclude2 in $match/fts:stringInclude  
            satisfies $stringInclude1/fts:tokenInfo/@startPara = 
                      $stringInclude2/fts:tokenInfo/@startPara
                  and $stringInclude1/fts:tokenInfo/@startPara = 
                      $stringInclude1/fts:tokenInfo/@endPara
                  and $stringInclude2/fts:tokenInfo/@startPara = 
                      $stringInclude2/fts:tokenInfo/@endPara
                  and $stringInclude1/fts:tokenInfo/@startPara &gt; 0
                  and $stringInclude2/fts:tokenInfo/@endPara &gt; 0
      return 
         &lt;fts:match&gt;
         {
            $match/fts:stringInclude,
            for $stringExcl in $match/fts:stringExclude
            where 
               $stringExcl/fts:tokenInfo/@startPara = 0
               or
               ($stringExcl/fts:tokenInfo/@startPara = 
                $stringExcl/fts:tokenInfo/@endPara
                and
                   (every $stringIncl in $match/fts:stringInclude
                    satisfies $stringIncl/fts:tokenInfo/@startPara = 
                              $stringExcl/fts:tokenInfo/@startPara) )
            return $stringExcl
         }
         &lt;/fts:match&gt;
   }
   &lt;/fts:allMatches&gt;
};
</eg>
            
            <p>The semantics of <code>different paragraph</code> is analogous to 
            <code>different sentence</code> and is given below.</p>
            
<!-- file: fts.xqy -->            
            <eg role="parse-text" xml:space="preserve">
declare function fts:ApplyFTScopeDifferentParagraph (
      $allMatches as element(fts:allMatches) ) 
   as element(fts:allMatches) 
{
   &lt;fts:allMatches stokenNum="{$allMatches/@stokenNum}"&gt;
   {
      for $match in $allMatches/fts:match
      where every $stringInclude1 in $match/fts:stringInclude,
                  $stringInclude2 in $match/fts:stringInclude  
            satisfies $stringInclude1 = $stringInclude2
                   or $stringInclude1/fts:tokenInfo/@endPara &lt;
                      $stringInclude2/fts:tokenInfo/@startPara
                   or $stringInclude2/fts:tokenInfo/@endPara &lt;
                      $stringInclude1/fts:tokenInfo/@startPara
      return 
         &lt;fts:match&gt;
         {
            $match/fts:stringInclude,
            for $stringExcl in $match/fts:stringExclude
            where every $stringIncl in $match/fts:stringInclude
                  satisfies $stringExcl/fts:tokenInfo/@endPara &lt;  
                            $stringIncl/fts:tokenInfo/@startPara
                         or $stringIncl/fts:tokenInfo/@endPara &lt;
                            $stringExcl/fts:tokenInfo/@startPara
            return $stringExcl
         }
         &lt;/fts:match&gt;
   }
   &lt;/fts:allMatches&gt;
};
</eg>
            
            <p>The semantics for the general case is given below.</p>
            
<!-- file: fts.xqy -->            
            <eg role="parse-text" xml:space="preserve">
declare function fts:ApplyFTScope (
      $type as fts:ScopeType,
      $selector as fts:ScopeSelector, 
      $allMatches as element(fts:allMatches) ) 
   as element(fts:allMatches) 
{
   if ($type eq "same" and $selector eq "sentence")
   then fts:ApplyFTScopeSameSentence($allMatches)
   else if ($type eq "different" and $selector eq "sentence")
      then fts:ApplyFTScopeDifferentSentence($allMatches)
   else if ($type eq "same" and $selector eq "paragraph")
      then fts:ApplyFTScopeSameParagraph($allMatches)
   else fts:ApplyFTScopeDifferentParagraph($allMatches)
};
</eg>
            
            <p>For example, consider the <term>FTSelection</term>
            <code>("Mustang" &amp;&amp; "Honda") same 
            paragraph</code>. The source <term>AllMatches</term> is given below.</p>
            
            <graphic xmlns:xlink="http://www.w3.org/1999/xlink" source="images/FTScopeEx.jpg" alt="FTScope input AllMatches" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
                     
            <p>The <term>FTScope</term> returns an empty <term>AllMatches</term> because neither 
			<term>Match</term> contains <term>TokenInfo</term>s from a single sentence.</p>
            
        </div4>
        
        
        
        <!-- ***************************************************************
             *                            FTContent                        *
             *************************************************************** -->
        <div4 role="xquery" id="tq-ft-fs-FTContent">
            <head>FTContent</head>
            
            <p>The parameters of the <function>ApplyFTContent</function>
            function are 1) the search context, 2) the match options,
            3) the type of the content
            match at the start of the current node, at the end of it,
            or its entire content, and 4) one
            <term>AllMatches</term> parameter corresponding to the result of the
            nested <term>FTSelection</term>s. The semantics is given below.</p>
            
<!-- file: fts.xqy -->            
            <eg role="parse-text" xml:space="preserve">
declare function fts:ApplyFTContent (
      $searchContext as item(),
      $matchOptions as element(fts:matchOptions),
      $type as fts:ContentMatchType,
      $allMatches as element(fts:allMatches) ) 
   as element(fts:allMatches) 
{
   if ($type eq "entire content") then
      let $temp1 := fts:ApplyFTWordDistanceExactly(
                        $matchOptions,
                        $allMatches,
                        1)
      let $temp2 := fts:ApplyFTContent(
                        $searchContext,
                        $matchOptions,
                        $temp1,
                        "at start")
      let $temp3 := fts:ApplyFTContent(
                        $searchContext,
                        $matchOptions,
                        $temp2,
                        "at end")
      return $temp3
   else
      &lt;fts:allMatches stokenNum="{$allMatches/@stokenNum}"&gt;
      {
         for $match in $allMatches/fts:match
         where if ($type eq "at start") then
                  some $si in $match/fts:stringInclude
                  satisfies fts:isStartToken($searchContext,
                                             $si/fts:tokenInfo)
               else (: $type eq "at end" :) 
                  some $si in $match/fts:stringInclude
                  satisfies fts:isEndToken($searchContext,
                                           $si/fts:tokenInfo)
         return $match
      }
      &lt;/fts:allMatches&gt;
};
</eg>
            
        <p>The evaluation of scope functions depends on 
        the type of the content match.</p>
		<ulist>
		
		<item><p><code>entire match</code> is evaluated as
		<code>distance exactly 0 words at start at end</code>, i.e., all the
		<term>StringInclude</term>s must match every token in the content of the current
		search context node.</p></item>
		
		
		<item><p><code>at start</code> retains only 
        <term>Match</term>es that contain a <term>StringInclude</term> that matches the 
        first token. This is checked using the semantic function
        <code>fts:isStartToken</code>.</p></item> 
		
		<item><p><code>at end</code> retains the 
        <term>Match</term>es that contain a <term>StringInclude</term> that matches the 
        last token. This is checked using the semantic function
        <code>fts:isEndToken</code>.</p></item>
		
		</ulist>
        </div4>
        
        
        <!-- **********************************************************************
             *                            FTDistance                     *
             ********************************************************************** -->
        <div4 role="xquery" id="tq-ft-fs-FTDistance">
            <head>FTDistance</head>
            
            <p>The parameters of the
            <function>ApplyFTDistance</function> function are 1) the
            search context, 2) the list of match options, 3) one
            <term>AllMatches</term> parameter corresponding to the result of the
            nested <term>FTSelection</term>s, 4) the unit of the distance (tokens,
            sentences, paragraphs), and 5) the range specified.
            The search context is not used by this function. The
            function definitions depend on the distance units and the range 
			specifications.</p>
            
            <p>The semantics of case <code>word distance exactly N</code> 
			is given below.</p>
            
<!-- file: fts.xqy -->            
            <eg role="parse-text" xml:space="preserve">
declare function fts:ApplyFTWordDistanceExactly(
      $matchOptions as element(fts:matchOptions),
      $allMatches as element(fts:allMatches),
      $n as xs:integer ) 
   as element(fts:allMatches) 
{
   &lt;fts:allMatches stokenNum="{$allMatches/@stokenNum}"&gt;
   {
      for $match in $allMatches/fts:match
      let $sorted := for $si in $match/fts:stringInclude          
                     order by $si/fts:tokenInfo/@startPos ascending
                     return $si
      where 
         if (fn:count($sorted) le 1) then fn:true() else
            every $idx in 1 to fn:count($sorted) - 1
            satisfies fts:wordDistance(
                         $sorted[$idx]/fts:tokenInfo,
                         $sorted[$idx+1]/fts:tokenInfo,
                         $matchOptions) = $n 
      return 
         &lt;fts:match&gt;
         {
            $match/fts:stringInclude,
            for $stringExcl in $match/fts:stringExclude
            where some $stringIncl in $match/fts:stringInclude
                  satisfies fts:wordDistance(
                                $stringIncl/fts:tokenInfo,
                                $stringExcl/fts:tokenInfo,
                                $matchOptions) = $n
            return $stringExcl
         }
         &lt;/fts:match&gt;
   }
   &lt;/fts:allMatches&gt;
};
</eg>
            
            <p>The semantics of <code>word distance at least N</code> is given 
			below.</p>
            
<!-- file: fts.xqy -->            
            <eg role="parse-text" xml:space="preserve">
declare function fts:ApplyFTWordDistanceAtLeast (
      $matchOptions as element(fts:matchOptions),
      $allMatches as element(fts:allMatches),
      $n as xs:integer ) 
   as element(fts:allMatches) 
{
   &lt;fts:allMatches stokenNum="{$allMatches/@stokenNum}"&gt;
   {
      for $match in $allMatches/fts:match
      let $sorted := for $si in $match/fts:stringInclude          
                     order by $si/fts:tokenInfo/@startPos ascending
                     return $si
      where 
         if (fn:count($sorted) le 1) then fn:true() else
            every $index in (1 to fn:count($sorted) - 1)
            satisfies fts:wordDistance(
                         $sorted[$index]/fts:tokenInfo,
                         $sorted[$index+1]/fts:tokenInfo,
                         $matchOptions) &gt;= $n 
      return 
         &lt;fts:match&gt;
         {
            $match/fts:stringInclude,
            for $stringExcl in $match/fts:stringExclude
            where some $stringIncl in $match/fts:stringInclude
                  satisfies fts:wordDistance(
                                $stringIncl/fts:tokenInfo,
                                $stringExcl/fts:tokenInfo,
                                $matchOptions) &gt;= $n
            return $stringExcl
         }
         &lt;/fts:match&gt;
   }           
   &lt;/fts:allMatches&gt;
};
</eg>
            
            <p>The semantics of <code>word distance at most N</code> is given 
			below.</p>
            
<!-- file: fts.xqy -->            
            <eg role="parse-text" xml:space="preserve">
declare function fts:ApplyFTWordDistanceAtMost (
      $matchOptions as element(fts:matchOptions),
      $allMatches as element(fts:allMatches),
      $n as xs:integer ) 
   as element(fts:allMatches) 
{
   &lt;fts:allMatches stokenNum="{$allMatches/@stokenNum}"&gt;
   {
      for $match in $allMatches/fts:match
      let $sorted := for $si in $match/fts:stringInclude          
                     order by $si/fts:tokenInfo/@startPos ascending
                     return $si
      where
         if (fn:count($sorted) le 1) then fn:true() else
            every $index in (1 to fn:count($sorted) - 1)
            satisfies fts:wordDistance(
                          $sorted[$index]/fts:tokenInfo,
                          $sorted[$index+1]/fts:tokenInfo,
                          $matchOptions) &lt;= $n 
      return 
        &lt;fts:match&gt;
        {
           $match/fts:stringInclude,
           for $stringExcl in $match/fts:stringExclude
           where some $stringIncl in $match/fts:stringInclude
                 satisfies fts:wordDistance(
                               $stringIncl/fts:tokenInfo,
                               $stringExcl/fts:tokenInfo,
                               $matchOptions) &lt;= $n
           return $stringExcl
        }
        &lt;/fts:match&gt;
   }
   &lt;/fts:allMatches&gt;
};
</eg>
            
            <p>The semantics of <code>word distance from M to N</code> is given 
			below.</p>
            
<!-- file: fts.xqy -->            
            <eg role="parse-text" xml:space="preserve">
declare function fts:ApplyFTWordDistanceFromTo (
      $matchOptions as element(fts:matchOptions),
      $allMatches as element(fts:allMatches),
      $m as xs:integer,
      $n as xs:integer ) 
   as element(fts:allMatches) 
{
   &lt;fts:allMatches stokenNum="{$allMatches/@stokenNum}"&gt;
   {
      for $match in $allMatches/fts:match
      let $sorted := for $si in $match/fts:stringInclude          
                     order by $si/fts:tokenInfo/@startPos ascending
                     return $si
      where 
         if (fn:count($sorted) le 1) then fn:true() else
            every $index in (1 to fn:count($sorted) - 1)
            satisfies fts:wordDistance(
                          $sorted[$index]/fts:tokenInfo,
                          $sorted[$index+1]/fts:tokenInfo,
                          $matchOptions) &gt;= $m 
                      and
                      fts:wordDistance(
                          $sorted[$index]/fts:tokenInfo,
                          $sorted[$index+1]/fts:tokenInfo,
                          $matchOptions) &lt;= $n 
      return 
         &lt;fts:match&gt;
         {
            $match/fts:stringInclude,
            for $stringExcl in $match/fts:stringExclude
            where some $stringIncl in $match/fts:stringInclude
                  satisfies fts:wordDistance(
                                $stringIncl/fts:tokenInfo,
                                $stringExcl/fts:tokenInfo,
                                $matchOptions) &gt;= $m
                            and
                            fts:wordDistance(
                                $stringIncl/fts:tokenInfo,
                                $stringExcl/fts:tokenInfo,
                                $matchOptions) &lt;= $n
            return $stringExcl
         }
         &lt;/fts:match&gt;
   }
   &lt;/fts:allMatches&gt;
};
</eg>
            
            <p>The semantics of <code>sentence distance exactly N</code> 
			is given below.</p>
            
<!-- file: fts.xqy -->            
            <eg role="parse-text" xml:space="preserve">
declare function fts:ApplyFTSentenceDistanceExactly (
      $matchOptions as element(fts:matchOptions),
      $allMatches as element(fts:allMatches),
      $n as xs:integer ) 
   as element(fts:allMatches) 
{
   &lt;fts:allMatches stokenNum="{$allMatches/@stokenNum}"&gt;
   {
      for $match in $allMatches/fts:match
      let $sorted := for $si in $match/fts:stringInclude          
                    order by $si/fts:tokenInfo/@startPos ascending
                    return $si
      where 
         if (fn:count($sorted) le 1) then fn:true() else
            every $index in (1 to fn:count($sorted) - 1)
            satisfies fts:sentenceDistance(
                          $sorted[$index]/fts:tokenInfo,
                          $sorted[$index+1]/fts:tokenInfo,
                          $matchOptions) = $n 
      return 
         &lt;fts:match&gt;
         {
            $match/fts:stringInclude,
            for $stringExcl in $match/fts:stringExclude
            where some $stringIncl in $match/fts:stringInclude
                  satisfies fts:sentenceDistance(
                                $stringIncl/fts:tokenInfo,
                                $stringExcl/fts:tokenInfo,
                                $matchOptions) = $n
            return $stringExcl
         }
         &lt;/fts:match&gt;
   }           
   &lt;/fts:allMatches&gt;
};
</eg>
            
            <p>The semantics of <code>sentence distance at least N</code> 
			is given below.</p>
            
<!-- file: fts.xqy -->            
            <eg role="parse-text" xml:space="preserve">
declare function fts:ApplyFTSentenceDistanceAtLeast (
      $matchOptions as element(fts:matchOptions),
      $allMatches as element(fts:allMatches),
      $n as xs:integer ) 
   as element(fts:allMatches) 
{
   &lt;fts:allMatches stokenNum="{$allMatches/@stokenNum}"&gt;
   {
      for $match in $allMatches/fts:match
      let $sorted := for $si in $match/fts:stringInclude          
                    order by $si/fts:tokenInfo/@startPos ascending
                    return $si
      where 
         if (fn:count($sorted) le 1) then fn:true() else
            every $index in (1 to fn:count($sorted) - 1)
            satisfies fts:sentenceDistance(
                          $sorted[$index]/fts:tokenInfo,
                          $sorted[$index+1]/fts:tokenInfo,
                          $matchOptions) &gt;= $n 
      return 
         &lt;fts:match&gt;
         {
            $match/fts:stringInclude,
            for $stringExcl in $match/fts:stringExclude
            where some $stringIncl in $match/fts:stringInclude
                  satisfies fts:sentenceDistance(
                                $stringIncl/fts:tokenInfo,
                                $stringExcl/fts:tokenInfo,
                                $matchOptions) &gt;= $n
            return $stringExcl
         }
         &lt;/fts:match&gt;
   }           
   &lt;/fts:allMatches&gt;
};
</eg>
            
            <p>The semantics of <code>sentence distance at most N</code> 
            is given below.</p>
            
<!-- file: fts.xqy -->            
            <eg role="parse-text" xml:space="preserve">
declare function fts:ApplyFTSentenceDistanceAtMost (
      $matchOptions as element(fts:matchOptions),
      $allMatches as element(fts:allMatches),
      $n as xs:integer ) 
   as element(fts:allMatches) 
{
   &lt;fts:allMatches stokenNum="{$allMatches/@stokenNum}"&gt;
   {
      for $match in $allMatches/fts:match
      let $sorted := for $si in $match/fts:stringInclude          
                    order by $si/fts:tokenInfo/@startPos ascending
                    return $si
      where 
         if (fn:count($sorted) le 1) then fn:true() else
            every $index in (1 to fn:count($sorted) - 1)
            satisfies fts:sentenceDistance(
                          $sorted[$index]/fts:tokenInfo,
                          $sorted[$index+1]/fts:tokenInfo,
                          $matchOptions) &lt;= $n 
      return 
         &lt;fts:match&gt;
         {
            $match/fts:stringInclude,
            for $stringExcl in $match/fts:stringExclude
            where some $stringIncl in $match/fts:stringInclude
                  satisfies fts:sentenceDistance(
                                $stringIncl/fts:tokenInfo,
                                $stringExcl/fts:tokenInfo,
                                $matchOptions) &lt;= $n
            return $stringExcl
         }
         &lt;/fts:match&gt;
   }           
   &lt;/fts:allMatches&gt;
};
</eg>
            
            <p>The semantics of  <code>sentence distance from M to N</code> 
            is given below.</p>
            
<!-- file: fts.xqy -->            
            <eg role="parse-text" xml:space="preserve">
declare function fts:ApplyFTSentenceDistanceFromTo (
      $matchOptions as element(fts:matchOptions),
      $allMatches as element(fts:allMatches),
      $m as xs:integer,
      $n as xs:integer ) 
   as element(fts:allMatches) 
{
   &lt;fts:allMatches stokenNum="{$allMatches/@stokenNum}"&gt;
   {
      for $match in $allMatches/fts:match
      let $sorted := for $si in $match/fts:stringInclude          
                    order by $si/fts:tokenInfo/@startPos ascending
                    return $si
      where 
         if (fn:count($sorted) le 1) then fn:true() else
            every $index in (1 to fn:count($sorted) - 1)
            satisfies fts:sentenceDistance(
                          $sorted[$index]/fts:tokenInfo,
                          $sorted[$index+1]/fts:tokenInfo,
                          $matchOptions) &gt;= $m 
                      and
                      fts:sentenceDistance(
                          $sorted[$index]/fts:tokenInfo,
                          $sorted[$index+1]/fts:tokenInfo,
                          $matchOptions) &lt;= $n 
      return 
         &lt;fts:match&gt;
         {
            $match/fts:stringInclude,
            for $stringExcl in $match/fts:stringExclude
            where some $stringIncl in $match/fts:stringInclude
                  satisfies fts:sentenceDistance(
                                $stringIncl/fts:tokenInfo,
                                $stringExcl/fts:tokenInfo,
                                $matchOptions) &gt;= $m
                            and
                            fts:sentenceDistance(
                                $stringIncl/fts:tokenInfo,
                                $stringExcl/fts:tokenInfo,
                                $matchOptions) &lt;= $n
            return $stringExcl
         }
         &lt;/fts:match&gt;
   }
   &lt;/fts:allMatches&gt;
};
</eg>
            
            <p>The semantics of <code>paragraph distance exactly N</code> 
			is given below.</p>
            
<!-- file: fts.xqy -->            
            <eg role="parse-text" xml:space="preserve">
declare function fts:ApplyFTParagraphDistanceExactly (
      $matchOptions as element(fts:matchOptions),
      $allMatches as element(fts:allMatches),
      $n as xs:integer ) 
   as element(fts:allMatches) 
{
   &lt;fts:allMatches stokenNum="{$allMatches/@stokenNum}"&gt;
   {
      for $match in $allMatches/fts:match
      let $sorted := for $si in $match/fts:stringInclude          
                    order by $si/fts:tokenInfo/@startPos ascending
                    return $si
      where 
         if (fn:count($sorted) le 1) then fn:true() else
            every $index in (1 to fn:count($sorted) - 1)
            satisfies fts:paraDistance(
                          $sorted[$index]/fts:tokenInfo,
                          $sorted[$index+1]/fts:tokenInfo,
                          $matchOptions) = $n 
      return 
         &lt;fts:match&gt;
         {
            $match/fts:stringInclude,
            for $stringExcl in $match/fts:stringExclude
            where some $stringIncl in $match/fts:stringInclude
                  satisfies fts:paraDistance(
                                $stringIncl/fts:tokenInfo,
                                $stringExcl/fts:tokenInfo,
                                $matchOptions) = $n
            return $stringExcl
         }
         &lt;/fts:match&gt;
   }           
   &lt;/fts:allMatches&gt;
};
</eg>
            
            <p>The semantics of <code>paragraph distance at least N</code> 
		is given below.</p>
            
<!-- file: fts.xqy -->            
            <eg role="parse-text" xml:space="preserve">
declare function fts:ApplyFTParagraphDistanceAtLeast (
      $matchOptions as element(fts:matchOptions),
      $allMatches as element(fts:allMatches),
      $n as xs:integer ) 
   as element(fts:allMatches) 
{
   &lt;fts:allMatches stokenNum="{$allMatches/@stokenNum}"&gt;
   {
      for $match in $allMatches/fts:match
      let $sorted := for $si in $match/fts:stringInclude          
                    order by $si/fts:tokenInfo/@startPos ascending
                    return $si
      where 
         if (fn:count($sorted) le 1) then fn:true() else
            every $index in (1 to fn:count($sorted) - 1)
            satisfies fts:paraDistance(
                          $sorted[$index]/fts:tokenInfo,
                          $sorted[$index+1]/fts:tokenInfo,
                          $matchOptions) &gt;= $n 
      return 
         &lt;fts:match&gt;
         {
            $match/fts:stringInclude,
            for $stringExcl in $match/fts:stringExclude
            where some $stringIncl in $match/fts:stringInclude
                  satisfies fts:paraDistance(
                                $stringIncl/fts:tokenInfo,
                                $stringExcl/fts:tokenInfo,
                                $matchOptions) &gt;= $n
            return $stringExcl
         }
         &lt;/fts:match&gt;
   }           
   &lt;/fts:allMatches&gt;
};
</eg>
            
            <p>The semantics of <code>paragraph distance at most N</code>
		is given below.</p>
            
<!-- file: fts.xqy -->            
            <eg role="parse-text" xml:space="preserve">
declare function fts:ApplyFTParagraphDistanceAtMost (
      $matchOptions as element(fts:matchOptions),
      $allMatches as element(fts:allMatches),
      $n as xs:integer ) 
   as element(fts:allMatches) 
{
   &lt;fts:allMatches stokenNum="{$allMatches/@stokenNum}"&gt;
   {
      for $match in $allMatches/fts:match
      let $sorted := for $si in $match/fts:stringInclude          
                    order by $si/fts:tokenInfo/@startPos ascending
                    return $si
      where 
         if (fn:count($sorted) le 1) then fn:true() else
            every $index in (1 to fn:count($sorted) - 1)
            satisfies fts:paraDistance(
                          $sorted[$index]/fts:tokenInfo,
                          $sorted[$index+1]/fts:tokenInfo,
                          $matchOptions) &lt;= $n 
      return 
         &lt;fts:match&gt;
         {
            $match/fts:stringInclude,
            for $stringExcl in $match/fts:stringExclude
            where some $stringIncl in $match/fts:stringInclude
                  satisfies fts:paraDistance(
                                $stringIncl/fts:tokenInfo,
                                $stringExcl/fts:tokenInfo,
                                $matchOptions) &lt;= $n
            return $stringExcl
         }
         &lt;/fts:match&gt;
   }           
   &lt;/fts:allMatches&gt;
};
</eg>
            
            <p>The semantics of <code>paragraph distance from M to N</code>
		is given below.</p>
            
<!-- file: fts.xqy -->            
            <eg role="parse-text" xml:space="preserve">
declare function fts:ApplyFTParagraphDistanceFromTo (
      $matchOptions as element(fts:matchOptions),
      $allMatches as element(fts:allMatches),
      $m as xs:integer,
      $n as xs:integer ) 
   as element(fts:allMatches) 
{
   &lt;fts:allMatches stokenNum="{$allMatches/@stokenNum}"&gt;
   {
      for $match in $allMatches/fts:match
      let $sorted := for $si in $match/fts:stringInclude          
                    order by $si/fts:tokenInfo/@startPos ascending
                    return $si
      where 
         if (fn:count($sorted) le 1) then fn:true() else
            every $index in (1 to fn:count($sorted) - 1)
            satisfies fts:paraDistance(
                          $sorted[$index]/fts:tokenInfo,
                          $sorted[$index+1]/fts:tokenInfo,
                          $matchOptions) &gt;= $m 
                      and
                      fts:paraDistance(
                          $sorted[$index]/fts:tokenInfo,
                          $sorted[$index+1]/fts:tokenInfo,
                          $matchOptions) &lt;= $n 
      return 
         &lt;fts:match&gt;
         {
            $match/fts:stringInclude,
            for $stringExcl in $match/fts:stringExclude
            where some $stringIncl in $match/fts:stringInclude
                  satisfies fts:paraDistance(
                                $stringIncl/fts:tokenInfo,
                                $stringExcl/fts:tokenInfo,
                                $matchOptions) &gt;= $m
                            and
                            fts:paraDistance(
                                $stringIncl/fts:tokenInfo,
                                $stringExcl/fts:tokenInfo,
                                $matchOptions) &lt;= $n
            return $stringExcl
         }
         &lt;/fts:match&gt;
   }
   &lt;/fts:allMatches&gt;
};
</eg>
            
            <p>The resulting <term>AllMatches</term> contains 
            <term>Match</term>es of the operand that satisfy the condition that
            the distance 
            for every pair of consecutive <term>StringInclude</term>s is within the specified interval,
            where the distance is measured in tokens, sentences, or paragraphs from the end 
            of the preceding <term>StringInclude</term> to the start of the next.
<!--			<termdef id="ConsecutivePosDef" term="ConsecutivePos"><term>Consecutive 
			Positions</term> in a &Match; are two positions from the same 
			&Match; with no intervening &StringInclude;s.</termdef>-->
            </p>
            
            <p>In the general case, the semantics is given below.</p>
            
<!-- file: fts.xqy -->            
            <eg role="parse-text" xml:space="preserve">
declare function fts:ApplyFTDistance (
      $matchOptions as element(fts:matchOptions),
      $type as fts:DistanceType,
      $range as element(fts:range),
      $allMatches as element(fts:allMatches) ) 
   as element(fts:allMatches) 
{
   if ($type eq "word") then
      if ($range/@type eq "exactly") then
         fts:ApplyFTWordDistanceExactly($matchOptions, 
                                        $allMatches, 
                                        $range/@n)
      else if ($range/@type eq "at least") then 
         fts:ApplyFTWordDistanceAtLeast($matchOptions, 
                                        $allMatches, 
                                        $range/@n)
      else if ($range/@type eq "at most") then
         fts:ApplyFTWordDistanceAtMost($matchOptions, 
                                       $allMatches,
                                       $range/@n)
      else fts:ApplyFTWordDistanceFromTo($matchOptions, 
                                         $allMatches, 
                                         $range/@m,
                                         $range/@n)
   else if ($type eq "sentence") then
      if ($range/@type eq "exactly") then
         fts:ApplyFTSentenceDistanceExactly($matchOptions, 
                                            $allMatches, 
                                            $range/@n)
      else if ($range/@type eq "at least") then
         fts:ApplyFTSentenceDistanceAtLeast($matchOptions, 
                                            $allMatches, 
                                            $range/@n)
      else if ($range/@type eq "at most") then
         fts:ApplyFTSentenceDistanceAtMost($matchOptions, 
                                           $allMatches, 
                                           $range/@n)
      else fts:ApplyFTSentenceDistanceFromTo($matchOptions, 
                                             $allMatches, 
                                             $range/@m,
                                             $range/@n)
   else if ($range/@type eq "exactly") then
      fts:ApplyFTParagraphDistanceExactly($matchOptions, 
                                          $allMatches, 
                                          $range/@n)
   else if ($range/@type eq "at least") then
      fts:ApplyFTParagraphDistanceAtLeast($matchOptions, 
                                          $allMatches, 
                                          $range/@n)
   else if ($range/@type eq "at most") then
      fts:ApplyFTParagraphDistanceAtMost($matchOptions, 
                                         $allMatches, 
                                         $range/@n)
   else fts:ApplyFTParagraphDistanceFromTo($matchOptions, 
                                           $allMatches, 
                                           $range/@m,
                                           $range/@n)
};
</eg>
            
            <p>For example, consider the <term>FTDistance</term> selection
            <code>("Ford Mustang" &amp;&amp;
            "excellent") distance at most 3 words</code>.
            The <term>Match</term>es of the source <term>AllMatches</term> for
            <code>("Ford Mustang" &amp;&amp;
            "excellent")</code> are given below.</p>
            
            <graphic xmlns:xlink="http://www.w3.org/1999/xlink" source="images/FTDistanceEx1.jpg" alt="FTDistance input AllMatches" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
            <p><emph>Continued on next diagram</emph></p>
            <graphic xmlns:xlink="http://www.w3.org/1999/xlink" source="images/FTDistanceEx2.jpg" alt="FTDistance input AllMatches" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
            <p><emph>Continued on next diagram</emph></p>
            <graphic xmlns:xlink="http://www.w3.org/1999/xlink" source="images/FTDistanceEx3.jpg" alt="FTDistance input AllMatches" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
            <p><emph>Continued on next diagram</emph></p>
            <graphic xmlns:xlink="http://www.w3.org/1999/xlink" source="images/FTDistanceEx4.jpg" alt="FTDistance input AllMatches" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
            <p><emph>Continued on next diagram</emph></p>
            <graphic xmlns:xlink="http://www.w3.org/1999/xlink" source="images/FTDistanceEx5.jpg" alt="FTDistance input AllMatches" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
            <p><emph>Continued on next diagram</emph></p>
            <graphic xmlns:xlink="http://www.w3.org/1999/xlink" source="images/FTDistanceEx6.jpg" alt="FTDistance input AllMatches" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>

            <p>The result for the <term>FTDistance</term> selection
            consists of only the first <term>Match</term> (with positions 1, 2, and 5), because only
            for this <term>Match</term> the word distance between consecutive <term>TokenInfo</term>s  is always less than or equal to 3. It is 1 for the first pair and 3 for the second.</p>
            
        </div4>
        
        
        
        <!-- **********************************************************************
             *                            FTWindow                       *
             ********************************************************************** -->
        <div4 role="xquery" id="tq-ft-fs-FTWindow">
            <head>FTWindow</head>
            
            <p>The parameters of the
            <function>ApplyFTWindow</function> function are 1) the
            search context, 2) the list of match options, 3) the unit of
            type <code>fts:DistanceType</code>, 4) a size, and 5) one
            <term>AllMatches</term> parameter 
            corresponding to the result of the nested <term>FTSelection</term>s.
            The search context is not used by this function. For each unit 
			type a function is defined as follows.</p>
            
            <p>The semantics of <code>window N words </code> is given below.</p>
            
<!-- file: fts.xqy -->            
            <eg role="parse-text" xml:space="preserve">
declare function fts:ApplyFTWordWindow (
      $matchOptions as element(fts:matchOptions),
      $allMatches as element(fts:allMatches),
      $n as xs:integer ) 
   as element(fts:allMatches) 
{
   &lt;fts:allMatches stokenNum="{$allMatches/@stokenNum}"&gt;
   {
      for $match in $allMatches/fts:match
      let $minpos := fn:min($match/*/fts:tokenInfo/@startPos),
          $maxpos := fn:max($match/*/fts:tokenInfo/@endPos)
      for $windowStartPos in ($minpos to $maxpos - $n + 1)
      let $windowEndPos := $windowStartPos + $n - 1
      where fn:min($match/fts:stringInclude/fts:tokenInfo/@startPos) 
            &gt;= $windowStartPos
            and fn:max($match/fts:stringInclude/fts:tokenInfo/@endPos) 
                &lt;= $windowEndPos
      return 
         &lt;fts:match&gt;
         {
            $match/fts:stringInclude,
            for $stringExclude in $match/fts:stringExclude
            where $stringExclude/fts:tokenInfo/@startPos &gt;= $windowStartPos
                  and $stringExclude/fts:tokenInfo/@endPos &lt;= $windowEndPos
            return $stringExclude
         }
         &lt;/fts:match&gt;
   }
   &lt;/fts:allMatches&gt;
};
</eg>
            
            <p>The semantics of <code>window N sentences</code> is given below.</p>
            
<!-- file: fts.xqy -->            
            <eg role="parse-text" xml:space="preserve">
declare function fts:ApplyFTSentenceWindow (
      $matchOptions as element(fts:matchOptions),
      $allMatches as element(fts:allMatches),
      $n as xs:integer ) 
   as element(fts:allMatches) 
{
   &lt;fts:allMatches stokenNum="{$allMatches/@stokenNum}"&gt;
   {
      for $match in $allMatches/fts:match
      let $minpos := fn:min($match/*/fts:tokenInfo/@startSent),
          $maxpos := fn:max($match/*/fts:tokenInfo/@endSent)
      for $windowStartPos in ($minpos to $maxpos - $n + 1)
      let $windowEndPos := $windowStartPos + $n - 1
      where fn:min($match/fts:stringInclude/fts:tokenInfo/@startSent) 
            &gt;= $windowStartPos
            and fn:max($match/fts:stringInclude/fts:tokenInfo/@endSent) 
                &lt;= $windowEndPos
      return 
         &lt;fts:match&gt;
         {
            $match/fts:stringInclude,
            for $stringExclude in $match/fts:stringExclude
            where $stringExclude/fts:tokenInfo/@startSent &gt;= $windowStartPos
                  and $stringExclude/fts:tokenInfo/@endSent &lt;= $windowEndPos
            return $stringExclude
         }
         &lt;/fts:match&gt;
   }
   &lt;/fts:allMatches&gt;
};
</eg>
            
            <p>The semantics of <code>word N paragraphs </code> is given below.</p>
            
<!-- file: fts.xqy -->            
            <eg role="parse-text" xml:space="preserve">
declare function fts:ApplyFTParagraphWindow (
      $matchOptions as element(fts:matchOptions),
      $allMatches as element(fts:allMatches),
      $n as xs:integer ) 
   as element(fts:allMatches)
{
   &lt;fts:allMatches stokenNum="{$allMatches/@stokenNum}"&gt;
   {
      for $match in $allMatches/fts:match
      let $minpos := fn:min($match/*/fts:tokenInfo/@startPara),
          $maxpos := fn:max($match/*/fts:tokenInfo/@endPara)
      for $windowStartPos in ($minpos to $maxpos - $n + 1)
      let $windowEndPos := $windowStartPos + $n - 1
      where fn:min($match/fts:stringInclude/fts:tokenInfo/@startPara) 
            &gt;= $windowStartPos
            and fn:max($match/fts:stringInclude/fts:tokenInfo/@endPara) 
                &lt;= $windowEndPos
      return 
         &lt;fts:match&gt;
         {
            $match/fts:stringInclude,
            for $stringExclude in $match/fts:stringExclude
            where $stringExclude/fts:tokenInfo/@startPara &gt;= $windowStartPos
                  and $stringExclude/fts:tokenInfo/@endPara &lt;= $windowEndPos
            return $stringExclude
         }
         &lt;/fts:match&gt;
   }
   &lt;/fts:allMatches&gt;
};
</eg>
            
            <p>The resulting <term>AllMatches</term> contains 
            <term>Match</term>es of the operand that satisfy the condition that
            there exists a sequence of the specified number of
            consecutive (token, sentence, or paragraph) positions, such
            that all <term>StringInclude</term>s are within that window, and the
            <term>StringExclude</term>s retained are also within that window. </p>
            
            <p>The semantics for the general function  is given below.</p>
            
<!-- file: fts.xqy -->            
            <eg role="parse-text" xml:space="preserve">
declare function fts:ApplyFTWindow (
      $matchOptions as element(fts:matchOptions),
      $type as fts:DistanceType,
      $size as xs:integer,
      $allMatches as element(fts:allMatches) ) 
   as element(fts:allMatches) 
{
   if ($type eq "word") then
      fts:ApplyFTWordWindow($matchOptions, 
                            $allMatches, 
                            $size)
   else if ($type eq "sentence") then 
      fts:ApplyFTSentenceWindow($matchOptions, 
                                $allMatches, 
                                $size)
   else
      fts:ApplyFTParagraphWindow($matchOptions, 
                                 $allMatches, 
                                 $size)
};
</eg>
            
            <p>For example, consider the <term>FTWindow</term> selection
            <code>("Ford Mustang" &amp;&amp;
            "excellent") window 10 words</code>.
            The <term>Match</term>es of the source <term>AllMatches</term> for
            <code>("Ford Mustang" &amp;&amp;
            "excellent")</code> are given below.</p>
            
            <graphic xmlns:xlink="http://www.w3.org/1999/xlink" source="images/FTWindowEx1.jpg" alt="FTWindow AllMatches" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
            <p><emph>Continued on next diagram</emph></p>
            <graphic xmlns:xlink="http://www.w3.org/1999/xlink" source="images/FTWindowEx2.jpg" alt="FTWindow AllMatches" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
            <p><emph>Continued on next diagram</emph></p>
            <graphic xmlns:xlink="http://www.w3.org/1999/xlink" source="images/FTWindowEx3.jpg" alt="FTWindow AllMatches" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
            <p><emph>Continued on next diagram</emph></p>
            <graphic xmlns:xlink="http://www.w3.org/1999/xlink" source="images/FTWindowEx4.jpg" alt="FTWindow AllMatches" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
            <p><emph>Continued on next diagram</emph></p>
            <graphic xmlns:xlink="http://www.w3.org/1999/xlink" source="images/FTWindowEx5.jpg" alt="FTWindow AllMatches" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
            <p><emph>Continued on next diagram</emph></p>
            <graphic xmlns:xlink="http://www.w3.org/1999/xlink" source="images/FTWindowEx6.jpg" alt="FTWindow AllMatches" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
                     
            <p>The result for the <term>FTWindow</term> selection 
            consists of only the first, the fifth, and the sixth
            <term>Match</term>es because their respective window sizes are 5, 4,
            and 9.</p>
            
        </div4>
        
        
        
        <!-- *************************************************************
             *                            FTTimes                        *
             ************************************************************* -->
        <div4 role="xquery" id="tq-ft-fs-FTTimes">
            <head>FTTimes</head>
            
            <p>The parameters of the <function>ApplyFTTimes</function>
            function are 1)an <term>FTRange</term> specification, and 2)
            parameter corresponding to the result of the nested
            <term>FTWords</term>. </p>
            
            <p>The function definitions depend on the range
            specification <term>FTRange</term> to limit the number of
            occurrences. </p>
			
			<p>The general semantics is given below.</p>
            
<!-- file: fts.xqy -->            
            <eg role="parse-text" xml:space="preserve">
declare function fts:FormCombinations (
      $sms as element(fts:match)*, 
      $times as xs:integer ) 
   as element(fts:match)*
{
   if ( $times eq 1 ) then $sms
   else if (fn:count($sms) lt $times) then ()
   else if (fn:count($sms) eq $times) then 
      &lt;fts:match&gt;{$sms/*}&lt;/fts:match&gt; 
   else (
      fts:FormCombinations(fn:subsequence($sms, 2), $times),
      for $combination in 
         fts:FormCombinations(fn:subsequence($sms, 2), $times - 1)
      return 
      &lt;fts:match&gt;
      {
         $sms[1]/*,
         $combination/*
      }
      &lt;/fts:match&gt;
   )
};

declare function fts:FormRange (
      $sms as element(fts:match)*, 
      $l as xs:integer, 
      $u as xs:integer, 
      $stokenNum as xs:integer ) 
   as element(fts:allMatches)
{
   if ($l &gt; $u) then ()
   else 
      let $am1 := &lt;fts:allMatches stokenNum="{$stokenNum}"&gt;
                     {fts:FormCombinations($sms, $l)}
                  &lt;/fts:allMatches&gt;
      let $am2 := &lt;fts:allMatches stokenNum="{$stokenNum}"&gt;
                     {fts:FormCombinations($sms, $u+1)}
                  &lt;/fts:allMatches&gt;
      return fts:ApplyFTAnd($am1,
                            fts:ApplyFTUnaryNot($am2))
};
            </eg>
            
            <p>The semantics of <code>occurs exactly N times</code> is given 
			below.</p>
            
<!-- file: fts.xqy -->            
            <eg role="parse-text" xml:space="preserve">
declare function fts:ApplyFTTimesExactly (
      $allMatches as element(fts:allMatches),
      $n as xs:integer ) 
   as element(fts:allMatches) 
{
   fts:FormRange($allMatches/match, $n, $n, $allMatches/@stokenNum)      
};
</eg>
            
            <p>The semantics of <code>occurs at least N times</code> is given below.</p>
            
<!-- file: fts.xqy -->            
            <eg role="parse-text" xml:space="preserve">
declare function fts:ApplyFTTimesAtLeast (
      $allMatches as element(fts:allMatches),
      $n as xs:integer ) 
   as element(fts:allMatches) 
{
   &lt;fts:allMatches stokenNum="{$allMatches/@stokenNum}"&gt; 
   {fts:FormCombinations($allMatches/fts:match, $n)} 
   &lt;/fts:allMatches&gt;
};
</eg>
            
            <p>The semantics of <code>occurs at most N times</code> is given
			below.</p>
            
<!-- file: fts.xqy -->            
            <eg role="parse-text" xml:space="preserve">
declare function fts:ApplyFTTimesAtMost (
      $allMatches as element(fts:allMatches),
      $n as xs:integer ) 
   as element(fts:allMatches) 
{
   fts:FormRange($allMatches/fts:match, 0, $n, $allMatches/@stokenNum)
};
</eg>
            
            <p>The semantics of <code>occurs from M to N times</code> is given below.</p>
            
<!-- file: fts.xqy -->            
            <eg role="parse-text" xml:space="preserve">
declare function fts:ApplyFTTimesFromTo (
      $allMatches as element(fts:allMatches),
      $m as xs:integer,
      $n as xs:integer ) 
   as element(fts:allMatches) 
{
   fts:FormRange($allMatches/fts:match, $m, $n, $allMatches/@stokenNum)  
};
</eg>
            
            <p>The way to ensure that
            there are at least <term>N</term> different matches of an
            <term>FTSelection</term> is to ensure that at least <term>N</term> of
            its <term>Match</term>es occur simultaneously. This is similar to
            forming their conjunction by combining <term>N</term> distinct
            <term>Match</term>es into one simple match. Therefore, the <term>AllMatches</term>
            for the selection condition specifying the range qualifier
            <code>at least N </code> contains the possible
            combinations of <term>N</term> simple matches of the
            operand and one <term>Match</term> for each combination
            negating the rest of the simple matches. This operations
            is performed in the function <function>
            fts:FormCombinations</function>.</p>
            
			<p>The range [l, u] is represented by the condition 
			<code>at least l and not at least l+1</code>.This transformation
            is performed in the function
            <function>fts:FormRange</function>.</p>
            
            <p>The semantics for the general case is given below. </p>
            
<!-- file: fts.xqy -->            
            <eg role="parse-text" xml:space="preserve">
declare function fts:ApplyFTTimes (
      $range as element(fts:range),
      $allMatches as element(fts:allMatches) ) 
   as element(fts:allMatches) 
{
   if (fn:count($allMatches//fts:stringExclude) gt 0) then
      fn:error(fn:QName('http://www.w3.org/2005/xqt-errors', 'err:XPST0003'))
   else if ($range/@type eq "exactly") then
      fts:ApplyFTTimesExactly($allMatches, $range/@n)
   else if ($range/@type eq "at least") then 
      fts:ApplyFTTimesAtLeast($allMatches, $range/@n)
   else if ($range/@type eq "at most") then
      fts:ApplyFTTimesAtMost($allMatches, $range/@n)
   else fts:ApplyFTTimesFromTo($allMatches, 
                               $range/@m, 
                               $range/@n)
};
</eg>
		
			<p>The above function performs a sanity check to ensure that the nested 
			<term>AllMatches</term> is a result of the evaluation of <term>FTWords</term> as defined in
			the grammar. </p>
			
			<scrap headstyle="show">
			  <head/>
			  <prod num="149" id="doc-xquery-FTWordsSelection"><lhs>FTWordsSelection</lhs><rhs>(<nt def="doc-xquery-FTWords">FTWords</nt>  <nt def="doc-xquery-FTTimes">FTTimes</nt>?)  |  ("("  <nt def="doc-xquery-FTSelection">FTSelection</nt>  ")")</rhs></prod>
			</scrap> 

			
			<p> Otherwise, an error <xerrorref spec="XP" class="ST" code="0003" type="static"/>
			is raised. </p>            

            <p>For example, consider the <term>FTTimes</term> selection
            <code>"Mustang" occurs at least 2 times</code>. The source 
			<term>AllMatches</term> of the <term>FTWords</term>
            selection <code>"Mustang"</code> is given below.</p>
            
            <graphic xmlns:xlink="http://www.w3.org/1999/xlink" source="images/FTTimesEx1.jpg" alt="FTTimes input AllMatches" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
                     
            <p>The result consists of the pairs of the <term>Match</term>es.</p>
            
            <graphic xmlns:xlink="http://www.w3.org/1999/xlink" source="images/FTTimesEx2.jpg" alt="FTTimes result AllMatches" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
                     
        </div4>
    </div3>

    
    
    
    <!-- *************************************************************
         ***                  Match Options Semantics              ***
         ************************************************************* -->
    <div3 role="xquery" id="FTMatchOptionsSec">
        <head>Match Options Semantics</head>
        <div4 role="xquery" id="tq-ft-matchopt-types">
            <head>Types</head>
            <p>XQuery 1.0 functions are used to 
            define the semantics of <term>FTMatchOption</term>s. These functions 
            operate on an XML representation of the <term>FTMatchOption</term>s. 
            The representation closely follows the 
            <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftmatchoptions" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">syntax</loc>. Each <term>FTMatchOption</term> is 
	    represented by an XML element. Additional characteristics of the match 
	    option are represented as attributes.
	    The schema is given below.</p>

<!-- file: MatchOptions.xsd -->            
            <eg xml:space="preserve">
&lt;xs:schema 
    xmlns:xs="http://www.w3.org/2001/XMLSchema" 
    xmlns:fts="http://www.w3.org/2006/xquery-full-text"
    targetNamespace="http://www.w3.org/2006/xquery-full-text"
    elementFormDefault="qualified" 
    attributeFormDefault="unqualified"&gt;

  &lt;xs:complexType name="FTMatchOptions"&gt;
    &lt;xs:sequence minOccurs="0" maxOccurs="unbounded"&gt;
       &lt;xs:element ref="fts:matchOption"/&gt;
    &lt;/xs:sequence&gt;
  &lt;/xs:complexType&gt;

  &lt;xs:element name="matchOptions" type="fts:FTMatchOptions"/&gt;

  &lt;xs:element name="matchOption" abstract="true" type="fts:FTMatchOption"/&gt;

  &lt;xs:complexType name="FTMatchOption"&gt;
  &lt;/xs:complexType&gt;
 
  &lt;xs:element name="case" substitutionGroup="fts:matchOption"
              type="fts:FTCaseOption" /&gt;
  &lt;xs:element name="diacritics" substitutionGroup="fts:matchOption"
              type="fts:FTDiacriticsOption" /&gt;
  &lt;xs:element name="thesaurus" substitutionGroup="fts:matchOption"
              type="fts:FTThesaurusOption" /&gt;
  &lt;xs:element name="stem" substitutionGroup="fts:matchOption"
                type="fts:FTStemOption" /&gt;
  &lt;xs:element name="wildcard" substitutionGroup="fts:matchOption"
              type="fts:FTWildCardOption" /&gt;
  &lt;xs:element name="language" substitutionGroup="fts:matchOption"
              type="fts:FTLanguageOption" /&gt;
  &lt;xs:element name="stopWord" substitutionGroup="fts:matchOption"
              type="fts:FTStopwordOption" /&gt; 

 &lt;xs:complexType name="FTCaseOption"&gt;
   &lt;xs:complexContent&gt;
     &lt;xs:extension base="fts:FTMatchOption"&gt;
       &lt;xs:attribute name="caseIndicator"&gt;
          &lt;xs:simpleType&gt;
            &lt;xs:restriction base="xs:string"&gt;
              &lt;xs:enumeration value="insensitive"/&gt;
              &lt;xs:enumeration value="sensitive"/&gt;
              &lt;xs:enumeration value="lowercase"/&gt;
              &lt;xs:enumeration value="uppercase"/&gt;
            &lt;/xs:restriction&gt;
          &lt;/xs:simpleType&gt;
        &lt;/xs:attribute&gt;
        &lt;xs:attribute name="language" type="xs:string"/&gt;
     &lt;/xs:extension&gt;
   &lt;/xs:complexContent&gt;
  &lt;/xs:complexType&gt;

  &lt;xs:complexType name="FTDiacriticsOption"&gt;
   &lt;xs:complexContent&gt;
     &lt;xs:extension base="fts:FTMatchOption"&gt;
        &lt;xs:attribute name="diacriticsIndicator"&gt;
          &lt;xs:simpleType&gt;
            &lt;xs:restriction base="xs:string"&gt;
              &lt;xs:enumeration value="insensitive"/&gt;
              &lt;xs:enumeration value="sensitive"/&gt;
              &lt;xs:enumeration value="with"/&gt;
              &lt;xs:enumeration value="without"/&gt;
            &lt;/xs:restriction&gt;
          &lt;/xs:simpleType&gt;
        &lt;/xs:attribute&gt;
        &lt;xs:attribute name="language" type="xs:string"/&gt;
      &lt;/xs:extension&gt;
    &lt;/xs:complexContent&gt;
  &lt;/xs:complexType&gt;
           
  &lt;xs:complexType name="FTThesaurusOption"&gt;
   &lt;xs:complexContent&gt;
     &lt;xs:extension base="fts:FTMatchOption"&gt;
        &lt;xs:sequence&gt;
          &lt;xs:element name="thesaurusName" type="xs:string" 
                      minOccurs="0" maxOccurs="1"/&gt;
          &lt;xs:element name="relationship" type="xs:string" 
                      minOccurs="0" maxOccurs="1"/&gt;
          &lt;xs:element name="range" type="fts:FTRangeSpec" 
                      minOccurs="0" maxOccurs="1"/&gt;
        &lt;/xs:sequence&gt;
        &lt;xs:attribute name="thesaurusIndicator"&gt;
          &lt;xs:simpleType&gt;
            &lt;xs:restriction base="xs:string"&gt;
              &lt;xs:enumeration value="with"/&gt;
              &lt;xs:enumeration value="without"/&gt;
            &lt;/xs:restriction&gt;
          &lt;/xs:simpleType&gt;
        &lt;/xs:attribute&gt;
        &lt;xs:attribute name="language" type="xs:string"/&gt;
     &lt;/xs:extension&gt;
   &lt;/xs:complexContent&gt;
  &lt;/xs:complexType&gt;
 
  &lt;xs:complexType name="FTRangeSpec"&gt;
    &lt;xs:attribute name="type" 
                  type="fts:RangeSpecType" 
                  use="required"/&gt;
    &lt;xs:attribute name="m" 
                  type="xs:integer"/&gt;
    &lt;xs:attribute name="n" 
                  type="xs:integer" 
                  use="required"/&gt;
  &lt;/xs:complexType&gt;
  
  &lt;xs:simpleType name="RangeSpecType"&gt;
    &lt;xs:restriction base="xs:string"&gt;
      &lt;xs:enumeration value="exactly"/&gt;
      &lt;xs:enumeration value="at least"/&gt;
      &lt;xs:enumeration value="at most"/&gt;
      &lt;xs:enumeration value="from to"/&gt;
    &lt;/xs:restriction&gt;
  &lt;/xs:simpleType&gt;
  
  &lt;xs:complexType name="FTStemOption"&gt;
   &lt;xs:complexContent&gt;
     &lt;xs:extension base="fts:FTMatchOption"&gt;
        &lt;xs:attribute name="stemIndicator"&gt;
          &lt;xs:simpleType&gt;
            &lt;xs:restriction base="xs:string"&gt;
              &lt;xs:enumeration value="with"/&gt;
              &lt;xs:enumeration value="without"/&gt;
            &lt;/xs:restriction&gt;
          &lt;/xs:simpleType&gt;
        &lt;/xs:attribute&gt;
        &lt;xs:attribute name="language" type="xs:string"/&gt;
     &lt;/xs:extension&gt;
   &lt;/xs:complexContent&gt;
  &lt;/xs:complexType&gt;
 
  &lt;xs:complexType name="FTWildCardOption"&gt;
   &lt;xs:complexContent&gt;
     &lt;xs:extension base="fts:FTMatchOption"&gt;
        &lt;xs:attribute name="wildcardIndicator"&gt;
          &lt;xs:simpleType&gt;
            &lt;xs:restriction base="xs:string"&gt;
              &lt;xs:enumeration value="with"/&gt;
              &lt;xs:enumeration value="without"/&gt;
            &lt;/xs:restriction&gt;
          &lt;/xs:simpleType&gt;
        &lt;/xs:attribute&gt;
        &lt;xs:attribute name="language" type="xs:string"/&gt;
     &lt;/xs:extension&gt;
   &lt;/xs:complexContent&gt;
  &lt;/xs:complexType&gt;
 
  &lt;xs:complexType name="FTLanguageOption"&gt;
   &lt;xs:complexContent&gt;
     &lt;xs:extension base="fts:FTMatchOption"&gt;
        &lt;xs:attribute name="languageName" type="xs:string"/&gt;
     &lt;/xs:extension&gt;
   &lt;/xs:complexContent&gt;
  &lt;/xs:complexType&gt;

  &lt;xs:complexType name="FTStopwordOption"&gt;
   &lt;xs:complexContent&gt;
     &lt;xs:extension base="fts:FTMatchOption"&gt;
        &lt;xs:sequence&gt;
          &lt;xs:choice&gt;
            &lt;xs:element name="default-stopwords"&gt;
                &lt;xs:complexType /&gt;
            &lt;/xs:element&gt;
            &lt;xs:element name="stop-word" type="xs:string" /&gt;
            &lt;xs:element name="uri" type="xs:anyURI" /&gt;
          &lt;/xs:choice&gt;
          &lt;xs:element name="oper" minOccurs="0" maxOccurs="unbounded"&gt;
            &lt;xs:complexType&gt;
              &lt;xs:choice&gt;
                &lt;xs:element name="stop-word" type="xs:string" /&gt;
                &lt;xs:element name="uri" type="xs:anyURI" /&gt;
              &lt;/xs:choice&gt;
              &lt;xs:attribute name="type"&gt;
                &lt;xs:simpleType&gt;
                  &lt;xs:restriction base="xs:string"&gt;
                    &lt;xs:enumeration value="union"/&gt;
                    &lt;xs:enumeration value="except"/&gt;
                  &lt;/xs:restriction&gt;
                &lt;/xs:simpleType&gt;
              &lt;/xs:attribute&gt;
            &lt;/xs:complexType&gt;
          &lt;/xs:element&gt;
        &lt;/xs:sequence&gt;
      &lt;/xs:extension&gt;
    &lt;/xs:complexContent&gt;
  &lt;/xs:complexType&gt;
 
&lt;/xs:schema&gt;            
</eg>

        </div4>
        
        <div4 role="xquery" id="tq-ft-matchopt-highlevel">
            <head>High-Level Semantics</head>
            
            <p>The previous section described FTSelections without
            giving any details about how <term>FTMatchOption</term>s need to be
            interpreted. All processing of <term>FTMatchOption</term>s was
            delegated to the function
            <function>matchTokenInfos</function>, which is
            implementation-defined. In this section, further details
            on the semantics of <term>FTMatchOption</term>s are given.</p> 
            
            <p>The extension is achieved by modifying an existing 
            function and adding functions that are specific to the
            <term>FTMatchOption</term>s.</p>
            
			<p><emph>Modifications in the semantics of existing functions</emph></p>
			
            <p>The semantics of most of the
            <term>FTSelection</term>s remains unmodified. The modifications are
            to the method for matching a sequence of search tokens. </p>


<!-- file: fts.xqy -->            
    <eg role="parse-text" xml:space="preserve">
declare function fts:applySearchTokensAsPhrase (
      $searchContext as item(),
      $matchOptions as element(fts:matchOptions),
      $searchTokens as element(fts:searchToken)*,
      $queryPos as xs:integer )
   as element(fts:allMatches)
{
   let $thesaurusOption := $matchOptions/fts:thesaurus[1]
   return 
      if ($thesaurusOption and $thesaurusOption/@type eq "with") then
         let $noThesaurusOptions := 
            &lt;fts:matchOptions&gt;{
               $matchOptions/*[fn:not(self::fts:thesaurus)]
            }&lt;/fts:matchOptions&gt;
         let $lookupRes := fts:applyThesaurusOption($thesaurusOption,
                                                    $searchTokens)            
         return fts:ApplyFTWordsAny($searchContext,
                                    $noThesaurusOption,
                                    $lookupRes,
                                    $queryPos)
      else
         (: from here on we have a single sequence of search tokens :)
         (: which is to be matched a phrase; no alternatives anymore :)
         &lt;fts:allMatches stokenNum="{$queryPos}"&gt; 
         {
            for $pos in
               fts:matchTokenInfos( 
                  $searchContext,
                  fts:reduceMatchOptions($matchOptions),
                  fts:applyStopwordOption($matchOptions/fts:stopWord),
                  $searchTokens )
            return  
               &lt;fts:match&gt;  
                  &lt;fts:stringInclude queryPos="{$queryPos}"&gt; 
                  {$pos}
                  &lt;/fts:stringInclude&gt; 
               &lt;/fts:match&gt;
         } 
         &lt;/fts:allMatches&gt; 
};
</eg>

	<p>Two <term>FTMatchOption</term>s need to be
    processed differently than the rest of the <term>FTMatchOption</term>s as
    shown in the function above. </p>
	
<ulist>

    <item><p>Differently from all other <term>FTMatchOption</term>s the semantics
    of the <term>FTThesaurusOption</term> cannot be formulated as an operation on
    individual search tokens, because a thesaurus lookup may return
    alternative search items for a whole phrase, i.e., a sequence of
    search tokens. Since
    the result of a thesaurus lookup is a sequence of alternatives, 
    there must be a higher level of processing. The above call to
    <function>applyThesaurusOption&gt;</function> returns for the given
    sequence of search tokens (representing a phrase) all thesaurus
    expansions for the selected thesaurus, relationship and level
    range as a sequence of search items. The 
    alternative expansions are evaluated as a disjunction using
    the <code>fts:ApplyFTWordsAny</code>.
    The matching of the alternatives is performed with
    <term>FTThesaurusOption</term> turned off to avoid double expansions,
    i.e., expansion of an already expanded token.</p></item>
    
    <item><p>For the semantics of the <term>FTStopWordOption</term> the list of
    stop words needs to be computed as demanded by the special syntax
    for stop word lists involving the operators "union" and
    "except". </p></item> 
	
	</ulist>
	<p><emph>Semantics of new <term>FTMatchOption</term>s functions </emph></p>
	
    <p>The expansion of <term>FTSelection</term>s also includes adding additional functions
    that are specific to the <term>FTMatchOption</term>s. </p>
    
    <p>The above function
    <function>applySearchTokensAsPhrase</function> exhibits a call to the function
    <function>reduceMatchOptions</function>, which is defined here.</p>

<!-- file: fts.xqy -->            
    <eg role="parse-text" xml:space="preserve">
declare function fts:reduceMatchOptions (
      $matchOptions as element(fts:matchOptions) )
   as element(fts:matchOptions)
{
   &lt;fts:matchOptions&gt;
   {
      let $new-match-options := 
         $matchOptions/(fts:stopWord|
                        fts:case|
                        fts:diacritics|
                        fts:stem|
                        fts:language|
                        fts:wildcard)
      for $match-option at $index in $new-match-options
      where 
         fn:not(
            some $other in $new-match-options[fn:position() lt $index]
            satisfies fn:node-name($other) = fn:node-name($match-option)
         )
      return $match-option
   }
   &lt;/fts:matchOptions&gt;
};

</eg>

	
    <p>This function determines how match
    options of the same kind overwrite each other, so that only one
    option of the same kind remains.</p>

    <p>The details of the semantics of the remaining <term>FTMatchOption</term>s
    are determined by the implementation-defined function
    <function>matchTokenInfos</function>.</p>
	
    
        </div4>
        
        
        <div4 role="xquery" id="options-sem-functions">
            <head>Formal Semantics Functions</head>
            
            <p><term>FTMatchOption</term> functions which are necessary to support match
            option processing are given below.</p>
			
<!-- file: fts.xqy -->            
    <eg role="parse-text" xml:space="preserve">
declare function fts:resolveStopwordsUri ( $uri as xs:string? ) 
   as xs:string* external;

declare function fts:lookupThesaurus (
      $tokens as element(fts:searchToken)*,
      $thesaurusName as xs:string?, 
      $thesaurusLanguage as xs:string?,
      $relationship as xs:string?,
      $range as element(fts:range)? ) 
   as element(fts:searchItem)* external;
</eg>

            <p>The function <function>resolveStopwordsUri</function>
            is used to resolve any URI to a sequence of strings to be
            used as stop words.</p>

            <p>The function <function>lookupThesaurus</function> finds
            all expansions related to  <code>$tokens</code>
            in the thesaurus <code>$thesaurusName</code> for the language
            <code>$thesaurusLanguage</code> using the relationship 
            <code>$relationship</code> within the optional number of levels
            <code>$range</code>. If <code>$tokens</code> consists of 
            more than one search token, it is regarded as a
            phrase.
            </p>
            
           <p>The thesaurus function returns a sequence of expansion
           alternatives. Each alternative is regarded as a new search
           phrase and is represented as a search item.
           Alternatives are treated as though they are connected with
           a disjunction (<term>FTOr</term>). </p>
          
        </div4>
        
        <div4 role="xquery" id="tq-ft-matchopt-FTCaseOption">
            <head>FTCaseOption</head>
			
        <p><term>FTMatchOption</term>s of type <term>FTCaseOption</term> are passed in the
        <code>$matchOptions</code> parameter to
        <function>matchTokenInfos</function>. If the <term>FTCaseOption</term> is
        "lowercase" ["uppercase"] the returned <term>TokenInfo</term>s must span
        only tokens that are all lowercase [uppercase] If the
        <term>FTCaseOption</term> is "case insensitive" ["case sensitive"] the
        function must return all <term>TokenInfo</term>s matching the search
        tokens when disregarding character case [that also accord with
        the search tokens in character case].</p>
			
        </div4>
        
        <div4 role="xquery" id="tq-ft-matchopt-FTDiacriticsOption">
            <head>FTDiacriticsOption</head>
			
        <p><term>FTMatchOption</term>s of type <term>FTDiacriticsOption</term> are passed in the
        <code>$matchOptions</code> parameter to
        <function>matchTokenInfos</function>. If the <term>FTDiacriticsOption</term> is
        "with diacritics" ["without diacritics"] the returned <term>TokenInfo</term>s must span
        only tokens that have at least one character containing some
        diacritical mark [don't have any character containing a
        diacritical mark] as defined by Unicode. If the
        <term>FTDiacriticsOption</term> is "diacritics insensitive" ["diacritics
        sensitive"] the function must return all <term>TokenInfo</term>s matching
        the search tokens when disregarding diacritical marks [that
        also accord with the search tokens in diacritical marks].</p>
        
        </div4>        
        
        <div4 role="xquery" id="tq-ft-matchopt-FTStemOption">
            <head>FTStemOption</head>
			
        <p><term>FTMatchOption</term>s of type <term>FTStemOption</term> are passed in the
        <code>$matchOptions</code> parameter to
        <function>matchTokenInfos</function>. It is
        implementation-defined what the effect of the option "with
        stemming" is on matching tokens, however, it is expected that
        this option allows to match linguistic variants of the search
        tokens. If the <term>FTStemOption</term> is "without stemming" the
        returned <term>TokenInfo</term>s must span exact matches (i.e. not
        including linguistic variations) of the search tokens.</p>
        
        </div4>

        <div4 role="xquery" id="tq-ft-matchopt-FTThesaurusOption">
            <head>FTThesaurusOption</head>
			
			<p>The semantics for the <term>FTThesaurusOption</term>
			is given below.</p>
            
<!-- file: fts.xqy -->            
    <eg role="parse-text" xml:space="preserve">
declare function fts:applyThesaurusOption (
      $matchOption as element(fts:matchOption),
      $searchTokens as element(fts:searchToken)* )
   as element(xs:searchItem)*
{
   if ($matchOption/@thesaurusIndicator = "with") then
      fts:lookupThesaurus( $searchTokens,
                           $matchOption/fts:thesaurusName,
                           $matchOption/@language,
                           $matchOption/fts:relationship,
                           $matchOption/fts:range )
   else if ($matchOption/@thesaurus = "without") then
      &lt;fts:searchItem&gt;
      {$searchTokens}
      &lt;/fts:searchItem&gt;
   else ()
};
</eg>

        </div4>

        <div4 role="xquery" id="tq-ft-matchopt-FTStopWordOption">
            <head>FTStopWordOption</head>
			
			<p>Stop words interact with <term>FTDistance</term> and
			<term>FTWindow</term>. The semantics for the <term>FTStopWordOption</term>
			is given below.</p>
            
<!-- file: fts.xqy -->            
    <eg role="parse-text" xml:space="preserve">
declare function fts:applyStopwordOption (
      $stopwordOption as element(fts:stopWord)? )
   as xs:string*
{
   if ($stopwordOption) then
      let $swords := 
         typeswitch ($stopwordOption/*[1])
            case $e as element(fts:stop-word) 
               return $e/text()
            case $e as element(fts:uri) 
               return fts:resolveStopwordsUri($e/text())
            case element(fts:default-stopwords)
               return fts:resolveStopwordsUri(())
            default return ()
      return calcStopwords( $swords, $stopwordOption/fts:oper )
   else ()
};
declare function fts:calcStopwords ( 
      $stopWords as xs:string*,
      $opers as element(fts:oper)* )
   as element(fts:searchToken)*
{
   if ( fn:empty($opers) ) then $stopWords
   else
      let $swords := 
         typeswitch ($opers[1]/*[1])
            case $e as element(fts:stop-word) 
               return $e/text()
            case $e as element(fts:uri) 
               return fts:resolveStopwordsUri($e/text())
            default return ()
      return
         if ($opers[1]/@type eq "union") then
            fts:calcStopwords( ($stopWords, $swords), 
                               $opers[fn:position() gt 2] )
         else (: "except" :)
            fts:calcStopwords( $stopWords[fn:not(.)=$swords],
                               $opers[fn:position() gt 2] )
    else $stopWords
};
            </eg>
            <p>The stop words set is computed using the
            <code>fts:calcStopwords</code> function. The function uses
            the function <code>fts:resolveStopwordsUri</code> to resolve any URI
            to a sequence of strings. Then, the stop words are
            removed from the set of search tokens. </p>
        </div4>

        <div4 role="xquery" id="tq-ft-matchopt-FTLanguageOption">
            <head>FTLanguageOption</head>
			
		<p>The <term>FTLanguageOption</term> is not associated with a semantics function. It 
                is just a parameter to other semantics functions.</p>
        
        </div4>

        <div4 role="xquery" id="tq-ft-matchopt-FTWildCardOption">
            <head>FTWildCardOption</head>
			
        <p><term>FTMatchOption</term>s of type <term>FTWildCardOption</term> are passed in the
        <code>$matchOptions</code> parameter to
        <function>matchTokenInfos</function>. If the
        <term>FTWildCardOption</term> is "with wildcards" the function must
        return all <term>TokenInfo</term>s in the search context that span token
        occurrences, such that those token occurrences are wildcard
        expansions of the corresponding search token. The wildcard
        expansions are described in <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftwildcardoption" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">Section 3.2.7 FTWildCardOption</loc>. If the
        <term>FTWildCardOption</term> is "without wildcards" all search tokens
        must be matched literally.</p>
        </div4>
        
       </div3>
    </div2>
    
    
    <div2 role="xquery" id="FullTextExprSec">
    <head>XQuery 1.0 and XPath 2.0 Full-Text and Scoring Expressions</head>
    
    
    <!-- *************************************************************
         ***                     FTContains                    ***
         ************************************************************* -->
    <div3 role="xquery" id="FTContainsSec">
        <head>FTContainsExpr</head>
        
        <p>The <function>FTContainsExpr</function> function defines the semantics 
		of <term>FTContainsExpr</term>. The function takes the following parameters: 1) a
        search context consisting of a sequence of nodes (which is the result of
        a XQuery 1.0 and XPath 2.0 expression) and 2) an <term>AllMatches</term> corresponding
        to an <term>FTSelection</term>. The function returns a <code>xs:boolean</code> 
		atomic value. This value is <code>true</code> if and only if some node
		in the search contains satisifes the full-text condition given by the
		<term>FTSelection</term>. Since
        <term>FTContainsExpr</term> returns results in XDM (a sequence of
        items), it may be treated like XQuery 1.0 expressions and may be
        fully composed with other XQuery 1.0 expressions. In addition, since the
        <function>FTContainsExpr</function> function maps <term>AllMatches</term> to a 
		sequence of items, it provides
        semantics for mapping from <term>AllMatches</term> to XDM.</p>
        
        
        <!-- **********************************************************************
             *                    Semantics of FTContainsExpr                     *
             ********************************************************************** -->
        <div4 id="tq-ft-FTContainsExpr">
            <head>Semantics of FTContainsExpr</head>
                        
            <p>Consider an <term>FTContainsExpr</term> expression of the form
            <code>EvaluationContext ftcontains FTSelection</code>,
            where <code>EvaluationContext</code> is an XQuery 1.0
            expression that returns a sequence of nodes and
            <code>FTSelection</code> is an <term>FTSelection</term> that returns
            <term>AllMatches</term>. The <term>FTContainsExpr</term> returns
            true if and only if some node in the result of
            <code>EvaluationContext</code> satisfies the <term>AllMatches</term>
            returned by <code>FTSelection</code>.</p>
	    
	    <p>If the <term>FTContainsExpr</term> is of the form <code>EvaluationContext 
	    ftcontains FTSelection without content IgnoreExpr</code> for
	    some XQuery 1.0 expression <code>IgnoreExpr</code>, then
	    the following helper function is required. </p>

<!-- file: fts.xqy -->            
            <eg role="parse-text" xml:space="preserve">
declare function fts:reconstruct (
      $n as item(), 
      $ignore as node()* ) 
   as item()? 
{
   typeswitch ($n)
     case node() return
        if (some $i in $ignore satisfies $n is $i) then () 
        else if ($n instance of element()) then
           let $nodeName := fn:node-name($n)
           let $nodeContent := for $nn in $n/node()
                               return fts:reconstruct($nn,$ignore)
           return element {$nodeName} {$nodeContent}
        else $n
     default return $n
};
            </eg>
	    
            <p>In the general case, the XQuery 1.0 and XPath 2.0 <function>FTContainsExpr</function>
			function takes four parameters. </p>
			
			<olist>
			
			<item><p>The sequence of items returned by
            <code>EvalationContext</code>;</p></item>
			
			<item><p>The XML node representation of <code>FTSelection</code>;</p></item>
			
			<item><p>The sequence of nodes returned by
            <code>IgnoreExpr</code>, if that expression is present, or
            the empty sequence otherwise; and</p></item>
			
			
			<item><p>The XML representation of the set of default values for each of the
            <term>FTMatchOption</term>s as given by the static context.</p></item> 
			
			</olist>
			
			<p>The <function>FTContainsExpr</function> function returns true if
			and only if the corresponding <term>FTContainsExpr</term> returns true, and
			thus specifies the semantics of <term>FTContainsExpr</term>. Note that by using
			XQuery 1.0 and XPath 2.0 to specify the formal semantics, we avoid
			the need to introduce new formalism. We simply reuse the formal
			semantics of XQuery 1.0 and XPath 2.0.</p>
            
<!-- file: fts.xqy -->            
            <eg role="parse-text" xml:space="preserve">
declare function fts:FTContainsExpr (
      $searchContext as item()*,
      $ftSelection as element(*,fts:FTSelection),
      $ignoreNodes as node()*,
      $defOptions as element(fts:matchOptions) )
   as xs:boolean 
{ 
   some $node in $searchContext
   satisfies 
      let $newNode := fts:reconstruct( $node, $ignoreNodes )
      return
         if (fn:empty($newNode)) then fn:false()
         else
            let $allMatches := fts:evaluate($ftSelection,
                                            $newNode,
                                            $defOptions,
                                            0)
            return 
               some $match in $allMatches/fts:match
               satisfies 
                  fn:count($match/fts:stringExclude) eq 0
};
            </eg>
            
            <p>The <function>FTContainsExpr</function> function returns true if and only if the
            <term>AllMatches</term> that is the result of the application of the
            <term>FTSelection</term> for some node in the search context contains a
            <term>Match</term> with no <term>StringExclude</term>s. In other words, there is a set of
            <term>TokenInfo</term>s in that node which satisfy the condition of the
            <term>FTSelection</term>. If an FTIgnoreOption has been specified in
            the <term>FTContainsExpr</term>, then each node
            <code>$ignoreNodes</code> that is part of the tree of a node
            in the search context is pruned from that tree using the function
            <function>reconstruct</function> before that node is being passed to
            <function>fts:evaluate</function>.</p>
            
        </div4>
    
    </div3>
    


    <!-- **********************************************************
         ***                     Scoring                    ***
         *********************************************************** -->
        <div3 role="xquery" id="ScoreSec">
            <head>Scoring</head>
            
            <p>This section addresses the semantics of 
               scoring variables in XQuery 1.0 <code>for</code> and
               <code>let</code> clauses and XPath 2.0 <code>for</code>
               expressions.</p>
			   
			 <p>Scoring variables associate a numeric score with the result of the evaluation
			 of XQuery 1.0 and XPath 2.0 expressions. This numeric score
			 tries to estimate the value of a result item to the user
			 information need expressed using the XQuery 1.0 and XPath 2.0 
			 expression. The numeric score is computed using a implementation-provided 
			 <emph>scoring algorithm</emph>.</p>
			 
			 <p>There are numerous scoring algorithms used in practice. Most of
			 the scoring algorithms take as inputs a query and a set of results
			 to the query. In computing the score, these algorithms rely on the
			 structure of the query to estimate the relevance of the results. 
			 </p>
			 
			 <p>In the context of defining the semantics of XQuery 1.0 and XPath
			 2.0 Full-Text, passing the structure of the query poses a problem.
			 The query is an XQuery 1.0 and XPath 2.0 expression and an 
			 XQuery 1.0 and XPath 2.0 Full-text expression in particular. The 
			 semantics of XQuery 1.0 and XPath 2.0 expressions is
			 expressed using functions take as arguments sequences of items and
			 return sequences of items. They are not aware of what
			 expression produced a particular sequence, i.e., they are not
			 aware of the expression structure.</p>
			 
			 <p>To define the semantics of scoring in XQuery 1.0 and XPath 2.0
			 Full-Text using XQuery 1.0, expressions that produce
			 the query result (or the functions that implement the expressions)
			 must be passed as arguments. In other words, second-order functions
			 are necessary. Current XQuery 1.0 and XPath 2.0 do
			 not provide such functions. </p>
			 
             
            <p>Nevertheless, in the interest of the exposition, assume 
               that such second-order functions are present. In particular, that 
               there are two semantic second-order function
               <code>fts:score</code> and <code>fts:scoreSequence</code>
               that take one argument (an expression) and return the
               score value of this expression, respectively a sequence
               of score values, one for each item to which the expression
               evaluates. The scores must satisfy <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#section-score-variables" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">scoring properties</loc>.</p>
            <p>A <code>for</code> clause containing a score variable
<eg xml:space="preserve">
for $result score $score in Expr
...
</eg>
               is evaluated as
               though it is replaced by the following  the set of clauses.
               
<eg xml:space="preserve">
let $scoreSeq := fts:scoreSequence(Expr)
for $result at $i in Expr
let $score := $scoreSeq[$i]
...
</eg>
               Here, <code>$scoreSeq</code> and <code>$i</code> are
               new variables, not appearing elsewhere, and
               <code>fts:scoreSequence</code> is the 
               second-order function.
            </p>
            <p>Similarly, a <code>let</code> clause containing a score variable
<eg xml:space="preserve">
let $result score $score := Expr
...
</eg>
               is evaluated as
               though it is replaced by the following set of clauses.
<eg xml:space="preserve">
let $result := Expr
let $score := fts:score(Expr)
...
</eg>	
            </p>
        </div3>

    <!-- ***************************************************
         ***                    Example                  ***
         *************************************************** -->
        <div3 role="xquery" id="tq-ft-FTContainsExpr-example">
            <head>Example</head>
            
            <p>This section presents a more complex example for the evaluation of <term>FTContainsExpr</term>. This example uses the same 
			sample document fragment and assigns it <code>$doc</code>. 
            Consider the following <term>FTContainsExpr</term>.</p>
            
            <eg role="parse-text" xml:space="preserve">
    $doc ftcontains (
      (
       "mustang" &amp;&amp; ({("great", "excellent")} any word
       occurs at least 2 times)
      ) window 30 words
      &amp;&amp;
      ! "rust"
    ) same paragraph
</eg>
                
            <p>Begin by evaluating the <term>FTSelection</term> to <term>AllMatches</term>.</p>
            
            <eg role="parse-text" xml:space="preserve">
    (
      (
       "mustang" &amp;&amp; ({("great", "excellent")} any word
       occurs at least 2 times)
      ) window 30 words
      &amp;&amp;
      ! "rust"
    ) same paragraph
</eg>
                
            <p>Step 1: Evaluate the <term>FTWords</term>
                <code>"mustang"</code>.
            </p>
            <graphic xmlns:xlink="http://www.w3.org/1999/xlink" source="images/CompleteExample01.jpg" alt="Example, step 1" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
            <p>Step 2: Evaluate the <term>FTWords</term>
                <code>{"great", "excellent"} any word</code>.
            </p>
			<p>Step 2.1: Match the token "great"</p>
            <graphic xmlns:xlink="http://www.w3.org/1999/xlink" source="images/CompleteExample02.jpg" alt="Example, step 2" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
			<p>Step 2.2 Match the token "excellent"</p>
            <graphic xmlns:xlink="http://www.w3.org/1999/xlink" source="images/CompleteExample03.jpg" alt="Example, step 3" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
            <p>Step 2.3 - Combine the above <term>AllMatches</term> as if <term>FTOr</term> is used, i.e., by
                forming  a union of the <term>Match</term>es.</p>
            <graphic xmlns:xlink="http://www.w3.org/1999/xlink" source="images/CompleteExample04.jpg" alt="Example, step 4" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
            <p>Step 3 - Apply the <term>FTTimes</term>
                <code>{("great", "excellent")} any word occurs at least 2 times</code>
				forming two pairs of <term>Match</term>es.</p>
            <graphic xmlns:xlink="http://www.w3.org/1999/xlink" source="images/CompleteExample05_1.jpg" alt="Example, step 5.1" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
            <p><emph>Continued on next diagram</emph></p>
            <graphic xmlns:xlink="http://www.w3.org/1999/xlink" source="images/CompleteExample05_1_2.jpg" alt="Example, step 5.1" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
            <p><emph>Continued on next diagram</emph></p>
            <graphic xmlns:xlink="http://www.w3.org/1999/xlink" source="images/CompleteExample05_2.jpg" alt="Example, step 5.2" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
            <p>Step 4 - Apply the <term>FTAnd</term>
                <code>"Mustang" 
                &amp;&amp; ({("great", "excellent")} any word occurs at least 2 
                times)</code> forming all possible pairs of <term>StringMatch</term>es.</p>
            <graphic xmlns:xlink="http://www.w3.org/1999/xlink" source="images/CompleteExample06_1.jpg" alt="Example, step 6.1" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
            <p><emph>Continued on next diagram</emph></p>
            <graphic xmlns:xlink="http://www.w3.org/1999/xlink" source="images/CompleteExample06_1_2.jpg" alt="Example, step 6.1" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
            <p><emph>Continued on next diagram</emph></p>
            <graphic xmlns:xlink="http://www.w3.org/1999/xlink" source="images/CompleteExample06_2.jpg" alt="Example, step 6.2" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
            <p><emph>Continued on next diagram</emph></p>
            <graphic xmlns:xlink="http://www.w3.org/1999/xlink" source="images/CompleteExample06_2_2.jpg" alt="Example, step 6.2" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
            <p><emph>Continued on next diagram</emph></p>
            <graphic xmlns:xlink="http://www.w3.org/1999/xlink" source="images/CompleteExample06_3.jpg" alt="Example, step 6.3" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
            <p><emph>Continued on next diagram</emph></p>
            <graphic xmlns:xlink="http://www.w3.org/1999/xlink" source="images/CompleteExample06_3_2.jpg" alt="Example, step 6.3" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
            <p><emph>Continued on next diagram</emph></p>
            <graphic xmlns:xlink="http://www.w3.org/1999/xlink" source="images/CompleteExample06_4.jpg" alt="Example, step 6.4" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
            <p><emph>Continued on next diagram</emph></p>
            <graphic xmlns:xlink="http://www.w3.org/1999/xlink" source="images/CompleteExample06_4_2.jpg" alt="Example, step 6.4" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
            <p><emph>Continued on next diagram</emph></p>
            <graphic xmlns:xlink="http://www.w3.org/1999/xlink" source="images/CompleteExample06_5.jpg" alt="Example, step 6.5" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
            <p><emph>Continued on next diagram</emph></p>
            <graphic xmlns:xlink="http://www.w3.org/1999/xlink" source="images/CompleteExample06_5_2.jpg" alt="Example, step 6.5" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
            <p>Step 5 - Apply the <term>FTWindow</term>
                <code>("Mustang" 
                &amp;&amp; ({("great", "excellent")} any word 
                occurs at least 2 times)) window 30 words</code>, filtering out <term>Match</term>es 
                for which the window is not less than or equal to 30 tokens.</p>
            <graphic xmlns:xlink="http://www.w3.org/1999/xlink" source="images/CompleteExample07_1.jpg" alt="Example, step 7.1" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
            <p><emph>Continued on next diagram</emph></p>
            <graphic xmlns:xlink="http://www.w3.org/1999/xlink" source="images/CompleteExample07_1_2.jpg" alt="Example, step 7.1" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
            <p><emph>Continued on next diagram</emph></p>
            <graphic xmlns:xlink="http://www.w3.org/1999/xlink" source="images/CompleteExample07_2.jpg" alt="Example, step 7.2" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
            <p><emph>Continued on next diagram</emph></p>
            <graphic xmlns:xlink="http://www.w3.org/1999/xlink" source="images/CompleteExample07_2_2.jpg" alt="Example, step 7.2" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
            <p>Step 6 - Evaluate <term>FTWords</term>
                <code>"rust"</code>.
            </p>
            <graphic xmlns:xlink="http://www.w3.org/1999/xlink" source="images/CompleteExample08.jpg" alt="Example, step 8" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
            <p>Step 7 - Apply the <term>FTUnaryNot</term>
                <code>! "rust"</code>, 
                transforming the <code>StringInclude</code> into a 
				<code>StringExclude</code>.
            </p>
            <graphic xmlns:xlink="http://www.w3.org/1999/xlink" source="images/CompleteExample09.jpg" alt="Example, step 9" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
            <p>Step 8 - Apply the <term>FTAnd</term>
                <code>(("Mustang"
                &amp;&amp; ({("great", "excellent")} any word occurs at least 2 times)) 
                window 30 words) &amp;&amp; ! "rust"</code>, forming all
				possible combintations of three <term>StringMatch</term>es from the first
				<term>AllMatches</term> and one <term>StringMatch</term> from the second <term>AllMatches</term>. </p>
            <graphic xmlns:xlink="http://www.w3.org/1999/xlink" source="images/CompleteExample10_1.jpg" alt="Example, step 10.1" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/><p/>
            <p><emph>Continued on next diagram</emph></p>
            <graphic xmlns:xlink="http://www.w3.org/1999/xlink" source="images/CompleteExample10_1_2.jpg" alt="Example, step 10.1" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/><p/>
            <p><emph>Continued on next diagram</emph></p>
            <graphic xmlns:xlink="http://www.w3.org/1999/xlink" source="images/CompleteExample10_2.jpg" alt="Example, step 10.2" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/><p/>
            <p><emph>Continued on next diagram</emph></p>
            <graphic xmlns:xlink="http://www.w3.org/1999/xlink" source="images/CompleteExample10_2_2.jpg" alt="Example, step 10.2" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/><p/>
            <p><emph>Continued on next diagram</emph></p>
            <graphic xmlns:xlink="http://www.w3.org/1999/xlink" source="images/CompleteExample10_3.jpg" alt="Example, step 10.3" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/><p/>
            <p>Step 9: Apply the <term>FTScope</term>,  filtering out <term>
                Match</term>es whose <term>TokenInfo</term>s are not within the same paragraph 
				(assuming the <code>&lt;offer&gt;</code> elements determine
				paragraph boundaries).</p>
            <graphic xmlns:xlink="http://www.w3.org/1999/xlink" source="images/CompleteExample11.jpg" alt="Example, step 11" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
            
            <p>The resulting <term>AllMatches</term> contains a <term>Match</term> 
            that does not contain a <term>StringExclude</term>. Therefore, the
            sample <term>FTContainsExpr</term> returns <code>true</code>.</p>
            
        </div3>


    </div2>
    
</div1>

	</body>
	<back id="id-appendices">
	
<div1 id="id-grammar">
		<head>EBNF for XQuery 1.0 Grammar with Full-Text
		extensions</head>

<p>The EBNF in this document and in this section is aligned with
the current XML Query 1.0 grammar (see <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/TR/2005/CR-xquery-20051103/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">http://www.w3.org/TR/2005/CR-xquery-20051103/</loc>).</p>

		<scrap role="non-terminal-structure-expand" headstyle="show"><head/>
<prod num="1" id="prod-xquery-Module"><lhs>Module</lhs><rhs><nt def="prod-xquery-VersionDecl">VersionDecl</nt>?  (<nt def="prod-xquery-LibraryModule">LibraryModule</nt>  |  <nt def="prod-xquery-MainModule">MainModule</nt>)</rhs></prod><prod num="2" id="prod-xquery-VersionDecl"><lhs>VersionDecl</lhs><rhs>"xquery"  "version"  <nt def="prod-xquery-StringLiteral">StringLiteral</nt>  ("encoding"  <nt def="prod-xquery-StringLiteral">StringLiteral</nt>)?  <nt def="prod-xquery-Separator">Separator</nt></rhs></prod><prod num="3" id="prod-xquery-MainModule"><lhs>MainModule</lhs><rhs><nt def="prod-xquery-Prolog">Prolog</nt>  <nt def="prod-xquery-QueryBody">QueryBody</nt></rhs></prod><prod num="4" id="prod-xquery-LibraryModule"><lhs>LibraryModule</lhs><rhs><nt def="prod-xquery-ModuleDecl">ModuleDecl</nt>  <nt def="prod-xquery-Prolog">Prolog</nt></rhs></prod><prod num="5" id="prod-xquery-ModuleDecl"><lhs>ModuleDecl</lhs><rhs>"module"  "namespace"  <nt def="prod-xquery-NCName">NCName</nt>  "="  <nt def="prod-xquery-URILiteral">URILiteral</nt>  <nt def="prod-xquery-Separator">Separator</nt></rhs></prod><prod num="6" id="prod-xquery-Prolog"><lhs>Prolog</lhs><rhs>((<nt def="prod-xquery-DefaultNamespaceDecl">DefaultNamespaceDecl</nt>  |  <nt def="prod-xquery-Setter">Setter</nt>  |  <nt def="prod-xquery-NamespaceDecl">NamespaceDecl</nt>  |  <nt def="prod-xquery-Import">Import</nt>)  <nt def="prod-xquery-Separator">Separator</nt>)*  ((<nt def="prod-xquery-VarDecl">VarDecl</nt>  |  <nt def="prod-xquery-FunctionDecl">FunctionDecl</nt>  |  <nt def="prod-xquery-OptionDecl">OptionDecl</nt>  |  <nt def="prod-xquery-FTOptionDecl">FTOptionDecl</nt>)  <nt def="prod-xquery-Separator">Separator</nt>)*</rhs></prod><prod num="7" id="prod-xquery-Setter"><lhs>Setter</lhs><rhs><nt def="prod-xquery-BoundarySpaceDecl">BoundarySpaceDecl</nt>  |  <nt def="prod-xquery-DefaultCollationDecl">DefaultCollationDecl</nt>  |  <nt def="prod-xquery-BaseURIDecl">BaseURIDecl</nt>  |  <nt def="prod-xquery-ConstructionDecl">ConstructionDecl</nt>  |  <nt def="prod-xquery-OrderingModeDecl">OrderingModeDecl</nt>  |  <nt def="prod-xquery-EmptyOrderDecl">EmptyOrderDecl</nt>  |  <nt def="prod-xquery-CopyNamespacesDecl">CopyNamespacesDecl</nt></rhs></prod><prod num="8" id="prod-xquery-Import"><lhs>Import</lhs><rhs><nt def="prod-xquery-SchemaImport">SchemaImport</nt>  |  <nt def="prod-xquery-ModuleImport">ModuleImport</nt></rhs></prod><prod num="9" id="prod-xquery-Separator"><lhs>Separator</lhs><rhs>";"</rhs></prod><prod num="10" id="prod-xquery-NamespaceDecl"><lhs>NamespaceDecl</lhs><rhs>"declare"  "namespace"  <nt def="prod-xquery-NCName">NCName</nt>  "="  <nt def="prod-xquery-URILiteral">URILiteral</nt></rhs></prod><prod num="11" id="prod-xquery-BoundarySpaceDecl"><lhs>BoundarySpaceDecl</lhs><rhs>"declare"  "boundary-space"  ("preserve"  |  "strip")</rhs></prod><prod num="12" id="prod-xquery-DefaultNamespaceDecl"><lhs>DefaultNamespaceDecl</lhs><rhs>"declare"  "default"  ("element"  |  "function")  "namespace"  <nt def="prod-xquery-URILiteral">URILiteral</nt></rhs></prod><prod num="13" id="prod-xquery-OptionDecl"><lhs>OptionDecl</lhs><rhs>"declare"  "option"  <nt def="prod-xquery-QName">QName</nt>  <nt def="prod-xquery-StringLiteral">StringLiteral</nt></rhs></prod><prod num="14" id="prod-xquery-FTOptionDecl"><lhs>FTOptionDecl</lhs><rhs>"declare"  "ft-option"  <nt def="prod-xquery-FTMatchOption">FTMatchOption</nt></rhs></prod><prod num="15" id="prod-xquery-OrderingModeDecl"><lhs>OrderingModeDecl</lhs><rhs>"declare"  "ordering"  ("ordered"  |  "unordered")</rhs></prod><prod num="16" id="prod-xquery-EmptyOrderDecl"><lhs>EmptyOrderDecl</lhs><rhs>"declare"  "default"  "order"  "empty"  ("greatest"  |  "least")</rhs></prod><prod num="17" id="prod-xquery-CopyNamespacesDecl"><lhs>CopyNamespacesDecl</lhs><rhs>"declare"  "copy-namespaces"  <nt def="prod-xquery-PreserveMode">PreserveMode</nt>  ","  <nt def="prod-xquery-InheritMode">InheritMode</nt></rhs></prod><prod num="18" id="prod-xquery-PreserveMode"><lhs>PreserveMode</lhs><rhs>"preserve"  |  "no-preserve"</rhs></prod><prod num="19" id="prod-xquery-InheritMode"><lhs>InheritMode</lhs><rhs>"inherit"  |  "no-inherit"</rhs></prod><prod num="20" id="prod-xquery-DefaultCollationDecl"><lhs>DefaultCollationDecl</lhs><rhs>"declare"  "default"  "collation"  <nt def="prod-xquery-URILiteral">URILiteral</nt></rhs></prod><prod num="21" id="prod-xquery-BaseURIDecl"><lhs>BaseURIDecl</lhs><rhs>"declare"  "base-uri"  <nt def="prod-xquery-URILiteral">URILiteral</nt></rhs></prod><prod num="22" id="prod-xquery-SchemaImport"><lhs>SchemaImport</lhs><rhs>"import"  "schema"  <nt def="prod-xquery-SchemaPrefix">SchemaPrefix</nt>?  <nt def="prod-xquery-URILiteral">URILiteral</nt>  ("at"  <nt def="prod-xquery-URILiteral">URILiteral</nt>  (","  <nt def="prod-xquery-URILiteral">URILiteral</nt>)*)?</rhs></prod><prod num="23" id="prod-xquery-SchemaPrefix"><lhs>SchemaPrefix</lhs><rhs>("namespace"  <nt def="prod-xquery-NCName">NCName</nt>  "=")  |  ("default"  "element"  "namespace")</rhs></prod><prod num="24" id="prod-xquery-ModuleImport"><lhs>ModuleImport</lhs><rhs>"import"  "module"  ("namespace"  <nt def="prod-xquery-NCName">NCName</nt>  "=")?  <nt def="prod-xquery-URILiteral">URILiteral</nt>  ("at"  <nt def="prod-xquery-URILiteral">URILiteral</nt>  (","  <nt def="prod-xquery-URILiteral">URILiteral</nt>)*)?</rhs></prod><prod num="25" id="prod-xquery-VarDecl"><lhs>VarDecl</lhs><rhs>"declare"  "variable"  "$"  <nt def="prod-xquery-QName">QName</nt>  <nt def="prod-xquery-TypeDeclaration">TypeDeclaration</nt>?  ((":="  <nt def="prod-xquery-ExprSingle">ExprSingle</nt>)  |  "external")</rhs></prod><prod num="26" id="prod-xquery-ConstructionDecl"><lhs>ConstructionDecl</lhs><rhs>"declare"  "construction"  ("strip"  |  "preserve")</rhs></prod><prod num="27" id="prod-xquery-FunctionDecl"><lhs>FunctionDecl</lhs><rhs>"declare"  "function"  <nt def="prod-xquery-QName">QName</nt>  "("  <nt def="prod-xquery-ParamList">ParamList</nt>?  ")"  ("as"  <nt def="prod-xquery-SequenceType">SequenceType</nt>)?  (<nt def="prod-xquery-EnclosedExpr">EnclosedExpr</nt>  |  "external")</rhs></prod><prod num="28" id="prod-xquery-ParamList"><lhs>ParamList</lhs><rhs><nt def="prod-xquery-Param">Param</nt>  (","  <nt def="prod-xquery-Param">Param</nt>)*</rhs></prod><prod num="29" id="prod-xquery-Param"><lhs>Param</lhs><rhs>"$"  <nt def="prod-xquery-QName">QName</nt>  <nt def="prod-xquery-TypeDeclaration">TypeDeclaration</nt>?</rhs></prod><prod num="30" id="prod-xquery-EnclosedExpr"><lhs>EnclosedExpr</lhs><rhs>"{"  <nt def="prod-xquery-Expr">Expr</nt>  "}"</rhs></prod><prod num="31" id="prod-xquery-QueryBody"><lhs>QueryBody</lhs><rhs><nt def="prod-xquery-Expr">Expr</nt></rhs></prod><prod num="32" id="prod-xquery-Expr"><lhs>Expr</lhs><rhs><nt def="prod-xquery-ExprSingle">ExprSingle</nt>  (","  <nt def="prod-xquery-ExprSingle">ExprSingle</nt>)*</rhs></prod><prod num="33" id="prod-xquery-ExprSingle"><lhs>ExprSingle</lhs><rhs><nt def="prod-xquery-FLWORExpr">FLWORExpr</nt><br/>|  <nt def="prod-xquery-QuantifiedExpr">QuantifiedExpr</nt><br/>|  <nt def="prod-xquery-TypeswitchExpr">TypeswitchExpr</nt><br/>|  <nt def="prod-xquery-IfExpr">IfExpr</nt><br/>|  <nt def="prod-xquery-OrExpr">OrExpr</nt></rhs></prod><prod num="34" id="prod-xquery-FLWORExpr"><lhs>FLWORExpr</lhs><rhs>(<nt def="prod-xquery-ForClause">ForClause</nt>  |  <nt def="prod-xquery-LetClause">LetClause</nt>)+  <nt def="prod-xquery-WhereClause">WhereClause</nt>?  <nt def="prod-xquery-OrderByClause">OrderByClause</nt>?  "return"  <nt def="prod-xquery-ExprSingle">ExprSingle</nt></rhs></prod><prod num="35" id="prod-xquery-ForClause"><lhs>ForClause</lhs><rhs>"for"  "$"  <nt def="prod-xquery-VarName">VarName</nt>  <nt def="prod-xquery-TypeDeclaration">TypeDeclaration</nt>?  <nt def="prod-xquery-PositionalVar">PositionalVar</nt>?  <nt def="prod-xquery-FTScoreVar">FTScoreVar</nt>?  "in"  <nt def="prod-xquery-ExprSingle">ExprSingle</nt>  (","  "$"  <nt def="prod-xquery-VarName">VarName</nt>  <nt def="prod-xquery-TypeDeclaration">TypeDeclaration</nt>?  <nt def="prod-xquery-PositionalVar">PositionalVar</nt>?  <nt def="prod-xquery-FTScoreVar">FTScoreVar</nt>?  "in"  <nt def="prod-xquery-ExprSingle">ExprSingle</nt>)*</rhs></prod><prod num="36" id="prod-xquery-PositionalVar"><lhs>PositionalVar</lhs><rhs>"at"  "$"  <nt def="prod-xquery-VarName">VarName</nt></rhs></prod><prod num="37" id="prod-xquery-FTScoreVar"><lhs>FTScoreVar</lhs><rhs>"score"  "$"  <nt def="prod-xquery-VarName">VarName</nt></rhs></prod><prod num="38" id="prod-xquery-LetClause"><lhs>LetClause</lhs><rhs>(("let"  "$"  <nt def="prod-xquery-VarName">VarName</nt>  <nt def="prod-xquery-TypeDeclaration">TypeDeclaration</nt>?  <nt def="prod-xquery-FTScoreVar">FTScoreVar</nt>?)  |  ("let"  "score"  "$"  <nt def="prod-xquery-VarName">VarName</nt>))  ":="  <nt def="prod-xquery-ExprSingle">ExprSingle</nt>  (","  (("$"  <nt def="prod-xquery-VarName">VarName</nt>  <nt def="prod-xquery-TypeDeclaration">TypeDeclaration</nt>?  <nt def="prod-xquery-FTScoreVar">FTScoreVar</nt>?)  |  <nt def="prod-xquery-FTScoreVar">FTScoreVar</nt>)  ":="  <nt def="prod-xquery-ExprSingle">ExprSingle</nt>)*</rhs></prod><prod num="39" id="prod-xquery-WhereClause"><lhs>WhereClause</lhs><rhs>"where"  <nt def="prod-xquery-ExprSingle">ExprSingle</nt></rhs></prod><prod num="40" id="prod-xquery-OrderByClause"><lhs>OrderByClause</lhs><rhs>(("order"  "by")  |  ("stable"  "order"  "by"))  <nt def="prod-xquery-OrderSpecList">OrderSpecList</nt></rhs></prod><prod num="41" id="prod-xquery-OrderSpecList"><lhs>OrderSpecList</lhs><rhs><nt def="prod-xquery-OrderSpec">OrderSpec</nt>  (","  <nt def="prod-xquery-OrderSpec">OrderSpec</nt>)*</rhs></prod><prod num="42" id="prod-xquery-OrderSpec"><lhs>OrderSpec</lhs><rhs><nt def="prod-xquery-ExprSingle">ExprSingle</nt>  <nt def="prod-xquery-OrderModifier">OrderModifier</nt></rhs></prod><prod num="43" id="prod-xquery-OrderModifier"><lhs>OrderModifier</lhs><rhs>("ascending"  |  "descending")?  ("empty"  ("greatest"  |  "least"))?  ("collation"  <nt def="prod-xquery-URILiteral">URILiteral</nt>)?</rhs></prod><prod num="44" id="prod-xquery-QuantifiedExpr"><lhs>QuantifiedExpr</lhs><rhs>("some"  |  "every")  "$"  <nt def="prod-xquery-VarName">VarName</nt>  <nt def="prod-xquery-TypeDeclaration">TypeDeclaration</nt>?  "in"  <nt def="prod-xquery-ExprSingle">ExprSingle</nt>  (","  "$"  <nt def="prod-xquery-VarName">VarName</nt>  <nt def="prod-xquery-TypeDeclaration">TypeDeclaration</nt>?  "in"  <nt def="prod-xquery-ExprSingle">ExprSingle</nt>)*  "satisfies"  <nt def="prod-xquery-ExprSingle">ExprSingle</nt></rhs></prod><prod num="45" id="prod-xquery-TypeswitchExpr"><lhs>TypeswitchExpr</lhs><rhs>"typeswitch"  "("  <nt def="prod-xquery-Expr">Expr</nt>  ")"  <nt def="prod-xquery-CaseClause">CaseClause</nt>+  "default"  ("$"  <nt def="prod-xquery-VarName">VarName</nt>)?  "return"  <nt def="prod-xquery-ExprSingle">ExprSingle</nt></rhs></prod><prod num="46" id="prod-xquery-CaseClause"><lhs>CaseClause</lhs><rhs>"case"  ("$"  <nt def="prod-xquery-VarName">VarName</nt>  "as")?  <nt def="prod-xquery-SequenceType">SequenceType</nt>  "return"  <nt def="prod-xquery-ExprSingle">ExprSingle</nt></rhs></prod><prod num="47" id="prod-xquery-IfExpr"><lhs>IfExpr</lhs><rhs>"if"  "("  <nt def="prod-xquery-Expr">Expr</nt>  ")"  "then"  <nt def="prod-xquery-ExprSingle">ExprSingle</nt>  "else"  <nt def="prod-xquery-ExprSingle">ExprSingle</nt></rhs></prod><prod num="48" id="prod-xquery-OrExpr"><lhs>OrExpr</lhs><rhs><nt def="prod-xquery-AndExpr">AndExpr</nt> ( "or"  <nt def="prod-xquery-AndExpr">AndExpr</nt> )*</rhs></prod><prod num="49" id="prod-xquery-AndExpr"><lhs>AndExpr</lhs><rhs><nt def="prod-xquery-ComparisonExpr">ComparisonExpr</nt> ( "and"  <nt def="prod-xquery-ComparisonExpr">ComparisonExpr</nt> )*</rhs></prod><prod num="50" id="prod-xquery-ComparisonExpr"><lhs>ComparisonExpr</lhs><rhs><nt def="prod-xquery-FTContainsExpr">FTContainsExpr</nt> ( (<nt def="prod-xquery-ValueComp">ValueComp</nt><br/>|  <nt def="prod-xquery-GeneralComp">GeneralComp</nt><br/>|  <nt def="prod-xquery-NodeComp">NodeComp</nt>)  <nt def="prod-xquery-FTContainsExpr">FTContainsExpr</nt> )?</rhs></prod><prod num="51" id="prod-xquery-FTContainsExpr"><lhs>FTContainsExpr</lhs><rhs><nt def="prod-xquery-RangeExpr">RangeExpr</nt> ( "ftcontains"  <nt def="prod-xquery-FTSelection">FTSelection</nt>  <nt def="prod-xquery-FTIgnoreOption">FTIgnoreOption</nt>? )?</rhs></prod><prod num="52" id="prod-xquery-RangeExpr"><lhs>RangeExpr</lhs><rhs><nt def="prod-xquery-AdditiveExpr">AdditiveExpr</nt> ( "to"  <nt def="prod-xquery-AdditiveExpr">AdditiveExpr</nt> )?</rhs></prod><prod num="53" id="prod-xquery-AdditiveExpr"><lhs>AdditiveExpr</lhs><rhs><nt def="prod-xquery-MultiplicativeExpr">MultiplicativeExpr</nt> ( ("+"  |  "-")  <nt def="prod-xquery-MultiplicativeExpr">MultiplicativeExpr</nt> )*</rhs></prod><prod num="54" id="prod-xquery-MultiplicativeExpr"><lhs>MultiplicativeExpr</lhs><rhs><nt def="prod-xquery-UnionExpr">UnionExpr</nt> ( ("*"  |  "div"  |  "idiv"  |  "mod")  <nt def="prod-xquery-UnionExpr">UnionExpr</nt> )*</rhs></prod><prod num="55" id="prod-xquery-UnionExpr"><lhs>UnionExpr</lhs><rhs><nt def="prod-xquery-IntersectExceptExpr">IntersectExceptExpr</nt> ( ("union"  |  "|")  <nt def="prod-xquery-IntersectExceptExpr">IntersectExceptExpr</nt> )*</rhs></prod><prod num="56" id="prod-xquery-IntersectExceptExpr"><lhs>IntersectExceptExpr</lhs><rhs><nt def="prod-xquery-InstanceofExpr">InstanceofExpr</nt> ( ("intersect"  |  "except")  <nt def="prod-xquery-InstanceofExpr">InstanceofExpr</nt> )*</rhs></prod><prod num="57" id="prod-xquery-InstanceofExpr"><lhs>InstanceofExpr</lhs><rhs><nt def="prod-xquery-TreatExpr">TreatExpr</nt> ( "instance"  "of"  <nt def="prod-xquery-SequenceType">SequenceType</nt> )?</rhs></prod><prod num="58" id="prod-xquery-TreatExpr"><lhs>TreatExpr</lhs><rhs><nt def="prod-xquery-CastableExpr">CastableExpr</nt> ( "treat"  "as"  <nt def="prod-xquery-SequenceType">SequenceType</nt> )?</rhs></prod><prod num="59" id="prod-xquery-CastableExpr"><lhs>CastableExpr</lhs><rhs><nt def="prod-xquery-CastExpr">CastExpr</nt> ( "castable"  "as"  <nt def="prod-xquery-SingleType">SingleType</nt> )?</rhs></prod><prod num="60" id="prod-xquery-CastExpr"><lhs>CastExpr</lhs><rhs><nt def="prod-xquery-UnaryExpr">UnaryExpr</nt> ( "cast"  "as"  <nt def="prod-xquery-SingleType">SingleType</nt> )?</rhs></prod><prod num="61" id="prod-xquery-UnaryExpr"><lhs>UnaryExpr</lhs><rhs>("-"  |  "+")* <nt def="prod-xquery-ValueExpr">ValueExpr</nt></rhs></prod><prod num="62" id="prod-xquery-ValueExpr"><lhs>ValueExpr</lhs><rhs><nt def="prod-xquery-ValidateExpr">ValidateExpr</nt>  |  <nt def="prod-xquery-PathExpr">PathExpr</nt>  |  <nt def="prod-xquery-ExtensionExpr">ExtensionExpr</nt></rhs></prod><prod num="63" id="prod-xquery-GeneralComp"><lhs>GeneralComp</lhs><rhs>"="  |  "!="  |  "&lt;"  |  "&lt;="  |  "&gt;"  |  "&gt;="</rhs></prod><prod num="64" id="prod-xquery-ValueComp"><lhs>ValueComp</lhs><rhs>"eq"  |  "ne"  |  "lt"  |  "le"  |  "gt"  |  "ge"</rhs></prod><prod num="65" id="prod-xquery-NodeComp"><lhs>NodeComp</lhs><rhs>"is"  |  "&lt;&lt;"  |  "&gt;&gt;"</rhs></prod><prod num="66" id="prod-xquery-ValidateExpr"><lhs>ValidateExpr</lhs><rhs>"validate"  <nt def="prod-xquery-ValidationMode">ValidationMode</nt>?  "{"  <nt def="prod-xquery-Expr">Expr</nt>  "}"</rhs></prod><prod num="67" id="prod-xquery-ValidationMode"><lhs>ValidationMode</lhs><rhs>"lax"  |  "strict"</rhs></prod><prod num="68" id="prod-xquery-ExtensionExpr"><lhs>ExtensionExpr</lhs><rhs><nt def="prod-xquery-Pragma">Pragma</nt>+  "{"  <nt def="prod-xquery-Expr">Expr</nt>?  "}"</rhs></prod><prod num="69" id="prod-xquery-Pragma"><lhs>Pragma</lhs><rhs>"(#"  <nt def="prod-xquery-S">S</nt>?  <nt def="prod-xquery-QName">QName</nt>  (<nt def="prod-xquery-S">S</nt>  <nt def="prod-xquery-PragmaContents">PragmaContents</nt>)?  "#)"</rhs><com><phrase><xspecref ref="ws-explicit" spec="XQ">ws: explicit</xspecref></phrase></com></prod><prod num="70" id="prod-xquery-PragmaContents"><lhs>PragmaContents</lhs><rhs>(<nt def="prod-xquery-Char">Char</nt>* - (Char* '#)' Char*))</rhs></prod><prod num="71" id="prod-xquery-PathExpr"><lhs>PathExpr</lhs><rhs>("/"  <nt def="prod-xquery-RelativePathExpr">RelativePathExpr</nt>?)<br/>|  ("//"  <nt def="prod-xquery-RelativePathExpr">RelativePathExpr</nt>)<br/>|  <nt def="prod-xquery-RelativePathExpr">RelativePathExpr</nt></rhs><com><phrase><xspecref ref="parse-note-leading-lone-slash" spec="XQ">gn: leading-lone-slash</xspecref></phrase></com></prod><prod num="72" id="prod-xquery-RelativePathExpr"><lhs>RelativePathExpr</lhs><rhs><nt def="prod-xquery-StepExpr">StepExpr</nt>  (("/"  |  "//")  <nt def="prod-xquery-StepExpr">StepExpr</nt>)*</rhs></prod><prod num="73" id="prod-xquery-StepExpr"><lhs>StepExpr</lhs><rhs><nt def="prod-xquery-FilterExpr">FilterExpr</nt>  |  <nt def="prod-xquery-AxisStep">AxisStep</nt></rhs></prod><prod num="74" id="prod-xquery-AxisStep"><lhs>AxisStep</lhs><rhs>(<nt def="prod-xquery-ReverseStep">ReverseStep</nt>  |  <nt def="prod-xquery-ForwardStep">ForwardStep</nt>)  <nt def="prod-xquery-PredicateList">PredicateList</nt></rhs></prod><prod num="75" id="prod-xquery-ForwardStep"><lhs>ForwardStep</lhs><rhs>(<nt def="prod-xquery-ForwardAxis">ForwardAxis</nt>  <nt def="prod-xquery-NodeTest">NodeTest</nt>)  |  <nt def="prod-xquery-AbbrevForwardStep">AbbrevForwardStep</nt></rhs></prod><prod num="76" id="prod-xquery-ForwardAxis"><lhs>ForwardAxis</lhs><rhs>("child"  "::")<br/>|  ("descendant"  "::")<br/>|  ("attribute"  "::")<br/>|  ("self"  "::")<br/>|  ("descendant-or-self"  "::")<br/>|  ("following-sibling"  "::")<br/>|  ("following"  "::")</rhs></prod><prod num="77" id="prod-xquery-AbbrevForwardStep"><lhs>AbbrevForwardStep</lhs><rhs>"@"?  <nt def="prod-xquery-NodeTest">NodeTest</nt></rhs></prod><prod num="78" id="prod-xquery-ReverseStep"><lhs>ReverseStep</lhs><rhs>(<nt def="prod-xquery-ReverseAxis">ReverseAxis</nt>  <nt def="prod-xquery-NodeTest">NodeTest</nt>)  |  <nt def="prod-xquery-AbbrevReverseStep">AbbrevReverseStep</nt></rhs></prod><prod num="79" id="prod-xquery-ReverseAxis"><lhs>ReverseAxis</lhs><rhs>("parent"  "::")<br/>|  ("ancestor"  "::")<br/>|  ("preceding-sibling"  "::")<br/>|  ("preceding"  "::")<br/>|  ("ancestor-or-self"  "::")</rhs></prod><prod num="80" id="prod-xquery-AbbrevReverseStep"><lhs>AbbrevReverseStep</lhs><rhs>".."</rhs></prod><prod num="81" id="prod-xquery-NodeTest"><lhs>NodeTest</lhs><rhs><nt def="prod-xquery-KindTest">KindTest</nt>  |  <nt def="prod-xquery-NameTest">NameTest</nt></rhs></prod><prod num="82" id="prod-xquery-NameTest"><lhs>NameTest</lhs><rhs><nt def="prod-xquery-QName">QName</nt>  |  <nt def="prod-xquery-Wildcard">Wildcard</nt></rhs></prod><prod num="83" id="prod-xquery-Wildcard"><lhs>Wildcard</lhs><rhs>"*"<br/>|  (<nt def="prod-xquery-NCName">NCName</nt>  ":"  "*")<br/>|  ("*"  ":"  <nt def="prod-xquery-NCName">NCName</nt>)</rhs><com><phrase><xspecref ref="ws-explicit" spec="XQ">ws: explicit</xspecref></phrase></com></prod><prod num="84" id="prod-xquery-FilterExpr"><lhs>FilterExpr</lhs><rhs><nt def="prod-xquery-PrimaryExpr">PrimaryExpr</nt>  <nt def="prod-xquery-PredicateList">PredicateList</nt></rhs></prod><prod num="85" id="prod-xquery-PredicateList"><lhs>PredicateList</lhs><rhs><nt def="prod-xquery-Predicate">Predicate</nt>*</rhs></prod><prod num="86" id="prod-xquery-Predicate"><lhs>Predicate</lhs><rhs>"["  <nt def="prod-xquery-Expr">Expr</nt>  "]"</rhs></prod><prod num="87" id="prod-xquery-PrimaryExpr"><lhs>PrimaryExpr</lhs><rhs><nt def="prod-xquery-Literal">Literal</nt>  |  <nt def="prod-xquery-VarRef">VarRef</nt>  |  <nt def="prod-xquery-ParenthesizedExpr">ParenthesizedExpr</nt>  |  <nt def="prod-xquery-ContextItemExpr">ContextItemExpr</nt>  |  <nt def="prod-xquery-FunctionCall">FunctionCall</nt>  |  <nt def="prod-xquery-OrderedExpr">OrderedExpr</nt>  |  <nt def="prod-xquery-UnorderedExpr">UnorderedExpr</nt>  |  <nt def="prod-xquery-Constructor">Constructor</nt></rhs></prod><prod num="88" id="prod-xquery-Literal"><lhs>Literal</lhs><rhs><nt def="prod-xquery-NumericLiteral">NumericLiteral</nt>  |  <nt def="prod-xquery-StringLiteral">StringLiteral</nt></rhs></prod><prod num="89" id="prod-xquery-NumericLiteral"><lhs>NumericLiteral</lhs><rhs><nt def="prod-xquery-IntegerLiteral">IntegerLiteral</nt>  |  <nt def="prod-xquery-DecimalLiteral">DecimalLiteral</nt>  |  <nt def="prod-xquery-DoubleLiteral">DoubleLiteral</nt></rhs></prod><prod num="90" id="prod-xquery-VarRef"><lhs>VarRef</lhs><rhs>"$"  <nt def="prod-xquery-VarName">VarName</nt></rhs></prod><prod num="91" id="prod-xquery-VarName"><lhs>VarName</lhs><rhs><nt def="prod-xquery-QName">QName</nt></rhs></prod><prod num="92" id="prod-xquery-ParenthesizedExpr"><lhs>ParenthesizedExpr</lhs><rhs>"("  <nt def="prod-xquery-Expr">Expr</nt>?  ")"</rhs></prod><prod num="93" id="prod-xquery-ContextItemExpr"><lhs>ContextItemExpr</lhs><rhs>"."</rhs></prod><prod num="94" id="prod-xquery-OrderedExpr"><lhs>OrderedExpr</lhs><rhs>"ordered"  "{"  <nt def="prod-xquery-Expr">Expr</nt>  "}"</rhs></prod><prod num="95" id="prod-xquery-UnorderedExpr"><lhs>UnorderedExpr</lhs><rhs>"unordered"  "{"  <nt def="prod-xquery-Expr">Expr</nt>  "}"</rhs></prod><prod num="96" id="prod-xquery-FunctionCall"><lhs>FunctionCall</lhs><rhs><nt def="prod-xquery-QName">QName</nt>  "("  (<nt def="prod-xquery-ExprSingle">ExprSingle</nt>  (","  <nt def="prod-xquery-ExprSingle">ExprSingle</nt>)*)?  ")"</rhs><com><phrase><xspecref ref="parse-note-reserved-function-names" spec="XQ">gn: reserved-function-names</xspecref></phrase></com><com><phrase><xspecref ref="parse-note-parens" spec="XQ">gn: parens</xspecref></phrase></com></prod><prod num="97" id="prod-xquery-Constructor"><lhs>Constructor</lhs><rhs><nt def="prod-xquery-DirectConstructor">DirectConstructor</nt><br/>|  <nt def="prod-xquery-ComputedConstructor">ComputedConstructor</nt></rhs></prod><prod num="98" id="prod-xquery-DirectConstructor"><lhs>DirectConstructor</lhs><rhs><nt def="prod-xquery-DirElemConstructor">DirElemConstructor</nt><br/>|  <nt def="prod-xquery-DirCommentConstructor">DirCommentConstructor</nt><br/>|  <nt def="prod-xquery-DirPIConstructor">DirPIConstructor</nt></rhs></prod><prod num="99" id="prod-xquery-DirElemConstructor"><lhs>DirElemConstructor</lhs><rhs>"&lt;"  <nt def="prod-xquery-QName">QName</nt>  <nt def="prod-xquery-DirAttributeList">DirAttributeList</nt>  ("/&gt;"  |  ("&gt;"  <nt def="prod-xquery-DirElemContent">DirElemContent</nt>*  "&lt;/"  <nt def="prod-xquery-QName">QName</nt>  <nt def="prod-xquery-S">S</nt>?  "&gt;"))</rhs><com><phrase><xspecref ref="ws-explicit" spec="XQ">ws: explicit</xspecref></phrase></com></prod><prod num="100" id="prod-xquery-DirAttributeList"><lhs>DirAttributeList</lhs><rhs>(<nt def="prod-xquery-S">S</nt>  (<nt def="prod-xquery-QName">QName</nt>  <nt def="prod-xquery-S">S</nt>?  "="  <nt def="prod-xquery-S">S</nt>?  <nt def="prod-xquery-DirAttributeValue">DirAttributeValue</nt>)?)*</rhs><com><phrase><xspecref ref="ws-explicit" spec="XQ">ws: explicit</xspecref></phrase></com></prod><prod num="101" id="prod-xquery-DirAttributeValue"><lhs>DirAttributeValue</lhs><rhs>('"'  (<nt def="prod-xquery-EscapeQuot">EscapeQuot</nt>  |  <nt def="prod-xquery-QuotAttrValueContent">QuotAttrValueContent</nt>)*  '"')<br/>|  ("'"  (<nt def="prod-xquery-EscapeApos">EscapeApos</nt>  |  <nt def="prod-xquery-AposAttrValueContent">AposAttrValueContent</nt>)*  "'")</rhs><com><phrase><xspecref ref="ws-explicit" spec="XQ">ws: explicit</xspecref></phrase></com></prod><prod num="102" id="prod-xquery-QuotAttrValueContent"><lhs>QuotAttrValueContent</lhs><rhs><nt def="prod-xquery-QuotAttrContentChar">QuotAttrContentChar</nt><br/>|  <nt def="prod-xquery-CommonContent">CommonContent</nt></rhs></prod><prod num="103" id="prod-xquery-AposAttrValueContent"><lhs>AposAttrValueContent</lhs><rhs><nt def="prod-xquery-AposAttrContentChar">AposAttrContentChar</nt><br/>|  <nt def="prod-xquery-CommonContent">CommonContent</nt></rhs></prod><prod num="104" id="prod-xquery-DirElemContent"><lhs>DirElemContent</lhs><rhs><nt def="prod-xquery-DirectConstructor">DirectConstructor</nt><br/>|  <nt def="prod-xquery-CDataSection">CDataSection</nt><br/>|  <nt def="prod-xquery-CommonContent">CommonContent</nt><br/>|  <nt def="prod-xquery-ElementContentChar">ElementContentChar</nt></rhs></prod><prod num="105" id="prod-xquery-CommonContent"><lhs>CommonContent</lhs><rhs><nt def="prod-xquery-PredefinedEntityRef">PredefinedEntityRef</nt>  |  <nt def="prod-xquery-CharRef">CharRef</nt>  |  "{{"  |  "}}"  |  <nt def="prod-xquery-EnclosedExpr">EnclosedExpr</nt></rhs></prod><prod num="106" id="prod-xquery-DirCommentConstructor"><lhs>DirCommentConstructor</lhs><rhs>"&lt;!--"  <nt def="prod-xquery-DirCommentContents">DirCommentContents</nt>  "--&gt;"</rhs><com><phrase><xspecref ref="ws-explicit" spec="XQ">ws: explicit</xspecref></phrase></com></prod><prod num="107" id="prod-xquery-DirCommentContents"><lhs>DirCommentContents</lhs><rhs>((<nt def="prod-xquery-Char">Char</nt> - '-')  |  ('-'  (<nt def="prod-xquery-Char">Char</nt> - '-')))*</rhs><com><phrase><xspecref ref="ws-explicit" spec="XQ">ws: explicit</xspecref></phrase></com></prod><prod num="108" id="prod-xquery-DirPIConstructor"><lhs>DirPIConstructor</lhs><rhs>"&lt;?"  <nt def="prod-xquery-PITarget">PITarget</nt>  (<nt def="prod-xquery-S">S</nt>  <nt def="prod-xquery-DirPIContents">DirPIContents</nt>)?  "?&gt;"</rhs><com><phrase><xspecref ref="ws-explicit" spec="XQ">ws: explicit</xspecref></phrase></com></prod><prod num="109" id="prod-xquery-DirPIContents"><lhs>DirPIContents</lhs><rhs>(<nt def="prod-xquery-Char">Char</nt>* - (Char* '?&gt;' Char*))</rhs><com><phrase><xspecref ref="ws-explicit" spec="XQ">ws: explicit</xspecref></phrase></com></prod><prod num="110" id="prod-xquery-CDataSection"><lhs>CDataSection</lhs><rhs>"&lt;![CDATA["  <nt def="prod-xquery-CDataSectionContents">CDataSectionContents</nt>  "]]&gt;"</rhs><com><phrase><xspecref ref="ws-explicit" spec="XQ">ws: explicit</xspecref></phrase></com></prod><prod num="111" id="prod-xquery-CDataSectionContents"><lhs>CDataSectionContents</lhs><rhs>(<nt def="prod-xquery-Char">Char</nt>* - (Char* ']]&gt;' Char*))</rhs><com><phrase><xspecref ref="ws-explicit" spec="XQ">ws: explicit</xspecref></phrase></com></prod><prod num="112" id="prod-xquery-ComputedConstructor"><lhs>ComputedConstructor</lhs><rhs><nt def="prod-xquery-CompDocConstructor">CompDocConstructor</nt><br/>|  <nt def="prod-xquery-CompElemConstructor">CompElemConstructor</nt><br/>|  <nt def="prod-xquery-CompAttrConstructor">CompAttrConstructor</nt><br/>|  <nt def="prod-xquery-CompTextConstructor">CompTextConstructor</nt><br/>|  <nt def="prod-xquery-CompCommentConstructor">CompCommentConstructor</nt><br/>|  <nt def="prod-xquery-CompPIConstructor">CompPIConstructor</nt></rhs></prod><prod num="113" id="prod-xquery-CompDocConstructor"><lhs>CompDocConstructor</lhs><rhs>"document"  "{"  <nt def="prod-xquery-Expr">Expr</nt>  "}"</rhs></prod><prod num="114" id="prod-xquery-CompElemConstructor"><lhs>CompElemConstructor</lhs><rhs>"element"  (<nt def="prod-xquery-QName">QName</nt>  |  ("{"  <nt def="prod-xquery-Expr">Expr</nt>  "}"))  "{"  <nt def="prod-xquery-ContentExpr">ContentExpr</nt>?  "}"</rhs></prod><prod num="115" id="prod-xquery-ContentExpr"><lhs>ContentExpr</lhs><rhs><nt def="prod-xquery-Expr">Expr</nt></rhs></prod><prod num="116" id="prod-xquery-CompAttrConstructor"><lhs>CompAttrConstructor</lhs><rhs>"attribute"  (<nt def="prod-xquery-QName">QName</nt>  |  ("{"  <nt def="prod-xquery-Expr">Expr</nt>  "}"))  "{"  <nt def="prod-xquery-Expr">Expr</nt>?  "}"</rhs></prod><prod num="117" id="prod-xquery-CompTextConstructor"><lhs>CompTextConstructor</lhs><rhs>"text"  "{"  <nt def="prod-xquery-Expr">Expr</nt>  "}"</rhs></prod><prod num="118" id="prod-xquery-CompCommentConstructor"><lhs>CompCommentConstructor</lhs><rhs>"comment"  "{"  <nt def="prod-xquery-Expr">Expr</nt>  "}"</rhs></prod><prod num="119" id="prod-xquery-CompPIConstructor"><lhs>CompPIConstructor</lhs><rhs>"processing-instruction"  (<nt def="prod-xquery-NCName">NCName</nt>  |  ("{"  <nt def="prod-xquery-Expr">Expr</nt>  "}"))  "{"  <nt def="prod-xquery-Expr">Expr</nt>?  "}"</rhs></prod><prod num="120" id="prod-xquery-SingleType"><lhs>SingleType</lhs><rhs><nt def="prod-xquery-AtomicType">AtomicType</nt>  "?"?</rhs></prod><prod num="121" id="prod-xquery-TypeDeclaration"><lhs>TypeDeclaration</lhs><rhs>"as"  <nt def="prod-xquery-SequenceType">SequenceType</nt></rhs></prod><prod num="122" id="prod-xquery-SequenceType"><lhs>SequenceType</lhs><rhs>("empty-sequence"  "("  ")")<br/>|  (<nt def="prod-xquery-ItemType">ItemType</nt>  <nt def="prod-xquery-OccurrenceIndicator">OccurrenceIndicator</nt>?)</rhs></prod><prod num="123" id="prod-xquery-OccurrenceIndicator"><lhs>OccurrenceIndicator</lhs><rhs>"?"  |  "*"  |  "+"</rhs><com><phrase><xspecref ref="parse-note-occurrence-indicators" spec="XQ">gn: occurrence-indicators</xspecref></phrase></com></prod><prod num="124" id="prod-xquery-ItemType"><lhs>ItemType</lhs><rhs><nt def="prod-xquery-KindTest">KindTest</nt>  |  ("item"  "("  ")")  |  <nt def="prod-xquery-AtomicType">AtomicType</nt></rhs></prod><prod num="125" id="prod-xquery-AtomicType"><lhs>AtomicType</lhs><rhs><nt def="prod-xquery-QName">QName</nt></rhs></prod><prod num="126" id="prod-xquery-KindTest"><lhs>KindTest</lhs><rhs><nt def="prod-xquery-DocumentTest">DocumentTest</nt><br/>|  <nt def="prod-xquery-ElementTest">ElementTest</nt><br/>|  <nt def="prod-xquery-AttributeTest">AttributeTest</nt><br/>|  <nt def="prod-xquery-SchemaElementTest">SchemaElementTest</nt><br/>|  <nt def="prod-xquery-SchemaAttributeTest">SchemaAttributeTest</nt><br/>|  <nt def="prod-xquery-PITest">PITest</nt><br/>|  <nt def="prod-xquery-CommentTest">CommentTest</nt><br/>|  <nt def="prod-xquery-TextTest">TextTest</nt><br/>|  <nt def="prod-xquery-AnyKindTest">AnyKindTest</nt></rhs></prod><prod num="127" id="prod-xquery-AnyKindTest"><lhs>AnyKindTest</lhs><rhs>"node"  "("  ")"</rhs></prod><prod num="128" id="prod-xquery-DocumentTest"><lhs>DocumentTest</lhs><rhs>"document-node"  "("  (<nt def="prod-xquery-ElementTest">ElementTest</nt>  |  <nt def="prod-xquery-SchemaElementTest">SchemaElementTest</nt>)?  ")"</rhs></prod><prod num="129" id="prod-xquery-TextTest"><lhs>TextTest</lhs><rhs>"text"  "("  ")"</rhs></prod><prod num="130" id="prod-xquery-CommentTest"><lhs>CommentTest</lhs><rhs>"comment"  "("  ")"</rhs></prod><prod num="131" id="prod-xquery-PITest"><lhs>PITest</lhs><rhs>"processing-instruction"  "("  (<nt def="prod-xquery-NCName">NCName</nt>  |  <nt def="prod-xquery-StringLiteral">StringLiteral</nt>)?  ")"</rhs></prod><prod num="132" id="prod-xquery-AttributeTest"><lhs>AttributeTest</lhs><rhs>"attribute"  "("  (<nt def="prod-xquery-AttribNameOrWildcard">AttribNameOrWildcard</nt>  (","  <nt def="prod-xquery-TypeName">TypeName</nt>)?)?  ")"</rhs></prod><prod num="133" id="prod-xquery-AttribNameOrWildcard"><lhs>AttribNameOrWildcard</lhs><rhs><nt def="prod-xquery-AttributeName">AttributeName</nt>  |  "*"</rhs></prod><prod num="134" id="prod-xquery-SchemaAttributeTest"><lhs>SchemaAttributeTest</lhs><rhs>"schema-attribute"  "("  <nt def="prod-xquery-AttributeDeclaration">AttributeDeclaration</nt>  ")"</rhs></prod><prod num="135" id="prod-xquery-AttributeDeclaration"><lhs>AttributeDeclaration</lhs><rhs><nt def="prod-xquery-AttributeName">AttributeName</nt></rhs></prod><prod num="136" id="prod-xquery-ElementTest"><lhs>ElementTest</lhs><rhs>"element"  "("  (<nt def="prod-xquery-ElementNameOrWildcard">ElementNameOrWildcard</nt>  (","  <nt def="prod-xquery-TypeName">TypeName</nt>  "?"?)?)?  ")"</rhs></prod><prod num="137" id="prod-xquery-ElementNameOrWildcard"><lhs>ElementNameOrWildcard</lhs><rhs><nt def="prod-xquery-ElementName">ElementName</nt>  |  "*"</rhs></prod><prod num="138" id="prod-xquery-SchemaElementTest"><lhs>SchemaElementTest</lhs><rhs>"schema-element"  "("  <nt def="prod-xquery-ElementDeclaration">ElementDeclaration</nt>  ")"</rhs></prod><prod num="139" id="prod-xquery-ElementDeclaration"><lhs>ElementDeclaration</lhs><rhs><nt def="prod-xquery-ElementName">ElementName</nt></rhs></prod><prod num="140" id="prod-xquery-AttributeName"><lhs>AttributeName</lhs><rhs><nt def="prod-xquery-QName">QName</nt></rhs></prod><prod num="141" id="prod-xquery-ElementName"><lhs>ElementName</lhs><rhs><nt def="prod-xquery-QName">QName</nt></rhs></prod><prod num="142" id="prod-xquery-TypeName"><lhs>TypeName</lhs><rhs><nt def="prod-xquery-QName">QName</nt></rhs></prod><prod num="143" id="prod-xquery-URILiteral"><lhs>URILiteral</lhs><rhs><nt def="prod-xquery-StringLiteral">StringLiteral</nt></rhs></prod><prod num="144" id="prod-xquery-FTSelection"><lhs>FTSelection</lhs><rhs><nt def="prod-xquery-FTOr">FTOr</nt>  (<nt def="prod-xquery-FTMatchOption">FTMatchOption</nt>  |  <nt def="prod-xquery-FTProximity">FTProximity</nt>)*  ("weight"  <nt def="prod-xquery-RangeExpr">RangeExpr</nt>)?</rhs></prod><prod num="145" id="prod-xquery-FTOr"><lhs>FTOr</lhs><rhs><nt def="prod-xquery-FTAnd">FTAnd</nt> ( "||"  <nt def="prod-xquery-FTAnd">FTAnd</nt> )*</rhs></prod><prod num="146" id="prod-xquery-FTAnd"><lhs>FTAnd</lhs><rhs><nt def="prod-xquery-FTMildnot">FTMildnot</nt> ( "&amp;&amp;"  <nt def="prod-xquery-FTMildnot">FTMildnot</nt> )*</rhs></prod><prod num="147" id="prod-xquery-FTMildnot"><lhs>FTMildnot</lhs><rhs><nt def="prod-xquery-FTUnaryNot">FTUnaryNot</nt> ( "not"  "in"  <nt def="prod-xquery-FTUnaryNot">FTUnaryNot</nt> )*</rhs></prod><prod num="148" id="prod-xquery-FTUnaryNot"><lhs>FTUnaryNot</lhs><rhs>("!")? <nt def="prod-xquery-FTWordsSelection">FTWordsSelection</nt></rhs></prod><prod num="149" id="prod-xquery-FTWordsSelection"><lhs>FTWordsSelection</lhs><rhs>(<nt def="prod-xquery-FTWords">FTWords</nt>  <nt def="prod-xquery-FTTimes">FTTimes</nt>?)  |  ("("  <nt def="prod-xquery-FTSelection">FTSelection</nt>  ")")</rhs></prod><prod num="150" id="prod-xquery-FTWords"><lhs>FTWords</lhs><rhs><nt def="prod-xquery-FTWordsValue">FTWordsValue</nt>  <nt def="prod-xquery-FTAnyallOption">FTAnyallOption</nt>?</rhs></prod><prod num="151" id="prod-xquery-FTWordsValue"><lhs>FTWordsValue</lhs><rhs><nt def="prod-xquery-Literal">Literal</nt>  |  ("{"  <nt def="prod-xquery-Expr">Expr</nt>  "}")</rhs></prod><prod num="152" id="prod-xquery-FTProximity"><lhs>FTProximity</lhs><rhs><nt def="prod-xquery-FTOrderedIndicator">FTOrderedIndicator</nt>  |  <nt def="prod-xquery-FTWindow">FTWindow</nt>  |  <nt def="prod-xquery-FTDistance">FTDistance</nt>  |  <nt def="prod-xquery-FTScope">FTScope</nt>  |  <nt def="prod-xquery-FTContent">FTContent</nt></rhs></prod><prod num="153" id="prod-xquery-FTOrderedIndicator"><lhs>FTOrderedIndicator</lhs><rhs>"ordered"</rhs></prod><prod num="154" id="prod-xquery-FTMatchOption"><lhs>FTMatchOption</lhs><rhs><nt def="prod-xquery-FTCaseOption">FTCaseOption</nt><br/>|  <nt def="prod-xquery-FTDiacriticsOption">FTDiacriticsOption</nt><br/>|  <nt def="prod-xquery-FTStemOption">FTStemOption</nt><br/>|  <nt def="prod-xquery-FTThesaurusOption">FTThesaurusOption</nt><br/>|  <nt def="prod-xquery-FTStopwordOption">FTStopwordOption</nt><br/>|  <nt def="prod-xquery-FTLanguageOption">FTLanguageOption</nt><br/>|  <nt def="prod-xquery-FTWildCardOption">FTWildCardOption</nt></rhs></prod><prod num="155" id="prod-xquery-FTCaseOption"><lhs>FTCaseOption</lhs><rhs>"lowercase"<br/>|  "uppercase"<br/>|  ("case"  "sensitive")<br/>|  ("case"  "insensitive")</rhs></prod><prod num="156" id="prod-xquery-FTDiacriticsOption"><lhs>FTDiacriticsOption</lhs><rhs>("with"  "diacritics")<br/>|  ("without"  "diacritics")<br/>|  ("diacritics"  "sensitive")<br/>|  ("diacritics"  "insensitive")</rhs></prod><prod num="157" id="prod-xquery-FTStemOption"><lhs>FTStemOption</lhs><rhs>("with"  "stemming")  |  ("without"  "stemming")</rhs></prod><prod num="158" id="prod-xquery-FTThesaurusOption"><lhs>FTThesaurusOption</lhs><rhs>("with"  "thesaurus"  (<nt def="prod-xquery-FTThesaurusID">FTThesaurusID</nt>  |  "default"))<br/>|  ("with"  "thesaurus"  "("  (<nt def="prod-xquery-FTThesaurusID">FTThesaurusID</nt>  |  "default")  (","  <nt def="prod-xquery-FTThesaurusID">FTThesaurusID</nt>)*  ")")<br/>|  ("without"  "thesaurus")</rhs></prod><prod num="159" id="prod-xquery-FTThesaurusID"><lhs>FTThesaurusID</lhs><rhs>"at"  <nt def="prod-xquery-StringLiteral">StringLiteral</nt>  ("relationship"  <nt def="prod-xquery-StringLiteral">StringLiteral</nt>)?  (<nt def="prod-xquery-FTRange">FTRange</nt>  "levels")?</rhs></prod><prod num="160" id="prod-xquery-FTStopwordOption"><lhs>FTStopwordOption</lhs><rhs>("with"  "stop"  "words"  <nt def="prod-xquery-FTRefOrList">FTRefOrList</nt>  <nt def="prod-xquery-FTInclExclStringLiteral">FTInclExclStringLiteral</nt>*)<br/>|  ("without"  "stop"  "words")<br/>|  ("with"  "default"  "stop"  "words"  <nt def="prod-xquery-FTInclExclStringLiteral">FTInclExclStringLiteral</nt>*)</rhs></prod><prod num="161" id="prod-xquery-FTRefOrList"><lhs>FTRefOrList</lhs><rhs>("at"  <nt def="prod-xquery-StringLiteral">StringLiteral</nt>)<br/>|  ("("  <nt def="prod-xquery-StringLiteral">StringLiteral</nt>  (","  <nt def="prod-xquery-StringLiteral">StringLiteral</nt>)*  ")")</rhs></prod><prod num="162" id="prod-xquery-FTInclExclStringLiteral"><lhs>FTInclExclStringLiteral</lhs><rhs>("union"  |  "except")  <nt def="prod-xquery-FTRefOrList">FTRefOrList</nt></rhs></prod><prod num="163" id="prod-xquery-FTLanguageOption"><lhs>FTLanguageOption</lhs><rhs>"language"  <nt def="prod-xquery-StringLiteral">StringLiteral</nt></rhs></prod><prod num="164" id="prod-xquery-FTWildCardOption"><lhs>FTWildCardOption</lhs><rhs>("with"  "wildcards")  |  ("without"  "wildcards")</rhs></prod><prod num="165" id="prod-xquery-FTContent"><lhs>FTContent</lhs><rhs>("at"  "start")  |  ("at"  "end")  |  ("entire"  "content")</rhs></prod><prod num="166" id="prod-xquery-FTAnyallOption"><lhs>FTAnyallOption</lhs><rhs>("any"  "word"?)  |  ("all"  "words"?)  |  "phrase"</rhs></prod><prod num="167" id="prod-xquery-FTRange"><lhs>FTRange</lhs><rhs>("exactly"  <nt def="prod-xquery-UnionExpr">UnionExpr</nt>)<br/>|  ("at"  "least"  <nt def="prod-xquery-UnionExpr">UnionExpr</nt>)<br/>|  ("at"  "most"  <nt def="prod-xquery-UnionExpr">UnionExpr</nt>)<br/>|  ("from"  <nt def="prod-xquery-UnionExpr">UnionExpr</nt>  "to"  <nt def="prod-xquery-UnionExpr">UnionExpr</nt>)</rhs></prod><prod num="168" id="prod-xquery-FTDistance"><lhs>FTDistance</lhs><rhs>"distance"  <nt def="prod-xquery-FTRange">FTRange</nt>  <nt def="prod-xquery-FTUnit">FTUnit</nt></rhs></prod><prod num="169" id="prod-xquery-FTWindow"><lhs>FTWindow</lhs><rhs>"window"  <nt def="prod-xquery-UnionExpr">UnionExpr</nt>  <nt def="prod-xquery-FTUnit">FTUnit</nt></rhs></prod><prod num="170" id="prod-xquery-FTTimes"><lhs>FTTimes</lhs><rhs>"occurs"  <nt def="prod-xquery-FTRange">FTRange</nt>  "times"</rhs></prod><prod num="171" id="prod-xquery-FTScope"><lhs>FTScope</lhs><rhs>("same"  |  "different")  <nt def="prod-xquery-FTBigUnit">FTBigUnit</nt></rhs></prod><prod num="172" id="prod-xquery-FTUnit"><lhs>FTUnit</lhs><rhs>"words"  |  "sentences"  |  "paragraphs"</rhs></prod><prod num="173" id="prod-xquery-FTBigUnit"><lhs>FTBigUnit</lhs><rhs>"sentence"  |  "paragraph"</rhs></prod><prod num="174" id="prod-xquery-FTIgnoreOption"><lhs>FTIgnoreOption</lhs><rhs>"without"  "content"  <nt def="prod-xquery-UnionExpr">UnionExpr</nt></rhs></prod>
</scrap>

<div2 id="grammar-terminals"><head>Terminal Symbols</head><scrap headstyle="show">
		    
		  <head/><prod num="175" id="prod-xquery-IntegerLiteral"><lhs>IntegerLiteral</lhs><rhs><nt def="prod-xquery-Digits">Digits</nt></rhs></prod><prod num="176" id="prod-xquery-DecimalLiteral"><lhs>DecimalLiteral</lhs><rhs>("."  <nt def="prod-xquery-Digits">Digits</nt>)  |  (<nt def="prod-xquery-Digits">Digits</nt>  "."  [0-9]*)</rhs><com><phrase><xspecref ref="ws-explicit" spec="XQ">ws: explicit</xspecref></phrase></com></prod><prod num="177" id="prod-xquery-DoubleLiteral"><lhs>DoubleLiteral</lhs><rhs>(("."  <nt def="prod-xquery-Digits">Digits</nt>)  |  (<nt def="prod-xquery-Digits">Digits</nt>  ("."  [0-9]*)?))  [eE]  [+-]?  <nt def="prod-xquery-Digits">Digits</nt></rhs><com><phrase><xspecref ref="ws-explicit" spec="XQ">ws: explicit</xspecref></phrase></com></prod><prod num="178" id="prod-xquery-StringLiteral"><lhs>StringLiteral</lhs><rhs>('"'  (<nt def="prod-xquery-PredefinedEntityRef">PredefinedEntityRef</nt>  |  <nt def="prod-xquery-CharRef">CharRef</nt>  |  <nt def="prod-xquery-EscapeQuot">EscapeQuot</nt>  |  [^"&amp;])*  '"')  |  ("'"  (<nt def="prod-xquery-PredefinedEntityRef">PredefinedEntityRef</nt>  |  <nt def="prod-xquery-CharRef">CharRef</nt>  |  <nt def="prod-xquery-EscapeApos">EscapeApos</nt>  |  [^'&amp;])*  "'")</rhs><com><phrase><xspecref ref="ws-explicit" spec="XQ">ws: explicit</xspecref></phrase></com></prod><prod num="179" id="prod-xquery-PredefinedEntityRef"><lhs>PredefinedEntityRef</lhs><rhs>"&amp;"  ("lt"  |  "gt"  |  "amp"  |  "quot"  |  "apos")  ";"</rhs><com><phrase><xspecref ref="ws-explicit" spec="XQ">ws: explicit</xspecref></phrase></com></prod><prod num="180" id="prod-xquery-EscapeQuot"><lhs>EscapeQuot</lhs><rhs>'""'</rhs></prod><prod num="181" id="prod-xquery-EscapeApos"><lhs>EscapeApos</lhs><rhs>"''"</rhs></prod><prod num="182" id="prod-xquery-ElementContentChar"><lhs>ElementContentChar</lhs><rhs><nt def="prod-xquery-Char">Char</nt> - [{}&lt;&amp;]</rhs></prod><prod num="183" id="prod-xquery-QuotAttrContentChar"><lhs>QuotAttrContentChar</lhs><rhs><nt def="prod-xquery-Char">Char</nt> - ["{}&lt;&amp;]</rhs></prod><prod num="184" id="prod-xquery-AposAttrContentChar"><lhs>AposAttrContentChar</lhs><rhs><nt def="prod-xquery-Char">Char</nt> - ['{}&lt;&amp;]</rhs></prod><prod num="185" id="prod-xquery-Comment"><lhs>Comment</lhs><rhs>"(:"  (<nt def="prod-xquery-CommentContents">CommentContents</nt>  |  <nt def="prod-xquery-Comment">Comment</nt>)*  ":)"</rhs><com><phrase><xspecref ref="ws-explicit" spec="XQ">ws: explicit</xspecref></phrase></com><com><phrase><xspecref ref="parse-note-comments" spec="XQ">gn: comments</xspecref></phrase></com></prod><prod num="186" id="prod-xquery-PITarget"><lhs>PITarget</lhs><rhs><xnt spec="XML" ref="NT-PITarget">[http://www.w3.org/TR/REC-xml#NT-PITarget]</xnt></rhs><com><phrase><xspecref ref="parse-note-xml-version" spec="XQ">gn: xml-version</xspecref></phrase></com></prod><prod num="187" id="prod-xquery-CharRef"><lhs>CharRef</lhs><rhs><xnt spec="XML" ref="NT-CharRef">[http://www.w3.org/TR/REC-xml#NT-CharRef]</xnt></rhs><com><phrase><xspecref ref="parse-note-xml-version" spec="XQ">gn: xml-version</xspecref></phrase></com></prod><prod num="188" id="prod-xquery-QName"><lhs>QName</lhs><rhs><xnt spec="Names" ref="NT-QName">[http://www.w3.org/TR/REC-xml-names/#NT-QName]</xnt></rhs><com><phrase><xspecref ref="parse-note-xml-version" spec="XQ">gn: xml-version</xspecref></phrase></com></prod><prod num="189" id="prod-xquery-NCName"><lhs>NCName</lhs><rhs><xnt spec="Names" ref="NT-NCName">[http://www.w3.org/TR/REC-xml-names/#NT-NCName]</xnt></rhs><com><phrase><xspecref ref="parse-note-xml-version" spec="XQ">gn: xml-version</xspecref></phrase></com></prod><prod num="190" id="prod-xquery-S"><lhs>S</lhs><rhs><xnt spec="XML" ref="NT-S">[http://www.w3.org/TR/REC-xml#NT-S]</xnt></rhs><com><phrase><xspecref ref="parse-note-xml-version" spec="XQ">gn: xml-version</xspecref></phrase></com></prod><prod num="191" id="prod-xquery-Char"><lhs>Char</lhs><rhs><xnt spec="XML" ref="NT-Char">[http://www.w3.org/TR/REC-xml#NT-Char]</xnt></rhs><com><phrase><xspecref ref="parse-note-xml-version" spec="XQ">gn: xml-version</xspecref></phrase></com></prod> 
		   
		</scrap>
<p>The following symbols are used only in the definition of
  terminal symbols; they are not terminal symbols in the
  grammar of <specref ref="id-grammar"/>.</p><scrap headstyle="show">
		    
		  <head/><prod num="192" id="prod-xquery-Digits"><lhs>Digits</lhs><rhs>[0-9]+</rhs></prod><prod num="193" id="prod-xquery-CommentContents"><lhs>CommentContents</lhs><rhs>(<nt def="prod-xquery-Char">Char</nt>+ - (Char* ('(:' | ':)') Char*))</rhs></prod> 
		   
		</scrap>
</div2></div1>

	
<div1 id="id-xpath-grammar">
		<head>EBNF for XPath 2.0 Grammar with Full-Text
		extensions</head>

<p>The EBNF in this document and in this section is aligned with
the current XPath 2.0 grammar (see <loc xmlns:xlink="http://www.w3.org/1999/xlink" href="http://www.w3.org/TR/2005/CR-xpath20-20051103/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">http://www.w3.org/TR/2005/CR-xpath20-20051103/</loc>).</p>

		<scrap role="non-terminal-structure-expand" headstyle="show"><head/>
<prod num="1" id="prod-xpath-XPath"><lhs>XPath</lhs><rhs><nt def="prod-xpath-Expr">Expr</nt></rhs></prod><prod num="2" id="prod-xpath-Expr"><lhs>Expr</lhs><rhs><nt def="prod-xpath-ExprSingle">ExprSingle</nt>  (","  <nt def="prod-xpath-ExprSingle">ExprSingle</nt>)*</rhs></prod><prod num="3" id="prod-xpath-ExprSingle"><lhs>ExprSingle</lhs><rhs><nt def="prod-xpath-ForExpr">ForExpr</nt><br/>|  <nt def="prod-xpath-QuantifiedExpr">QuantifiedExpr</nt><br/>|  <nt def="prod-xpath-IfExpr">IfExpr</nt><br/>|  <nt def="prod-xpath-OrExpr">OrExpr</nt></rhs></prod><prod num="4" id="prod-xpath-ForExpr"><lhs>ForExpr</lhs><rhs><nt def="prod-xpath-SimpleForClause">SimpleForClause</nt>  "return"  <nt def="prod-xpath-ExprSingle">ExprSingle</nt></rhs></prod><prod num="5" id="prod-xpath-SimpleForClause"><lhs>SimpleForClause</lhs><rhs>"for"  "$"  <nt def="prod-xpath-VarName">VarName</nt>  <nt def="prod-xpath-FTScoreVar">FTScoreVar</nt>?  "in"  <nt def="prod-xpath-ExprSingle">ExprSingle</nt>  (","  "$"  <nt def="prod-xpath-VarName">VarName</nt>  <nt def="prod-xpath-FTScoreVar">FTScoreVar</nt>?  "in"  <nt def="prod-xpath-ExprSingle">ExprSingle</nt>)*</rhs></prod><prod num="6" id="prod-xpath-FTScoreVar"><lhs>FTScoreVar</lhs><rhs>"score"  "$"  <nt def="prod-xpath-VarName">VarName</nt></rhs></prod><prod num="7" id="prod-xpath-QuantifiedExpr"><lhs>QuantifiedExpr</lhs><rhs>("some"  |  "every")  "$"  <nt def="prod-xpath-VarName">VarName</nt>  "in"  <nt def="prod-xpath-ExprSingle">ExprSingle</nt>  (","  "$"  <nt def="prod-xpath-VarName">VarName</nt>  "in"  <nt def="prod-xpath-ExprSingle">ExprSingle</nt>)*  "satisfies"  <nt def="prod-xpath-ExprSingle">ExprSingle</nt></rhs></prod><prod num="8" id="prod-xpath-IfExpr"><lhs>IfExpr</lhs><rhs>"if"  "("  <nt def="prod-xpath-Expr">Expr</nt>  ")"  "then"  <nt def="prod-xpath-ExprSingle">ExprSingle</nt>  "else"  <nt def="prod-xpath-ExprSingle">ExprSingle</nt></rhs></prod><prod num="9" id="prod-xpath-OrExpr"><lhs>OrExpr</lhs><rhs><nt def="prod-xpath-AndExpr">AndExpr</nt> ( "or"  <nt def="prod-xpath-AndExpr">AndExpr</nt> )*</rhs></prod><prod num="10" id="prod-xpath-AndExpr"><lhs>AndExpr</lhs><rhs><nt def="prod-xpath-ComparisonExpr">ComparisonExpr</nt> ( "and"  <nt def="prod-xpath-ComparisonExpr">ComparisonExpr</nt> )*</rhs></prod><prod num="11" id="prod-xpath-ComparisonExpr"><lhs>ComparisonExpr</lhs><rhs><nt def="prod-xpath-FTContainsExpr">FTContainsExpr</nt> ( (<nt def="prod-xpath-ValueComp">ValueComp</nt><br/>|  <nt def="prod-xpath-GeneralComp">GeneralComp</nt><br/>|  <nt def="prod-xpath-NodeComp">NodeComp</nt>)  <nt def="prod-xpath-FTContainsExpr">FTContainsExpr</nt> )?</rhs></prod><prod num="12" id="prod-xpath-FTContainsExpr"><lhs>FTContainsExpr</lhs><rhs><nt def="prod-xpath-RangeExpr">RangeExpr</nt> ( "ftcontains"  <nt def="prod-xpath-FTSelection">FTSelection</nt>  <nt def="prod-xpath-FTIgnoreOption">FTIgnoreOption</nt>? )?</rhs></prod><prod num="13" id="prod-xpath-RangeExpr"><lhs>RangeExpr</lhs><rhs><nt def="prod-xpath-AdditiveExpr">AdditiveExpr</nt> ( "to"  <nt def="prod-xpath-AdditiveExpr">AdditiveExpr</nt> )?</rhs></prod><prod num="14" id="prod-xpath-AdditiveExpr"><lhs>AdditiveExpr</lhs><rhs><nt def="prod-xpath-MultiplicativeExpr">MultiplicativeExpr</nt> ( ("+"  |  "-")  <nt def="prod-xpath-MultiplicativeExpr">MultiplicativeExpr</nt> )*</rhs></prod><prod num="15" id="prod-xpath-MultiplicativeExpr"><lhs>MultiplicativeExpr</lhs><rhs><nt def="prod-xpath-UnionExpr">UnionExpr</nt> ( ("*"  |  "div"  |  "idiv"  |  "mod")  <nt def="prod-xpath-UnionExpr">UnionExpr</nt> )*</rhs></prod><prod num="16" id="prod-xpath-UnionExpr"><lhs>UnionExpr</lhs><rhs><nt def="prod-xpath-IntersectExceptExpr">IntersectExceptExpr</nt> ( ("union"  |  "|")  <nt def="prod-xpath-IntersectExceptExpr">IntersectExceptExpr</nt> )*</rhs></prod><prod num="17" id="prod-xpath-IntersectExceptExpr"><lhs>IntersectExceptExpr</lhs><rhs><nt def="prod-xpath-InstanceofExpr">InstanceofExpr</nt> ( ("intersect"  |  "except")  <nt def="prod-xpath-InstanceofExpr">InstanceofExpr</nt> )*</rhs></prod><prod num="18" id="prod-xpath-InstanceofExpr"><lhs>InstanceofExpr</lhs><rhs><nt def="prod-xpath-TreatExpr">TreatExpr</nt> ( "instance"  "of"  <nt def="prod-xpath-SequenceType">SequenceType</nt> )?</rhs></prod><prod num="19" id="prod-xpath-TreatExpr"><lhs>TreatExpr</lhs><rhs><nt def="prod-xpath-CastableExpr">CastableExpr</nt> ( "treat"  "as"  <nt def="prod-xpath-SequenceType">SequenceType</nt> )?</rhs></prod><prod num="20" id="prod-xpath-CastableExpr"><lhs>CastableExpr</lhs><rhs><nt def="prod-xpath-CastExpr">CastExpr</nt> ( "castable"  "as"  <nt def="prod-xpath-SingleType">SingleType</nt> )?</rhs></prod><prod num="21" id="prod-xpath-CastExpr"><lhs>CastExpr</lhs><rhs><nt def="prod-xpath-UnaryExpr">UnaryExpr</nt> ( "cast"  "as"  <nt def="prod-xpath-SingleType">SingleType</nt> )?</rhs></prod><prod num="22" id="prod-xpath-UnaryExpr"><lhs>UnaryExpr</lhs><rhs>("-"  |  "+")* <nt def="prod-xpath-ValueExpr">ValueExpr</nt></rhs></prod><prod num="23" id="prod-xpath-ValueExpr"><lhs>ValueExpr</lhs><rhs><nt def="prod-xpath-PathExpr">PathExpr</nt></rhs></prod><prod num="24" id="prod-xpath-GeneralComp"><lhs>GeneralComp</lhs><rhs>"="  |  "!="  |  "&lt;"  |  "&lt;="  |  "&gt;"  |  "&gt;="</rhs></prod><prod num="25" id="prod-xpath-ValueComp"><lhs>ValueComp</lhs><rhs>"eq"  |  "ne"  |  "lt"  |  "le"  |  "gt"  |  "ge"</rhs></prod><prod num="26" id="prod-xpath-NodeComp"><lhs>NodeComp</lhs><rhs>"is"  |  "&lt;&lt;"  |  "&gt;&gt;"</rhs></prod><prod num="27" id="prod-xpath-PathExpr"><lhs>PathExpr</lhs><rhs>("/"  <nt def="prod-xpath-RelativePathExpr">RelativePathExpr</nt>?)<br/>|  ("//"  <nt def="prod-xpath-RelativePathExpr">RelativePathExpr</nt>)<br/>|  <nt def="prod-xpath-RelativePathExpr">RelativePathExpr</nt></rhs><com><phrase><xspecref ref="parse-note-leading-lone-slash" spec="XP">gn: leading-lone-slash</xspecref></phrase></com></prod><prod num="28" id="prod-xpath-RelativePathExpr"><lhs>RelativePathExpr</lhs><rhs><nt def="prod-xpath-StepExpr">StepExpr</nt>  (("/"  |  "//")  <nt def="prod-xpath-StepExpr">StepExpr</nt>)*</rhs></prod><prod num="29" id="prod-xpath-StepExpr"><lhs>StepExpr</lhs><rhs><nt def="prod-xpath-FilterExpr">FilterExpr</nt>  |  <nt def="prod-xpath-AxisStep">AxisStep</nt></rhs></prod><prod num="30" id="prod-xpath-AxisStep"><lhs>AxisStep</lhs><rhs>(<nt def="prod-xpath-ReverseStep">ReverseStep</nt>  |  <nt def="prod-xpath-ForwardStep">ForwardStep</nt>)  <nt def="prod-xpath-PredicateList">PredicateList</nt></rhs></prod><prod num="31" id="prod-xpath-ForwardStep"><lhs>ForwardStep</lhs><rhs>(<nt def="prod-xpath-ForwardAxis">ForwardAxis</nt>  <nt def="prod-xpath-NodeTest">NodeTest</nt>)  |  <nt def="prod-xpath-AbbrevForwardStep">AbbrevForwardStep</nt></rhs></prod><prod num="32" id="prod-xpath-ForwardAxis"><lhs>ForwardAxis</lhs><rhs>("child"  "::")<br/>|  ("descendant"  "::")<br/>|  ("attribute"  "::")<br/>|  ("self"  "::")<br/>|  ("descendant-or-self"  "::")<br/>|  ("following-sibling"  "::")<br/>|  ("following"  "::")<br/>|  ("namespace"  "::")</rhs></prod><prod num="33" id="prod-xpath-AbbrevForwardStep"><lhs>AbbrevForwardStep</lhs><rhs>"@"?  <nt def="prod-xpath-NodeTest">NodeTest</nt></rhs></prod><prod num="34" id="prod-xpath-ReverseStep"><lhs>ReverseStep</lhs><rhs>(<nt def="prod-xpath-ReverseAxis">ReverseAxis</nt>  <nt def="prod-xpath-NodeTest">NodeTest</nt>)  |  <nt def="prod-xpath-AbbrevReverseStep">AbbrevReverseStep</nt></rhs></prod><prod num="35" id="prod-xpath-ReverseAxis"><lhs>ReverseAxis</lhs><rhs>("parent"  "::")<br/>|  ("ancestor"  "::")<br/>|  ("preceding-sibling"  "::")<br/>|  ("preceding"  "::")<br/>|  ("ancestor-or-self"  "::")</rhs></prod><prod num="36" id="prod-xpath-AbbrevReverseStep"><lhs>AbbrevReverseStep</lhs><rhs>".."</rhs></prod><prod num="37" id="prod-xpath-NodeTest"><lhs>NodeTest</lhs><rhs><nt def="prod-xpath-KindTest">KindTest</nt>  |  <nt def="prod-xpath-NameTest">NameTest</nt></rhs></prod><prod num="38" id="prod-xpath-NameTest"><lhs>NameTest</lhs><rhs><nt def="prod-xpath-QName">QName</nt>  |  <nt def="prod-xpath-Wildcard">Wildcard</nt></rhs></prod><prod num="39" id="prod-xpath-Wildcard"><lhs>Wildcard</lhs><rhs>"*"<br/>|  (<nt def="prod-xpath-NCName">NCName</nt>  ":"  "*")<br/>|  ("*"  ":"  <nt def="prod-xpath-NCName">NCName</nt>)</rhs><com><phrase><xspecref ref="ws-explicit" spec="XP">ws: explicit</xspecref></phrase></com></prod><prod num="40" id="prod-xpath-FilterExpr"><lhs>FilterExpr</lhs><rhs><nt def="prod-xpath-PrimaryExpr">PrimaryExpr</nt>  <nt def="prod-xpath-PredicateList">PredicateList</nt></rhs></prod><prod num="41" id="prod-xpath-PredicateList"><lhs>PredicateList</lhs><rhs><nt def="prod-xpath-Predicate">Predicate</nt>*</rhs></prod><prod num="42" id="prod-xpath-Predicate"><lhs>Predicate</lhs><rhs>"["  <nt def="prod-xpath-Expr">Expr</nt>  "]"</rhs></prod><prod num="43" id="prod-xpath-PrimaryExpr"><lhs>PrimaryExpr</lhs><rhs><nt def="prod-xpath-Literal">Literal</nt>  |  <nt def="prod-xpath-VarRef">VarRef</nt>  |  <nt def="prod-xpath-ParenthesizedExpr">ParenthesizedExpr</nt>  |  <nt def="prod-xpath-ContextItemExpr">ContextItemExpr</nt>  |  <nt def="prod-xpath-FunctionCall">FunctionCall</nt></rhs></prod><prod num="44" id="prod-xpath-Literal"><lhs>Literal</lhs><rhs><nt def="prod-xpath-NumericLiteral">NumericLiteral</nt>  |  <nt def="prod-xpath-StringLiteral">StringLiteral</nt></rhs></prod><prod num="45" id="prod-xpath-NumericLiteral"><lhs>NumericLiteral</lhs><rhs><nt def="prod-xpath-IntegerLiteral">IntegerLiteral</nt>  |  <nt def="prod-xpath-DecimalLiteral">DecimalLiteral</nt>  |  <nt def="prod-xpath-DoubleLiteral">DoubleLiteral</nt></rhs></prod><prod num="46" id="prod-xpath-VarRef"><lhs>VarRef</lhs><rhs>"$"  <nt def="prod-xpath-VarName">VarName</nt></rhs></prod><prod num="47" id="prod-xpath-VarName"><lhs>VarName</lhs><rhs><nt def="prod-xpath-QName">QName</nt></rhs></prod><prod num="48" id="prod-xpath-ParenthesizedExpr"><lhs>ParenthesizedExpr</lhs><rhs>"("  <nt def="prod-xpath-Expr">Expr</nt>?  ")"</rhs></prod><prod num="49" id="prod-xpath-ContextItemExpr"><lhs>ContextItemExpr</lhs><rhs>"."</rhs></prod><prod num="50" id="prod-xpath-FunctionCall"><lhs>FunctionCall</lhs><rhs><nt def="prod-xpath-QName">QName</nt>  "("  (<nt def="prod-xpath-ExprSingle">ExprSingle</nt>  (","  <nt def="prod-xpath-ExprSingle">ExprSingle</nt>)*)?  ")"</rhs><com><phrase><xspecref ref="parse-note-reserved-function-names" spec="XP">gn: reserved-function-names</xspecref></phrase></com><com><phrase><xspecref ref="parse-note-parens" spec="XP">gn: parens</xspecref></phrase></com></prod><prod num="51" id="prod-xpath-SingleType"><lhs>SingleType</lhs><rhs><nt def="prod-xpath-AtomicType">AtomicType</nt>  "?"?</rhs></prod><prod num="52" id="prod-xpath-SequenceType"><lhs>SequenceType</lhs><rhs>("empty-sequence"  "("  ")")<br/>|  (<nt def="prod-xpath-ItemType">ItemType</nt>  <nt def="prod-xpath-OccurrenceIndicator">OccurrenceIndicator</nt>?)</rhs></prod><prod num="53" id="prod-xpath-OccurrenceIndicator"><lhs>OccurrenceIndicator</lhs><rhs>"?"  |  "*"  |  "+"</rhs><com><phrase><xspecref ref="parse-note-occurrence-indicators" spec="XP">gn: occurrence-indicators</xspecref></phrase></com></prod><prod num="54" id="prod-xpath-ItemType"><lhs>ItemType</lhs><rhs><nt def="prod-xpath-KindTest">KindTest</nt>  |  ("item"  "("  ")")  |  <nt def="prod-xpath-AtomicType">AtomicType</nt></rhs></prod><prod num="55" id="prod-xpath-AtomicType"><lhs>AtomicType</lhs><rhs><nt def="prod-xpath-QName">QName</nt></rhs></prod><prod num="56" id="prod-xpath-KindTest"><lhs>KindTest</lhs><rhs><nt def="prod-xpath-DocumentTest">DocumentTest</nt><br/>|  <nt def="prod-xpath-ElementTest">ElementTest</nt><br/>|  <nt def="prod-xpath-AttributeTest">AttributeTest</nt><br/>|  <nt def="prod-xpath-SchemaElementTest">SchemaElementTest</nt><br/>|  <nt def="prod-xpath-SchemaAttributeTest">SchemaAttributeTest</nt><br/>|  <nt def="prod-xpath-PITest">PITest</nt><br/>|  <nt def="prod-xpath-CommentTest">CommentTest</nt><br/>|  <nt def="prod-xpath-TextTest">TextTest</nt><br/>|  <nt def="prod-xpath-AnyKindTest">AnyKindTest</nt></rhs></prod><prod num="57" id="prod-xpath-AnyKindTest"><lhs>AnyKindTest</lhs><rhs>"node"  "("  ")"</rhs></prod><prod num="58" id="prod-xpath-DocumentTest"><lhs>DocumentTest</lhs><rhs>"document-node"  "("  (<nt def="prod-xpath-ElementTest">ElementTest</nt>  |  <nt def="prod-xpath-SchemaElementTest">SchemaElementTest</nt>)?  ")"</rhs></prod><prod num="59" id="prod-xpath-TextTest"><lhs>TextTest</lhs><rhs>"text"  "("  ")"</rhs></prod><prod num="60" id="prod-xpath-CommentTest"><lhs>CommentTest</lhs><rhs>"comment"  "("  ")"</rhs></prod><prod num="61" id="prod-xpath-PITest"><lhs>PITest</lhs><rhs>"processing-instruction"  "("  (<nt def="prod-xpath-NCName">NCName</nt>  |  <nt def="prod-xpath-StringLiteral">StringLiteral</nt>)?  ")"</rhs></prod><prod num="62" id="prod-xpath-AttributeTest"><lhs>AttributeTest</lhs><rhs>"attribute"  "("  (<nt def="prod-xpath-AttribNameOrWildcard">AttribNameOrWildcard</nt>  (","  <nt def="prod-xpath-TypeName">TypeName</nt>)?)?  ")"</rhs></prod><prod num="63" id="prod-xpath-AttribNameOrWildcard"><lhs>AttribNameOrWildcard</lhs><rhs><nt def="prod-xpath-AttributeName">AttributeName</nt>  |  "*"</rhs></prod><prod num="64" id="prod-xpath-SchemaAttributeTest"><lhs>SchemaAttributeTest</lhs><rhs>"schema-attribute"  "("  <nt def="prod-xpath-AttributeDeclaration">AttributeDeclaration</nt>  ")"</rhs></prod><prod num="65" id="prod-xpath-AttributeDeclaration"><lhs>AttributeDeclaration</lhs><rhs><nt def="prod-xpath-AttributeName">AttributeName</nt></rhs></prod><prod num="66" id="prod-xpath-ElementTest"><lhs>ElementTest</lhs><rhs>"element"  "("  (<nt def="prod-xpath-ElementNameOrWildcard">ElementNameOrWildcard</nt>  (","  <nt def="prod-xpath-TypeName">TypeName</nt>  "?"?)?)?  ")"</rhs></prod><prod num="67" id="prod-xpath-ElementNameOrWildcard"><lhs>ElementNameOrWildcard</lhs><rhs><nt def="prod-xpath-ElementName">ElementName</nt>  |  "*"</rhs></prod><prod num="68" id="prod-xpath-SchemaElementTest"><lhs>SchemaElementTest</lhs><rhs>"schema-element"  "("  <nt def="prod-xpath-ElementDeclaration">ElementDeclaration</nt>  ")"</rhs></prod><prod num="69" id="prod-xpath-ElementDeclaration"><lhs>ElementDeclaration</lhs><rhs><nt def="prod-xpath-ElementName">ElementName</nt></rhs></prod><prod num="70" id="prod-xpath-AttributeName"><lhs>AttributeName</lhs><rhs><nt def="prod-xpath-QName">QName</nt></rhs></prod><prod num="71" id="prod-xpath-ElementName"><lhs>ElementName</lhs><rhs><nt def="prod-xpath-QName">QName</nt></rhs></prod><prod num="72" id="prod-xpath-TypeName"><lhs>TypeName</lhs><rhs><nt def="prod-xpath-QName">QName</nt></rhs></prod><prod num="73" id="prod-xpath-FTSelection"><lhs>FTSelection</lhs><rhs><nt def="prod-xpath-FTOr">FTOr</nt>  (<nt def="prod-xpath-FTMatchOption">FTMatchOption</nt>  |  <nt def="prod-xpath-FTProximity">FTProximity</nt>)*  ("weight"  <nt def="prod-xpath-RangeExpr">RangeExpr</nt>)?</rhs></prod><prod num="74" id="prod-xpath-FTOr"><lhs>FTOr</lhs><rhs><nt def="prod-xpath-FTAnd">FTAnd</nt> ( "||"  <nt def="prod-xpath-FTAnd">FTAnd</nt> )*</rhs></prod><prod num="75" id="prod-xpath-FTAnd"><lhs>FTAnd</lhs><rhs><nt def="prod-xpath-FTMildnot">FTMildnot</nt> ( "&amp;&amp;"  <nt def="prod-xpath-FTMildnot">FTMildnot</nt> )*</rhs></prod><prod num="76" id="prod-xpath-FTMildnot"><lhs>FTMildnot</lhs><rhs><nt def="prod-xpath-FTUnaryNot">FTUnaryNot</nt> ( "not"  "in"  <nt def="prod-xpath-FTUnaryNot">FTUnaryNot</nt> )*</rhs></prod><prod num="77" id="prod-xpath-FTUnaryNot"><lhs>FTUnaryNot</lhs><rhs>("!")? <nt def="prod-xpath-FTWordsSelection">FTWordsSelection</nt></rhs></prod><prod num="78" id="prod-xpath-FTWordsSelection"><lhs>FTWordsSelection</lhs><rhs>(<nt def="prod-xpath-FTWords">FTWords</nt>  <nt def="prod-xpath-FTTimes">FTTimes</nt>?)  |  ("("  <nt def="prod-xpath-FTSelection">FTSelection</nt>  ")")</rhs></prod><prod num="79" id="prod-xpath-FTWords"><lhs>FTWords</lhs><rhs><nt def="prod-xpath-FTWordsValue">FTWordsValue</nt>  <nt def="prod-xpath-FTAnyallOption">FTAnyallOption</nt>?</rhs></prod><prod num="80" id="prod-xpath-FTWordsValue"><lhs>FTWordsValue</lhs><rhs><nt def="prod-xpath-Literal">Literal</nt>  |  ("{"  <nt def="prod-xpath-Expr">Expr</nt>  "}")</rhs></prod><prod num="81" id="prod-xpath-FTProximity"><lhs>FTProximity</lhs><rhs><nt def="prod-xpath-FTOrderedIndicator">FTOrderedIndicator</nt>  |  <nt def="prod-xpath-FTWindow">FTWindow</nt>  |  <nt def="prod-xpath-FTDistance">FTDistance</nt>  |  <nt def="prod-xpath-FTScope">FTScope</nt>  |  <nt def="prod-xpath-FTContent">FTContent</nt></rhs></prod><prod num="82" id="prod-xpath-FTOrderedIndicator"><lhs>FTOrderedIndicator</lhs><rhs>"ordered"</rhs></prod><prod num="83" id="prod-xpath-FTMatchOption"><lhs>FTMatchOption</lhs><rhs><nt def="prod-xpath-FTCaseOption">FTCaseOption</nt><br/>|  <nt def="prod-xpath-FTDiacriticsOption">FTDiacriticsOption</nt><br/>|  <nt def="prod-xpath-FTStemOption">FTStemOption</nt><br/>|  <nt def="prod-xpath-FTThesaurusOption">FTThesaurusOption</nt><br/>|  <nt def="prod-xpath-FTStopwordOption">FTStopwordOption</nt><br/>|  <nt def="prod-xpath-FTLanguageOption">FTLanguageOption</nt><br/>|  <nt def="prod-xpath-FTWildCardOption">FTWildCardOption</nt></rhs></prod><prod num="84" id="prod-xpath-FTCaseOption"><lhs>FTCaseOption</lhs><rhs>"lowercase"<br/>|  "uppercase"<br/>|  ("case"  "sensitive")<br/>|  ("case"  "insensitive")</rhs></prod><prod num="85" id="prod-xpath-FTDiacriticsOption"><lhs>FTDiacriticsOption</lhs><rhs>("with"  "diacritics")<br/>|  ("without"  "diacritics")<br/>|  ("diacritics"  "sensitive")<br/>|  ("diacritics"  "insensitive")</rhs></prod><prod num="86" id="prod-xpath-FTStemOption"><lhs>FTStemOption</lhs><rhs>("with"  "stemming")  |  ("without"  "stemming")</rhs></prod><prod num="87" id="prod-xpath-FTThesaurusOption"><lhs>FTThesaurusOption</lhs><rhs>("with"  "thesaurus"  (<nt def="prod-xpath-FTThesaurusID">FTThesaurusID</nt>  |  "default"))<br/>|  ("with"  "thesaurus"  "("  (<nt def="prod-xpath-FTThesaurusID">FTThesaurusID</nt>  |  "default")  (","  <nt def="prod-xpath-FTThesaurusID">FTThesaurusID</nt>)*  ")")<br/>|  ("without"  "thesaurus")</rhs></prod><prod num="88" id="prod-xpath-FTThesaurusID"><lhs>FTThesaurusID</lhs><rhs>"at"  <nt def="prod-xpath-StringLiteral">StringLiteral</nt>  ("relationship"  <nt def="prod-xpath-StringLiteral">StringLiteral</nt>)?  (<nt def="prod-xpath-FTRange">FTRange</nt>  "levels")?</rhs></prod><prod num="89" id="prod-xpath-FTStopwordOption"><lhs>FTStopwordOption</lhs><rhs>("with"  "stop"  "words"  <nt def="prod-xpath-FTRefOrList">FTRefOrList</nt>  <nt def="prod-xpath-FTInclExclStringLiteral">FTInclExclStringLiteral</nt>*)<br/>|  ("without"  "stop"  "words")<br/>|  ("with"  "default"  "stop"  "words"  <nt def="prod-xpath-FTInclExclStringLiteral">FTInclExclStringLiteral</nt>*)</rhs></prod><prod num="90" id="prod-xpath-FTRefOrList"><lhs>FTRefOrList</lhs><rhs>("at"  <nt def="prod-xpath-StringLiteral">StringLiteral</nt>)<br/>|  ("("  <nt def="prod-xpath-StringLiteral">StringLiteral</nt>  (","  <nt def="prod-xpath-StringLiteral">StringLiteral</nt>)*  ")")</rhs></prod><prod num="91" id="prod-xpath-FTInclExclStringLiteral"><lhs>FTInclExclStringLiteral</lhs><rhs>("union"  |  "except")  <nt def="prod-xpath-FTRefOrList">FTRefOrList</nt></rhs></prod><prod num="92" id="prod-xpath-FTLanguageOption"><lhs>FTLanguageOption</lhs><rhs>"language"  <nt def="prod-xpath-StringLiteral">StringLiteral</nt></rhs></prod><prod num="93" id="prod-xpath-FTWildCardOption"><lhs>FTWildCardOption</lhs><rhs>("with"  "wildcards")  |  ("without"  "wildcards")</rhs></prod><prod num="94" id="prod-xpath-FTContent"><lhs>FTContent</lhs><rhs>("at"  "start")  |  ("at"  "end")  |  ("entire"  "content")</rhs></prod><prod num="95" id="prod-xpath-FTAnyallOption"><lhs>FTAnyallOption</lhs><rhs>("any"  "word"?)  |  ("all"  "words"?)  |  "phrase"</rhs></prod><prod num="96" id="prod-xpath-FTRange"><lhs>FTRange</lhs><rhs>("exactly"  <nt def="prod-xpath-UnionExpr">UnionExpr</nt>)<br/>|  ("at"  "least"  <nt def="prod-xpath-UnionExpr">UnionExpr</nt>)<br/>|  ("at"  "most"  <nt def="prod-xpath-UnionExpr">UnionExpr</nt>)<br/>|  ("from"  <nt def="prod-xpath-UnionExpr">UnionExpr</nt>  "to"  <nt def="prod-xpath-UnionExpr">UnionExpr</nt>)</rhs></prod><prod num="97" id="prod-xpath-FTDistance"><lhs>FTDistance</lhs><rhs>"distance"  <nt def="prod-xpath-FTRange">FTRange</nt>  <nt def="prod-xpath-FTUnit">FTUnit</nt></rhs></prod><prod num="98" id="prod-xpath-FTWindow"><lhs>FTWindow</lhs><rhs>"window"  <nt def="prod-xpath-UnionExpr">UnionExpr</nt>  <nt def="prod-xpath-FTUnit">FTUnit</nt></rhs></prod><prod num="99" id="prod-xpath-FTTimes"><lhs>FTTimes</lhs><rhs>"occurs"  <nt def="prod-xpath-FTRange">FTRange</nt>  "times"</rhs></prod><prod num="100" id="prod-xpath-FTScope"><lhs>FTScope</lhs><rhs>("same"  |  "different")  <nt def="prod-xpath-FTBigUnit">FTBigUnit</nt></rhs></prod><prod num="101" id="prod-xpath-FTUnit"><lhs>FTUnit</lhs><rhs>"words"  |  "sentences"  |  "paragraphs"</rhs></prod><prod num="102" id="prod-xpath-FTBigUnit"><lhs>FTBigUnit</lhs><rhs>"sentence"  |  "paragraph"</rhs></prod><prod num="103" id="prod-xpath-FTIgnoreOption"><lhs>FTIgnoreOption</lhs><rhs>"without"  "content"  <nt def="prod-xpath-UnionExpr">UnionExpr</nt></rhs></prod>
</scrap>

<div2 id="xpath-grammar-terminals"><head>Terminal Symbols</head><scrap headstyle="show">
		    
		  <head/><prod num="104" id="prod-xpath-IntegerLiteral"><lhs>IntegerLiteral</lhs><rhs><nt def="prod-xpath-Digits">Digits</nt></rhs></prod><prod num="105" id="prod-xpath-DecimalLiteral"><lhs>DecimalLiteral</lhs><rhs>("."  <nt def="prod-xpath-Digits">Digits</nt>)  |  (<nt def="prod-xpath-Digits">Digits</nt>  "."  [0-9]*)</rhs><com><phrase><xspecref ref="ws-explicit" spec="XP">ws: explicit</xspecref></phrase></com></prod><prod num="106" id="prod-xpath-DoubleLiteral"><lhs>DoubleLiteral</lhs><rhs>(("."  <nt def="prod-xpath-Digits">Digits</nt>)  |  (<nt def="prod-xpath-Digits">Digits</nt>  ("."  [0-9]*)?))  [eE]  [+-]?  <nt def="prod-xpath-Digits">Digits</nt></rhs><com><phrase><xspecref ref="ws-explicit" spec="XP">ws: explicit</xspecref></phrase></com></prod><prod num="107" id="prod-xpath-StringLiteral"><lhs>StringLiteral</lhs><rhs>('"'  (<nt def="prod-xpath-EscapeQuot">EscapeQuot</nt>  |  [^"])*  '"')  |  ("'"  (<nt def="prod-xpath-EscapeApos">EscapeApos</nt>  |  [^'])*  "'")</rhs><com><phrase><xspecref ref="ws-explicit" spec="XP">ws: explicit</xspecref></phrase></com></prod><prod num="108" id="prod-xpath-EscapeQuot"><lhs>EscapeQuot</lhs><rhs>'""'</rhs></prod><prod num="109" id="prod-xpath-EscapeApos"><lhs>EscapeApos</lhs><rhs>"''"</rhs></prod><prod num="110" id="prod-xpath-Comment"><lhs>Comment</lhs><rhs>"(:"  (<nt def="prod-xpath-CommentContents">CommentContents</nt>  |  <nt def="prod-xpath-Comment">Comment</nt>)*  ":)"</rhs><com><phrase><xspecref ref="ws-explicit" spec="XP">ws: explicit</xspecref></phrase></com><com><phrase><xspecref ref="parse-note-comments" spec="XP">gn: comments</xspecref></phrase></com></prod><prod num="111" id="prod-xpath-QName"><lhs>QName</lhs><rhs><xnt spec="Names" ref="NT-QName">[http://www.w3.org/TR/REC-xml-names/#NT-QName]</xnt></rhs><com><phrase><xspecref ref="parse-note-xml-version" spec="XP">gn: xml-version</xspecref></phrase></com></prod><prod num="112" id="prod-xpath-NCName"><lhs>NCName</lhs><rhs><xnt spec="Names" ref="NT-NCName">[http://www.w3.org/TR/REC-xml-names/#NT-NCName]</xnt></rhs><com><phrase><xspecref ref="parse-note-xml-version" spec="XP">gn: xml-version</xspecref></phrase></com></prod><prod num="113" id="prod-xpath-Char"><lhs>Char</lhs><rhs><xnt spec="XML" ref="NT-Char">[http://www.w3.org/TR/REC-xml#NT-Char]</xnt></rhs><com><phrase><xspecref ref="parse-note-xml-version" spec="XP">gn: xml-version</xspecref></phrase></com></prod> 
		   
		</scrap>
<p>The following symbols are used only in the definition of
  terminal symbols; they are not terminal symbols in the
  grammar of <specref ref="id-xpath-grammar"/>.</p><scrap headstyle="show">
		    
		  <head/><prod num="114" id="prod-xpath-Digits"><lhs>Digits</lhs><rhs>[0-9]+</rhs></prod><prod num="115" id="prod-xpath-CommentContents"><lhs>CommentContents</lhs><rhs>(<nt def="prod-xpath-Char">Char</nt>+ - (Char* ('(:' | ':)') Char*))</rhs></prod> 
		   
		</scrap>
</div2></div1>

  
<!-- JD
<div1 role="xquery" id="id-xqft-context-components"><head>Context
Components</head><p>The tables in this section describe how values are
assigned to the various components of the static context and dynamic
context, and to the parameters that control the serialization
process.</p>
-->

<div1 id="id-xqft-static-context-components"><head>Static Context
Components</head><p>The following table describes the full-text components of
the <term>static context</term> (see <xspecref spec="XQ" ref="dt-static-context"/>). The following aspects of each
component are described:</p><ulist><item><p><emph>Default initial
value:</emph> This is the initial value of the component if it is not
overridden or augmented by the implementation or by a query.</p>
</item>
<item><p><emph>Can be overwritten or augmented by
implementation:</emph> Indicates whether an XQuery implementation is
allowed to replace the default initial value of the component by a
different, <term>implementation-defined</term> (for a definition see <xspecref spec="XQ" ref="dt-implementation-defined"/>) value
and/or to augment the default initial value by additional
implementation-defined values.</p></item>
<item><p><emph>Can be overwritten or augmented by a
query:</emph> Indicates whether a query is allowed to replace and/or
augment the initial value provided by default or by the
implementation. If so, indicates how this is accomplished (for
example, by a declaration in the
<term>prolog</term>; see <xspecref spec="XQ" ref="dt-prolog"/>).
</p></item>
<item><p><emph>Scope:</emph> Indicates where the
component is applicable. "Global" indicates that the component applies
globally, throughout all the modules used in a query. "Module"
indicates that the component applies throughout a <term>module</term>
(see <xspecref spec="XQ" ref="dt-module"/>). "Lexical" indicates that the
component applies within the expression in which it is defined
(equivalent to "module", if the component is declared in a
prolog.)</p>
</item>
<item>
<p><emph>Consistency
Rules:</emph> Indicates rules that must be observed in assigning
values to the component. </p></item></ulist><table width="100%" border="1" summary="Static Context" role="small">
<caption>Static Context Components</caption>

<tbody>
<tr>
<th rowspan="1" colspan="1">Component</th> <th rowspan="1" colspan="1">Default initial value</th> <th rowspan="1" colspan="1">Can be
overwritten or augmented by implementation?</th> <th rowspan="1" colspan="1">Can be
overwritten or augmented by a query?</th> <th rowspan="1" colspan="1">Scope</th>
<th rowspan="1" colspan="1">Consistency rules</th>
</tr>

<tr>
<td rowspan="1" colspan="1"><loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftcaseoption" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTCaseOption</loc></td> <td rowspan="1" colspan="1"><code>case
insensitive</code></td> <td rowspan="1" colspan="1">overwriteable</td>
<td rowspan="1" colspan="1">overwriteable by prolog</td> <td rowspan="1" colspan="1">lexical</td> 
<td rowspan="1" colspan="1">Value must be
<code>case insensitive</code> or <code>case sensitive</code>.</td>
</tr>

<tr>
<td rowspan="1" colspan="1"><loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftdiacriticsoption" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTDiacriticsOption</loc></td>
<td rowspan="1" colspan="1"><code>diacritics insensitive</code></td> <td rowspan="1" colspan="1">overwriteable</td> 
<td rowspan="1" colspan="1">overwriteable by prolog</td> <td rowspan="1" colspan="1">lexical</td> 
<td rowspan="1" colspan="1">Value must be <code>diacritics insensitive</code> or
<code>diacritics sensitive</code>.</td>
</tr>

<tr>
<td rowspan="1" colspan="1"><loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftstemoption" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTStemOption</loc></td>
<td rowspan="1" colspan="1"><code>without stemming</code></td> <td rowspan="1" colspan="1">overwriteable</td> 
<td rowspan="1" colspan="1">overwriteable by prolog</td> <td rowspan="1" colspan="1">lexical</td> 
<td rowspan="1" colspan="1">Value must be <code>without stemming</code> or
<code>with stemming</code>.</td>
</tr>

<tr>
<td rowspan="1" colspan="1"><loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftthesaurusoption" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTThesaurusOption</loc></td>
<td rowspan="1" colspan="1"><code>without thesaurus</code></td> <td rowspan="1" colspan="1">overwriteable</td> 
<td rowspan="1" colspan="1">overwriteable by prolog (refer to default to augment)</td> 
<td rowspan="1" colspan="1">lexical</td> 
<td rowspan="1" colspan="1"> Value must be part of the statically known thesauri.</td>
</tr>

<tr>
<td rowspan="1" colspan="1">Statically known thesauri</td>
<td rowspan="1" colspan="1">none</td> <td rowspan="1" colspan="1">augmentable</td> 
<td rowspan="1" colspan="1">cannot be augmented or overwritten by prolog</td> <td rowspan="1" colspan="1">module</td> 
<td rowspan="1" colspan="1"> Each URI uniquely identifies a thesaurus list.</td>
</tr>

<tr>
<td rowspan="1" colspan="1"><loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftstopwordoption" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTStopWordOption</loc></td>
<td rowspan="1" colspan="1"><code>without stopwords</code></td> <td rowspan="1" colspan="1">overwriteable</td> 
<td rowspan="1" colspan="1">overwriteable by prolog (refer to default to augment)</td> 
<td rowspan="1" colspan="1">lexical</td>
<td rowspan="1" colspan="1">Value must be part of the statically known stop word lists.</td>
</tr>

<tr>
<td rowspan="1" colspan="1">Statically known stop word lists</td>
<td rowspan="1" colspan="1">none</td> <td rowspan="1" colspan="1">augmentable</td> 
<td rowspan="1" colspan="1">cannot be augmented or overwritten by prolog</td> <td rowspan="1" colspan="1">module</td> 
<td rowspan="1" colspan="1">Each URI uniquely identifies a stop word list.</td>
</tr>

<tr>
<td rowspan="1" colspan="1"><loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftlanguageoption" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTLanguageOption</loc></td> 
<td rowspan="1" colspan="1">no language is selected</td> <td rowspan="1" colspan="1">overwriteable</td>
<td rowspan="1" colspan="1">overwriteable by prolog</td> <td rowspan="1" colspan="1">lexical</td> 
<td rowspan="1" colspan="1">Value must be castable to "xs:language" or "none".</td>
</tr>

<tr>
<td rowspan="1" colspan="1">Statically known languages</td> 
<td rowspan="1" colspan="1">none</td> <td rowspan="1" colspan="1">augmentable</td>
<td rowspan="1" colspan="1">cannot be augmented or overwritten by prolog</td> <td rowspan="1" colspan="1">module</td> 
<td rowspan="1" colspan="1">Each string uniquely identifies a language.</td>
</tr>

<tr>
<td rowspan="1" colspan="1"><loc xmlns:xlink="http://www.w3.org/1999/xlink" href="#ftwildcardoption" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">FTWildCardOption</loc></td>
<td rowspan="1" colspan="1"><code>without wildcards</code></td> <td rowspan="1" colspan="1">no</td> 
<td rowspan="1" colspan="1">overwriteable by prolog</td> <td rowspan="1" colspan="1">lexical</td>
<td rowspan="1" colspan="1">Value must be <code>without wildcards</code> or <code>without
wildcards</code>.</td>
</tr>

</tbody>
</table>

</div1>


  
<div1 id="id-errors">	
  <head>Error Conditions</head>	

<error-list>

<error spec="XP" code="0004" class="TY" type="type">
<p>It is a type error if, during the static analysis phase,
an expression is found to have a static type
that is not appropriate for the context in which the expression occurs, or during the
dynamic evaluation phase, the dynamic type of a value does not match a required type as
specified by the matching rules in <xspecref spec="XP" ref="id-sequencetype-matching"/>.</p></error>

<error spec="FO" code="0002" class="CH" type="dynamic">
<p>It is a dynamic error if, in a function invocation, the argument corresponding to
the specified function's collation parameter does not identify a supported collation.</p></error>

</error-list>

</div1>
	<div1 id="References">
<head>References</head>
<div2 id="id-normative-references">
<head>Normative References</head>
<blist>
<bibl xmlns:xlink="http://www.w3.org/1999/xlink" id="xquery" key="XQuery 1.0: An XML Query Language" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest"/>

<bibl xmlns:xlink="http://www.w3.org/1999/xlink" id="xpath20" key="XML Path Language (XPath) 2.0" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest"/>

<bibl xmlns:xlink="http://www.w3.org/1999/xlink" id="xpath-functions" key="XQuery 1.0 and XPath 2.0 Functions and Operators" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest"/>

<bibl xmlns:xlink="http://www.w3.org/1999/xlink" id="xqueryft-requirements" key="XQuery and XPath Full-Text Requirements" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest"><emph><loc href="http://www.w3.org/TR/xquery-full-text-requirements/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">XQuery
and XPath Full-Text Requirements</loc></emph>,
Stephen Buxton, Michael Rys, Editors. World Wide Web Consortium, 02 May 2003.
This version is http://www.w3.org/TR/2003/WD-xquery-full-text-requirements-20030502/.
The <loc href="http://www.w3.org/TR/xquery-full-text-requirements/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">latest version</loc>
is available at <loc href="http://www.w3.org/TR/xquery-full-text-requirements/" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">http://www.w3.org/TR/xquery-full-text-requirements/</loc>.
</bibl>

<bibl xmlns:xlink="http://www.w3.org/1999/xlink" id="xmlquery-full-text-use-cases" key="XQuery 1.0 and XPath 2.0 Full-Text Use Cases" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest"/>

<!--  <bibl id="xqueryft-usecases" key="XQuery 1.0 and XPath 2.0 Full-Text Use Cases"><emph><loc href="http://www.w3.org/TR/xmlquery-full-text-use-cases/">XQuery 1.0 and XPath 2.0 Full-Text Use Cases</loc></emph>, -->
<!--  Sihem Amer-Yahia, Pat Case, Editors. World Wide Web Consortium, 04 April 2005. -->
<!--  This version is http://www.w3.org/TR/2004/WD-xmlquery-full-text-use-cases-20040709/. The -->
<!--  <loc href="http://www.w3.org/TR/xmlquery-full-text-use-cases/">latest version</loc> is available at -->
<!--  <loc href="http://www.w3.org/TR/xmlquery-full-text-use-cases/">http://www.w3.org/TR/xmlquery-full-text-use-cases/.</loc> -->
<!--  </bibl> -->

</blist>
</div2>
<div2 id="id-non-normative-references">
<head>Non-normative References</head>
<blist>

<bibl xmlns:xlink="http://www.w3.org/1999/xlink" id="iso-2788" key="ISO 2788" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest">
Documentation Guidelines for the Establishment and Development of
Monolingual Thesauri, Geneva: International Organization for
Standardization, 2nd edition, 1986.
</bibl>


<bibl xmlns:xlink="http://www.w3.org/1999/xlink" id="sqlmm" key="SQL/MM" xlink:type="simple" xlink:show="replace" xlink:actuate="onRequest"> ISO/IEC 13249-2 Information technology
--- Database languages --- SQL Multimedia and Application Packages ---
Part 2: Full-Text. Geneva: International Organization for
Standardization, 2nd edition, 2003.
</bibl>


</blist>
</div2>
</div1>

  <inform-div1 id="ft-acknowledgements">
	<head>Acknowledgements</head>

<p>We would like to thank the members of the XQuery and XPath
Full-Text group for their fruitful discussions. </p>

<p>We would like to thank the following people for their contributions on earlier drafts of this document.</p>

<ulist>
  <item><p> "Andrew Eisenberg" - IBM - andrew.eisenberg@us.ibm.com</p></item>
  <item><p> "Roland Seiffert" - IBM -  seiffert@de.ibm.com</p></item>
  <item><p> "Andrew Cencini" - Microsoft - acencini@microsoft.com </p></item>
  <item><p> "Nimish Khanolkar" - Microsoft - nimishk@exchange.microsoft.com </p></item>
  <item><p> "Ashok Malhotra" Oracle - ashok.malhotra@oracle.com </p></item>
  <item><p> "Tapas Nayak" Microsoft - tapasnay@exchange.microsoft.com </p></item>
</ulist>
</inform-div1>

  <inform-div1 id="ft-glossary">
	<head>Glossary</head>


<!-- This processing instruction automatically generates the glossary. --> 

<?glossary?>

</inform-div1>

  
<inform-div1 id="impl-def">
<head>Checklist of Implementation-Defined Features</head>

<p>This appendix provides a summary of features defined in this specification
whose effect is explicitly <term>implementation-defined</term>. 
The conformance rules require vendors to provide documentation that
explains how these choices have been exercised.
</p>

<olist>

<item><p> Everything about tokenization, including the definition of
the term "words", is <term>implementation-defined</term>,
except that
<olist>
<item><p>each word consists of one or more consecutive characters;</p>
</item>
<item><p>the tokenizer must preserve the containment hierarchy
(paragraphs contain sentences contain words); and</p>
</item>
<item><p>the tokenizer must, when tokenizing two equal strings,
 identify the same tokens in each. </p>
</item>
</olist></p>
</item>

<item><p> Implementations are free to provide
<term>implementation-defined</term> ways to differentiate between markup's 
effect on token boundaries during tokenization. </p></item>

<item><p>  It is <term>implementation-defined</term> what a stem of a word is and 
whether stemming will based on an algorithm, dictionary, or mixed approach. </p></item>

<item><p> When the option "with default stop words" is used, an
<term>implementation-defined</term> collection of stop words is used. </p></item>

<item><p> The set of valid language identifiers is <term>implementation-defined</term>. </p></item>

<item><p>Certain values in the static context (see <specref ref="id-xqft-static-context-components"/>)
that can be overwritten or augmented by implementations are
<term>implementation-defined</term>. </p></item>

</olist>

</inform-div1>
<!--	&issues; -->
  <inform-div1 id="id-xqft-changelog">
<head>Change Log</head>
<table border="1" summary="Change Log Table">
<tbody>
<!--
=================== commented out from here
<tr>
<td>Jochen Doerre</td>
<td>2004-10-04</td>
<td>Added issue on FTIgnore</td>
<td>Added Cluster B, Issue 50 IGNORE Queries.</td>
</tr>
<tr>
<td>Jochen Doerre</td>
<td>2004-10-04</td>
<td>Added issue on FTWindow</td>
<td>Added Cluster I, Issue 51 Alternative Semantics for FTWindow.</td>
</tr>
<tr>
<td>Sihem Amer-Yahia</td>
<td>2005-01-14</td>
<td>Added issue on UnionExpr in StopWords</td>
<td>Added Cluster D, Issue 52 UnionExpr in StopWords.</td>
</tr>
<tr>
<td>Sihem Amer-Yahia</td>
<td>2005-01-16</td>
<td>Added FTStartswith to syntax</td>
<td>Added Section 3.1.12 on startswith. Closed Cluster C, Issue 40 Starts With</td>
</tr>
<tr>
<td>Sihem Amer-Yahia</td>
<td>2005-01-16</td>
<td>Removed FTSpecialCharacter syntax</td>
<td>Removed the Special Character match option in section 3 and closed Cluster E, Issue 22 DiacriticsMatchOption and Cluster E, Issue 24 SpecialCharMatchOption.</td>
</tr>
<tr>
<td>Sihem Amer-Yahia</td>
<td>2005-01-16</td>
<td>Updated FTLanguage syntax</td>
<td>Added the sentence "The set of valid language identifiers is implementation-defined." in Section 3.2.7 (now 3.2.6) FTLanguage.</td>
</tr>
<tr>
<td>Sihem Amer-Yahia</td>
<td>2005-01-16</td>
<td>Updated score syntax</td>
<td>Changed syntax of ft:score() into score $var as Expr in Section 3.</td>
</tr>
<tr>
<td>Sihem Amer-Yahia</td>
<td>2005-01-16</td>
<td>Added score weighting syntax</td>
<td>Added 1) weight to FTSelection inside a scoring expression and 2) text stating that Weight values in scoring expressions are in the interval [0,1]. Closed Cluster A, Issue 17 Weighting and Cluster A, Issue 18 Weight Values.</td>
</tr>
<tr>
<td>Sihem Amer-Yahia</td>
<td>2005-01-24</td>
<td>Changed FTStartswith syntax to FTContent syntax</td>
<td>Changed FTStartswith to FTContent and changed wording to use "the tokenized string of elements".</td>
</tr>
<tr>
<td>Sihem Amer-Yahia</td>
<td>2005-01-24</td>
<td>Added issue on defaults</td>
<td>Added issue Cluster D, Issue 45 MatchOptions Default.</td>
</tr>
<tr>
<td>Sihem Amer-Yahia</td>
<td>2005-01-24</td>
<td>Changed FTStopWords and FTThesaurus syntax</td>
<td>Closed Cluster E, Issue 26 StopWordsMatchOption, Cluster E, Issue 48 Stop words option, and Cluster D, Issue 8 Thesaurus, among other things changing the syntax to allow URIs for a stop word list or thesaurus.</td>
</tr>
<tr>
<td>Sihem Amer-Yahia</td>
<td>2005-02-01</td>
<td>Added issue on score weights</td>
<td>Added Issue 54 Cluster A on weights in scores.</td>
</tr>
<tr>
<td>Sihem Amer-Yahia</td>
<td>2005-02-10</td>
<td>Updated FTStopwords syntax</td>
<td>Updated syntax in Section 2.3.5 Stop Words.</td>
</tr>
<tr>
<td>Sihem Amer-Yahia</td>
<td>2005-02-10</td>
<td>Updated FTThesaurus section</td>
<td>Updated descriptive text, adding reference to ISO 2788, in Section 2.3.4 Theasurus.</td>
</tr>
<tr>
<td>Sihem Amer-Yahia</td>
<td>2005-02-10</td>
<td>Updated introduction</td>
<td>Modified item 7 in Section 1.1 to reflect conditions on tokenizers.</td>
</tr>
<tr>
<td>Sihem Amer-Yahia</td>
<td>2005-02-10</td>
<td>Updated FTDistance syntax</td>
<td>Removed the optional keyword "with" from FTDistance.</td>
</tr>
<tr>
<td>Sihem Amer-Yahia</td>
<td>2005-02-10</td>
<td>Updated FTWindow syntax</td>
<td>Removed the optional keyword "within" from FTWindow.</td>
</tr>
<tr>
<td>Sihem Amer-Yahia</td>
<td>2005-02-14</td>
<td>Updated FTDiacritics syntax</td>
<td>Closed Cluster E, Issue 33 FTSpecialCharOption and Updated Section 3.2.2 Diacritics according to its resolution.</td>
</tr>
<tr>
<td>Sihem Amer-Yahia</td>
<td>2005-02-14</td>
<td>Added FTCase and FTDiacritics matrices</td>
<td>Added matrices which summarize the interaction between the diacritics and case match options and types of collations.</td>
</tr>
<tr>
<td>Sihem Amer-Yahia</td>
<td>2005-02-14</td>
<td>Added FTRegex escape syntax</td>
<td>Closed Cluster C, Issue 15 RegExp Escape by adding wildcard escape syntax.</td>
</tr>
<tr>
<td>Chavdar Botev</td>
<td>2005-02-14</td>
<td>Updated FTThesaurusOption and FTRegexOption semantics</td>
<td>Updated FTThesaurusOption and FTRegexOption in Section 4 Semantics.</td>
</tr>
<tr>
<td>Chavdar Botev</td>
<td>2005-02-14</td>
<td>Updated FTDiacritics semantics</td>
<td>The fts:applySingleSearchToken function in the match-options semantics section has been modified. Now it explicitly checks for the diacritics option and applies the necessary semantic functions.</td>
</tr>
<tr>
<td>Chavdar Botev</td>
<td>2005-02-14</td>
<td>Removed FTSpecialCharacter semantics</td>
<td>Removed the special-characters option semantics.</td>
</tr>
<tr>
<td>Chavdar Botev</td>
<td>2005-02-14</td>
<td>Updated FTStopWord semantics</td>
<td>Changed the XML representation and the fts:ApplyStopwordOption semantic function to reflex the new syntax.</td>
</tr>
<tr>
<td>Chavdar Botev</td>
<td>2005-02-14</td>
<td>Added FTContent semantics</td>
<td>Added an XML representation and a semantic function for FTContent.</td>
</tr>
<tr>
<td>Sihem Amer-Yahia</td>
<td>2005-02-18</td>
<td>Updated FTRegex syntax</td>
<td>Closed Cluster C, Issue 27 MatchOption and Tokenization which required changes only to FTRegex specifying it impact on tokenization. Text added.</td>
</tr>
<tr>
<td>Sihem Amer-Yahia</td>
<td>2005-02-21</td>
<td>Replaced FTRegex syntax with FTWildcard syntax</td>
<td>Replaced FTRegex syntax with FTWildcard syntax in Section 3.2.8</td>
</tr>
<tr>
<td>Sihem Amer-Yahia</td>
<td>2005-02-21</td>
<td>Added issue proposing FTCollationOption</td>
<td>Added Cluster D, Issue 57 Collations Match Option.</td>
</tr>
<tr>
<td>Jochen Doerre</td>
<td>2005-02-22</td>
<td>Closed issues resolved previously</td>
<td>Closed Cluster A, Issue 1 Scoring Properties with no change to the document. Closed Cluster C, Issue 7 Wildcards - regular expressions were dropped in favor of wildcards. Closed Cluster F, Issue 31 Optional Keyword "with" in FTDistance - "with" was dropped. Closed Cluster F, Issue 32 Optional Keyword "within" in FTWindow - "within" was dropped. Closed Cluster F, Issue 34 FTNegation Includes Unary Not with no change to the document.</td>
</tr>
<tr>
<td>Jochen Doerre</td>
<td>2005-02-22</td>
<td>Added issue on ft-about</td>
<td>Added Cluster H, Issue 58 Free-text search operator ft-about.</td>
</tr>
<tr>
<td>Chavdar Botev</td>
<td>2005-02-22</td>
<td>Updated FTDistance semantics</td>
<td>Removed the optional keyword "with" from FTDistance.</td>
</tr>
<tr>
<td>Chavdar Botev</td>
<td>2005-02-22</td>
<td>Updated FTWindow semantics</td>
<td>Removed the optional keyword "within" from FTWindow.</td>
</tr>
<tr>
<td>Chavdar Botev</td>
<td>2005-02-22</td>
<td>Updated FTWords semantics</td>
<td>Updated FTWords semantics to allow for zero-length string: An FTWords with an empty list of search tokens returns an empty AllMatches.</td>
</tr>
<tr>
<td>Chavdar Botev</td>
<td>2005-02-22</td>
<td>Replaced FTRegex semantics with FTWildcards semantics</td>
<td>Replaced FTRegex semantics with FTWildcards semantics.</td>
</tr>
<tr>
<td>Sihem Amer-Yahia</td>
<td>2005-03-03</td>
<td>Updated FTWildcards syntax</td>
<td>Updated FTWildcards syntax in Section 3.</td>
</tr>
<tr>
<td>Sihem Amer-Yahia</td>
<td>2005-03-04</td>
<td>Updated Section 2 (syntax) and issues list</td>
<td>Closed and updated Section 2 to reflect resolutions for 1) Cluster F, Issue 30 Precedence of XQuery and full-text, 2) Cluster G, Issue 47 Zero-length phrase, 3) Cluster F, Issue 49 Grammar Precedence and Lookahead. Also added introduction to the Issues List explaining the clusters.</td>
</tr>
<tr>
<td>Sihem Amer-Yahia</td>
<td>2005-03-04</td>
<td>Updated FTIgnoreOption syntax</td>
<td>Updated FTIgnoreOption in Section 3.</td>
</tr>
<tr>
<td>Sihem Amer-Yahia</td>
<td>2005-03-04</td>
<td>Updated FTThesaurus examples</td>
<td>Added "at" in thesaurus examples in Section 3.</td>
</tr>
<tr>
<td>Sihem Amer-Yahia</td>
<td>2005-03-04</td>
<td>Updated FTWindow section</td>
<td>Added descriptive text to FTWindow.</td>
</tr>
<tr>
<td>Scott Boag</td>
<td>2005-03-10</td>
<td>Updated grammar</td>
<td>1) Integrated full-text grammar (including the "{" "}" bracketing of expressions) into the main XPath grammar file. 2) Changed the way ftcontains is called. 3) Generated parser is now generated without any lookahead enabled.</td> 
</tr>
<tr>
<td>Chavdar Botev</td>
<td>2005-03-17</td>
<td>Updated Thesauri lookup</td>
<td>Closed Cluster D, Issue 42 Thesauri lookup for multi-word phrases, and updated section 4 to reflect the changes.
</td>
</tr>
<tr>
<td>Chavdar Botev</td>
<td>2005-03-17</td>
<td>Added text to describe schemas</td>
<td>Added two paragraphs to FTSelections and FTMatchOptions which describe the schemas.
</td>
</tr>
<tr>
<td>Scott Boag</td>
<td>2005-03-19</td>
<td>Updated FTThesaurus production</td>
<td>Updated FTThesaurus production by adding "at" before "except" and "union".</td>
</tr>
<tr>
<td>Sihem Amer-Yahia</td>
<td>2005-03-22</td>
<td>Removed ft and fts namespace references</td>
<td>Removed references to the ft (full-text) and fts (full-text semantics) namespaces.</td>
</tr>
<tr>
<td>Sihem Amer-Yahia</td>
<td>2005-03-28</td>
<td>Updated FTThesaurus syntax</td>
<td>Updated FTThesaurus in Section 3.</td>
</tr>
============= commented out upto here
-->

<tr>
<td rowspan="1" colspan="1">Sihem Amer-Yahia</td>
<td rowspan="1" colspan="1">2005-04-08</td>
<td rowspan="1" colspan="1">Updated case matrix</td>
<td rowspan="1" colspan="1">Updated case matrix row "sensitive", column "CCI" from "case-insensitive variant of CCI if it exists, else error" to 
"case-sensitive variant of CCI if it exists, else error".</td>
</tr>
<tr>
<td rowspan="1" colspan="1">Sihem Amer-Yahia</td>
<td rowspan="1" colspan="1">2005-05-02</td>
<td rowspan="1" colspan="1">Closed issues with no changes</td>
<td rowspan="1" colspan="1">Closed Cluster B, Issue 28 IGNORE Syntax with no change to the document. Closed Cluster B, Issue 50 IGNORE Queries with no change to the document.</td>
</tr>
<tr>
<td rowspan="1" colspan="1">Sihem Amer-Yahia</td>
<td rowspan="1" colspan="1">2005-05-02</td>
<td rowspan="1" colspan="1">Updated FTTimes syntax</td>
<td rowspan="1" colspan="1">Closed Cluster G, Issue 14 FTTimesSelection and added a related bullet item in Section 3.</td>
</tr>
<tr>
<td rowspan="1" colspan="1">Sihem Amer-Yahia</td>
<td rowspan="1" colspan="1">2005-05-02</td>
<td rowspan="1" colspan="1">Updated FTWildCard syntax</td>
<td rowspan="1" colspan="1">Updated FTWildCardOption in Section 3.</td>
</tr>
<tr>
<td rowspan="1" colspan="1">Sihem Amer-Yahia</td>
<td rowspan="1" colspan="1">2005-05-03</td>
<td rowspan="1" colspan="1">Updated introduction</td>
<td rowspan="1" colspan="1">Replaced "semantic element" with "semantic markup" and "tag" with "element" in the introduction.</td>
</tr>
<tr>
<td rowspan="1" colspan="1">Sihem Amer-Yahia</td>
<td rowspan="1" colspan="1">2005-05-03</td>
<td rowspan="1" colspan="1">Added issue on error codes</td>
<td rowspan="1" colspan="1">Added Cluster J, Issue 59 Error Codes.</td>
</tr>
<tr>
<td rowspan="1" colspan="1">Sihem Amer-Yahia</td>
<td rowspan="1" colspan="1">2005-05-03</td>
<td rowspan="1" colspan="1">Closed issues with no change</td>
<td rowspan="1" colspan="1">Closed Cluster A, Issue 54 Weight Granularity in Scoring with same resolution as for Cluster A, Issue 5 Score Weighting, no further change to document. Closed Cluster H, Issue 9 Window with no change to the document. Closed Cluster H, Issue 19 FTScopeSelection on structure with no change to the document. Closed Cluster E, Issue 25 MatchOption Syntax with no change to the document. Closed Cluster H, Issue 44 FTContains Semantics with no change to the document.
</td>
</tr>
<tr>
<td rowspan="1" colspan="1">Sihem Amer-Yahia</td>
<td rowspan="1" colspan="1">2005-05-03</td>
<td rowspan="1" colspan="1">Updated FTContent syntax</td>
<td rowspan="1" colspan="1">Updated FTContent adding "entire content", Closed Cluster C, Issue 39 Exact Element Content.</td>
</tr>
<tr>
<td rowspan="1" colspan="1">Sihem Amer-Yahia</td>
<td rowspan="1" colspan="1">2005-05-03</td>
<td rowspan="1" colspan="1">Closed issue on Boolean Naming</td>
<td rowspan="1" colspan="1">Closed Cluster F, Issue 38 Boolean Naming. Changes to the document are pending awaiting a decision on whether it is OK to use "and", "or", "not" for full-text. If so change existing symbols to "and", "or", "not". If not change existing symbols to "ftand", "ftor", "ftnot".</td>
</tr>
<tr>
<td rowspan="1" colspan="1">Chavdar Botev</td>
<td rowspan="1" colspan="1">2005-05-03</td>
<td rowspan="1" colspan="1">Updated FTDistance semantics</td>
<td rowspan="1" colspan="1">Updated the semantics for distance.</td>
</tr>
<tr>
<td rowspan="1" colspan="1">Sihem Amer-Yahia</td>
<td rowspan="1" colspan="1">2005-05-03</td>
<td rowspan="1" colspan="1">Updated FTRange syntax</td>
<td rowspan="1" colspan="1">Made "exactly" required before an exact number in FTRange. Closed Cluster F, Issue 43 Exactly in FTRangeSpec.</td>
</tr>
<tr>
<td rowspan="1" colspan="1">Sihem Amer-Yahia</td>
<td rowspan="1" colspan="1">2005-05-04</td>
<td rowspan="1" colspan="1">Closed issue on collations</td>
<td rowspan="1" colspan="1">Closed Cluster D, Issue 57 Collations Match Option.</td>
</tr>
<tr>
<td rowspan="1" colspan="1">Jochen Doerre</td>
<td rowspan="1" colspan="1">2005-05-19</td>
<td rowspan="1" colspan="1">Added issue on scoring</td>
<td rowspan="1" colspan="1">Added Cluster A, Issue 60 Extended Scoring.</td>
</tr>
<tr>
<td rowspan="1" colspan="1">Chavdar Botev</td>
<td rowspan="1" colspan="1">2005-06-29</td>
<td rowspan="1" colspan="1">Added issue on FTNegation</td>
<td rowspan="1" colspan="1">Added Cluster G, Issue 62 Precise semantics of double negation.</td>
</tr>
<tr>
<td rowspan="1" colspan="1">Chavdar Botev</td>
<td rowspan="1" colspan="1">2005-06-29</td>
<td rowspan="1" colspan="1">Added issue on FTTimes</td>
<td rowspan="1" colspan="1">Added Cluster G, Issue 61 Desired semantics of FTTimes.</td>
</tr>
<tr>
<td rowspan="1" colspan="1">Sihem Amer-Yahia</td>
<td rowspan="1" colspan="1">2005-07-11</td>
<td rowspan="1" colspan="1">Updated FTMildNegation syntax</td>
<td rowspan="1" colspan="1">Updated the mild not syntax from "mild not" to "not in". Closed Cluster I, Issue 10 MildNot and Cluster F, Issue 41 Mildnot Naming.</td>
</tr>
<tr>
<td rowspan="1" colspan="1">Chavdar Botev</td>
<td rowspan="1" colspan="1">2005-07-12</td>
<td rowspan="1" colspan="1">Updated FTIgnore semantics</td>
<td rowspan="1" colspan="1">Changed semantics of FTIgnoreOption.</td>
</tr>
<tr>
<td rowspan="1" colspan="1">Sihem Amer-Yahia</td>
<td rowspan="1" colspan="1">2005-07-18</td>
<td rowspan="1" colspan="1">Corrected error codes</td>
<td rowspan="1" colspan="1">Corrected and added error codes, closing and implementing the resolution for Cluster J Issue 59 Error Codes.</td>
</tr>
<tr>
<td rowspan="1" colspan="1">Sihem Amer-Yahia</td>
<td rowspan="1" colspan="1">2005-07-18</td>
<td rowspan="1" colspan="1">Closed issues with no changes</td>
<td rowspan="1" colspan="1">closed Cluster I, Issue 13 "loose-grammar" leaving the grammar as it is. Closed issue Cluster D, Issue 53 "matchoptions-default" with no change to the document. Closed Cluster H, Issue 58 "ft-about-operator" with no change to the document.</td>
</tr>
<tr>
<td rowspan="1" colspan="1">Sihem Amer-Yahia</td>
<td rowspan="1" colspan="1">2005-07-21</td>
<td rowspan="1" colspan="1">Updated score syntax</td>
<td rowspan="1" colspan="1">Closed Cluster A, Issue 60 "new-scoring-proposal" and Issue 2
"scoring-values" and updated Section 2.2 Score Clause to reflect new score syntaxes. There are now syntaxes for scored queries 1) returning the same results as queries with Boolean predicates and 2) for returning more or fewer results.</td>
</tr>
<tr>
<td rowspan="1" colspan="1">Sihem Amer-Yahia</td>
<td rowspan="1" colspan="1">2005-07-21</td>
<td rowspan="1" colspan="1">Added appendix for defaults</td>
<td rowspan="1" colspan="1">Added appendix for defaults in the query prolog analogous to C.1 in the XQuery language document.</td>
</tr>
<tr>
<td rowspan="1" colspan="1">Sihem Amer-Yahia</td>
<td rowspan="1" colspan="1">2005-07-21</td>
<td rowspan="1" colspan="1">Updated FTThesaurus section</td>
<td rowspan="1" colspan="1">Aligned description in Section 3.2.4 FTThesaurusOption with current grammar.</td>
</tr>
<tr>
<td rowspan="1" colspan="1">Sihem Amer-Yahia</td>
<td rowspan="1" colspan="1">2005-07-21</td>
<td rowspan="1" colspan="1">Opened and closed issue on nested FTNegation</td>
<td rowspan="1" colspan="1">Opened and closed Cluster I, Issue 65 Nested FTNegations on the right side of an FTMildNegation.</td>
</tr>
<tr>
<td rowspan="1" colspan="1">Chavdar Botev</td>
<td rowspan="1" colspan="1">2005-07-25</td>
<td rowspan="1" colspan="1">Updated FTMildNegation semantics</td>
<td rowspan="1" colspan="1">Changed the semantics of MildNot.</td>
</tr>
<tr>
<td rowspan="1" colspan="1">Sihem Amer-Yahia</td>
<td rowspan="1" colspan="1">2005-08-10</td>
<td rowspan="1" colspan="1">Added Change Log</td>
<td rowspan="1" colspan="1">Added Change Log harvesting back entries from CVS change log.</td>
</tr>
<tr>
<td rowspan="1" colspan="1">Jochen Doerre</td>
<td rowspan="1" colspan="1">2005-08-17</td>
<td rowspan="1" colspan="1">Grammar changes</td>
<td rowspan="1" colspan="1">Changed XQuery/XPath grammar for new scoring syntax (resolution of
Issue 60), for match option defaults in query prolog (resolution of
Issue 45), for simplified window operator (resolution to Issue 51),
renamed "mild not" to "not in" (resolution of Issue 41), modified
FTThesaurusOption, FTStopwordOption and FTLanguageOption to require
StringLiterals as decided in May 05 F2F.</td>
</tr>
<tr>
<td rowspan="1" colspan="1">Jochen Doerre</td>
<td rowspan="1" colspan="1">2005-08-17</td>
<td rowspan="1" colspan="1">Changes to Section 2</td>
<td rowspan="1" colspan="1">New scoring syntax introduced; rewritten most of 2.2. Corrected use
of weights in 2.2.1 (wrong default, wrong use of 1.5)</td>
</tr>
<tr>
<td rowspan="1" colspan="1">Jochen Doerre</td>
<td rowspan="1" colspan="1">2005-08-17</td>
<td rowspan="1" colspan="1">Changes to Section 3</td>
<td rowspan="1" colspan="1">Adapting the explanations to changed syntax for FTWindow,
FTThesaurusOption, FTStopwordOption and FTLanguageOption. Also
corrected a couple of example explanations. Removed FTIgnoreOption
from the list of match option defaults in 3.2 Corrected explanation
and example of FTLanguageOption (diacritics nor case are
language-specific!). Commented out last two examples of FTDistance,
because distance 15 does not work for phrases.</td>
</tr>
<tr>
<td rowspan="1" colspan="1">Jochen Doerre</td>
<td rowspan="1" colspan="1">2005-08-17</td>
<td rowspan="1" colspan="1">Appendices A+B</td>
<td rowspan="1" colspan="1">Adapted introductory comment about which version of the
XQuery/XPath grammars we are aligned to.</td>
</tr>
<tr>
<td rowspan="1" colspan="1">Jochen Doerre</td>
<td rowspan="1" colspan="1">2005-08-17</td>
<td rowspan="1" colspan="1">Dates in Header</td>
<td rowspan="1" colspan="1">Adapted current date and previous date and links in
full-text-query-language-semantics.xml and in tqheader.xml.</td>
</tr>
<tr>
<td rowspan="1" colspan="1">Jochen Doerre</td>
<td rowspan="1" colspan="1">2005-08-19</td>
<td rowspan="1" colspan="1">Added Section 2.3, Changes in 3+4</td>
<td rowspan="1" colspan="1">Added Section 2.3 Extension to Static Context. Changed Sections 3.2
and 4.4.1.1 to refer to match option settings in the static context.</td>
</tr>
<tr>
<td rowspan="1" colspan="1">Jochen Doerre</td>
<td rowspan="1" colspan="1">2005-08-19</td>
<td rowspan="1" colspan="1">Added Issue 63</td>
<td rowspan="1" colspan="1">Added Cluster G Issue 63: Distance constraints do not work on phrases.</td>
</tr>
<tr>
<td rowspan="1" colspan="1">Jochen Doerre</td>
<td rowspan="1" colspan="1">2005-08-19</td>
<td rowspan="1" colspan="1">Changes in Section 4</td>
<td rowspan="1" colspan="1">Adapted semantics to new scoring feature (resolution of Issue 60),
changed FTWindow semantics according to resolution of Issue
51, and cleaned examples. </td>
</tr>
<tr>
<td rowspan="1" colspan="1">Jochen Doerre</td>
<td rowspan="1" colspan="1">2005-08-19</td>
<td rowspan="1" colspan="1">Appendix G</td>
<td rowspan="1" colspan="1">Added lines for statically known thesauri and stop lists.</td>
</tr>
<tr>
<td rowspan="1" colspan="1">Jochen Doerre</td>
<td rowspan="1" colspan="1">2005-08-25</td>
<td rowspan="1" colspan="1">Added Issue 64</td>
<td rowspan="1" colspan="1">Added Cluster E Issue 64:System Relative Operator Defaults (using wording proposed by Pat Case).</td>
</tr>
<tr>
<td rowspan="1" colspan="1">Jochen Doerre</td>
<td rowspan="1" colspan="1">2005-10-10</td>
<td rowspan="1" colspan="1">Changes in Section 3</td>
<td rowspan="1" colspan="1">Rephrased Section 3.2.7 FTIgnoreOption. Explanation and example adapted to simple (non-recursive) use of "ignore".</td>
</tr>
<tr>
<td rowspan="1" colspan="1">Jochen Doerre</td>
<td rowspan="1" colspan="1">2005-10-10</td>
<td rowspan="1" colspan="1">Changes in Section 4</td>
<td rowspan="1" colspan="1">Incorporated Section 4.3.1.4 Match and AllMatches Normal Form.</td>
</tr>
<tr>
<td rowspan="1" colspan="1">Sihem Amer-Yahia</td>
<td rowspan="1" colspan="1">2005-10-12</td>
<td rowspan="1" colspan="1">Incorporated comments</td>
<td rowspan="1" colspan="1">Incorporated Pat's comments at http://lists.w3.org/Archives/Member/member-query-fttf/2005Sep/0068.html</td>
</tr>
<tr>
<td rowspan="1" colspan="1">Jim Melton</td>
<td rowspan="1" colspan="1">2005-10-20</td>
<td rowspan="1" colspan="1">Changes in Sections 3 and 4</td>
<td rowspan="1" colspan="1">Properly marked up errors and inserted error summary appendix. Re-ordered appendices so normative appendices precede non-normative appendices.</td>
</tr>
<tr>
<td rowspan="1" colspan="1">Jochen Doerre</td>
<td rowspan="1" colspan="1">2005-10-24</td>
<td rowspan="1" colspan="1">Final editings</td>
<td rowspan="1" colspan="1">Included corrections to examples in Section 3. Changed meaning of distance 0 for sentences (paragraphs) to mean adjacent. Rework of Appendix H Checklist of Implementation-Defined Features. Resolution texts to issues 45, 59, and 62.</td>
</tr>
<tr>
<td rowspan="1" colspan="1">Jochen Doerre</td>
<td rowspan="1" colspan="1">2005-11-28</td>
<td rowspan="1" colspan="1">Restrict FTTimes to FTWords</td>
<td rowspan="1" colspan="1">Modified EBNF syntax to allow the FTTimes operation to be applicable only to simple FTWords.</td>
</tr>
<tr>
<td rowspan="1" colspan="1">Jochen Doerre</td>
<td rowspan="1" colspan="1">2005-11-28</td>
<td rowspan="1" colspan="1">Re: Bug 2299: Changes to Section 4</td>
<td rowspan="1" colspan="1">The AllMatches model has been changed to allow the TokenInfo of a StringMatch to represent an interval of token positions, instead of single positions. Thus, a phrase is now modeled using a single StringMatch, and consequently distance constraints (which always apply to the individual StringMatches) can be used to constrain the entire phrase. In addition, this change allows to model overlapping tokens. The semantics functions for FTOrder (order now constrains the start positions of tokens), for FTScope, for FTDistance (a distance constraint requires a certain number of positions between the end of one token and the start of the next) and for FTWindows have been adapted.</td>
</tr>
<tr>
<td rowspan="1" colspan="1">Jochen Doerre</td>
<td rowspan="1" colspan="1">2006-01-09</td>
<td rowspan="1" colspan="1">Issues List removed</td>
<td rowspan="1" colspan="1">Dropped Appendix I "Issues List", as issues are tracked in Bugzilla now.</td>
</tr>
<tr>
<td rowspan="1" colspan="1">Mary Holstege</td>
<td rowspan="1" colspan="1">2006-02-01</td>
<td rowspan="1" colspan="1">Static context</td>
<td rowspan="1" colspan="1">Added known languages to static context.</td>
</tr>
<tr>
<td rowspan="1" colspan="1">Jochen Doerre</td>
<td rowspan="1" colspan="1">2006-03-06</td>
<td rowspan="1" colspan="1">Bug 2776</td>
<td rowspan="1" colspan="1">Changed EBNF grammar to allow weights to be specified using RangeExpr.</td>
</tr>
<tr>
<td rowspan="1" colspan="1">Mary Holstege</td>
<td rowspan="1" colspan="1">2006-03-30</td>
<td rowspan="1" colspan="1">Updated Tokenization 4.2.7</td>
<td rowspan="1" colspan="1">Expanded and clarified definition. Added examples.</td>
</tr>
<tr>
<td rowspan="1" colspan="1">Pat Case</td>
<td rowspan="1" colspan="1">2006-04-13</td>
<td rowspan="1" colspan="1">Replaced glossary</td>
<td rowspan="1" colspan="1">Removed glossary copied from the XQuery language document and inserted coding to produce a full-text glossary.</td>
</tr>
<tr>
<td rowspan="1" colspan="1">Jochen Doerre</td>
<td rowspan="1" colspan="1">2006-04-24</td>
<td rowspan="1" colspan="1">Section 2</td>
<td rowspan="1" colspan="1">Added new Processing Model section.</td>
</tr>
<tr>
<td rowspan="1" colspan="1">Jochen Doerre</td>
<td rowspan="1" colspan="1">2006-04-25</td>
<td rowspan="1" colspan="1">Section 4</td>
<td rowspan="1" colspan="1">Included the completely revised semantics schemata and  functions,
which now (i) correctly handle interval-based TokenInfos, (ii)
separate the representation of TokenInfos and SearchTokenInfos and
SearchItems, (iii) have been simplified regarding the semantics of
match options by no longer separating the implementation-defined
matching function from (most of) the implementation-defined
application of match options, and (iv) have been type- and syntax-checked.</td>
</tr>
</tbody>
</table>
</inform-div1>

	</back>
</spec>