W3C

XQuery 1.0 and XPath 2.0 Full-Text 1.0 Use Cases

W3C Working Draft 18 May 2007

This version:
http://www.w3.org/TR/2007/WD-xpath-full-text-10-use-cases-20070518/
Latest version:
http://www.w3.org/TR/xpath-full-text-10-use-cases/
Previous versions:
http://www.w3.org/TR/2006/WD-xmlquery-full-text-use-cases-20060501/ http://www.w3.org/TR/2005/WD-xmlquery-full-text-use-cases-20051103/ http://www.w3.org/TR/2005/WD-xmlquery-full-text-use-cases-20050915/ http://www.w3.org/TR/2005/WD-xmlquery-full-text-use-cases-20050404/ http://www.w3.org/TR/2004/WD-xmlquery-full-text-use-cases-20040709/ http://www.w3.org/TR/2003/WD-xmlquery-full-text-use-cases-20030214/
Editors:
Sihem Amer-Yahia, AT&T Labs - Research
Pat Case, Library of Congress

This document is also available in these non-normative formats: XML.


Abstract

This document specifies usage scenarios for full-text queries as part of XML Query [XQuery 1.0: An XML Query Language] and XPath [XML Path Language (XPath) 2.0].

Status of this Document

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 W3C technical reports index at http://www.w3.org/TR/.

This is a Working Draft for review by W3C Members and other interested parties. As of this publication, the Working Groups expect to eventually publish this document as a Working Group Note. This document was produced following the procedures set out for the W3C Process and was defined jointly by the XSL Working Group and the XML Query Working Group (both part of the XML Activity).

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.

This is the seventh version of this document. The syntax for the full-text and, or, not operators was changed from &&, ||, ! to ftand, ftor, ftnot. The ordered keywords were placed before distance and window operators so they will be processed first. Other small corrections were made. See Appendix D [ChangeLog] for more information.

This document provides a number of use cases designed to evaluate the language defined in XQuery 1.0 and XPath 2.0 Full-Text 1.0 at the time that it was issued as a Last Call Working Draft in May, 2007. Organizations and individuals should review this document to ascertain whether or not adequate coverage of the requirements is provided by these use cases.

Public Last Call comments on this document and its open issues are invited. Comments on this document are desired by 22 June 2007. Comments on this document should be made in W3C's public Bugzilla system for this specification (instructions can be found at http://www.w3.org/XML/2005/04/qt-bugzilla). When entering comments, select the Product named "XPath / XQuery / XSLT", the Component named "FT Use Cases", and the Version named "Working drafts". This repository includes open issues recorded by the Query Working Group as well as by members of the public. If access to the Bugzilla system is not feasible, you may send your comments to the W3C XSLT/XPath/XQuery mailing list, public-qt-comments@w3.org It will be very helpful if you include the string [FTUseCase] in the subject line of your comment, whether made in Bugzilla or in email. Each Bugzilla entry and email message should contain only one comment. Archives of the comments and responses are available at http://lists.w3.org/Archives/Public/public-qt-comments/.

This document was produced by groups operating under the 5 February 2004 W3C Patent Policy. W3C maintains a public list of any patent disclosures made in connection with the deliverables of the XML Query Working Group and also maintains a public list of any patent disclosures made in connection with the deliverables of the XSL Working Group; those pages also include instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy.

Table of Contents

1 Full-Text Use Cases: Preliminaries
    1.1 Proper Display of this Unicode Document
    1.2 Introduction
    1.3 Presentation of Use Cases
    1.4 Schema for Sample Data
    1.5 Sample Data
2 Use Case "ELEMENT": Queries on XML Elements with Simple Content
    2.1 Description
    2.2 Queries and Results
        2.2.1 Q1 Word Query in an Element
        2.2.2 Q2 Phrase Query in an Element
        2.2.3 Q3 Phrase Query on Chinese Characters in an Element
        2.2.4 Q4 Query in Different Elements
        2.2.5 Q5 Query in an Element Returning Different Elements
        2.2.6 Q6 Starts-with Query
        2.2.7 Q7 Entire Element Content Query
3 Use Case "ACROSS": Queries Across XML Element Boundaries
    3.1 Description
    3.2 Queries and Results
        3.2.1 Q1 Query Across Descendant Elements (No Element Content)
        3.2.2 Q2 Query Across Descendant Elements (Highlighting Tags)
        3.2.3 Q3 Query Across Descendant Elements (Substantive Tags)
        3.2.4 Q4 Query Across Siblings
        3.2.5 Q5 Query in Different Sub-Trees
        3.2.6 Q6 Query on Entire Document
4 Use Case "OTHER": Queries on Attribute Values
    4.1 Description
    4.2 Queries and Results
        4.2.1 Q1 Query on Attribute
        4.2.2 Q2 Query on Element and Attribute
5 Use Case "WILDCARD": Character Wildcard Queries
    5.1 Description
    5.2 Queries and Results
        5.2.1 Q1 One Character Suffix Wildcard Query
        5.2.2 Q2 Zero or One Character Prefix Wildcard Query
        5.2.3 Q3 Zero or More Character Infix Wildcard Query
        5.2.4 Q4 One or More Character Suffix Wildcard Query on Part of a Word
        5.2.5 Q5 Specified Range of Characters Suffix Wildcard Query
6 Use Case "STEMMING": Word Stemming Queries
    6.1 Description
    6.2 Queries and Results
        6.2.1 Q1 Query Stemming on Word Root
        6.2.2 Q2 Query Stemming on Multiple Word Roots
7 Use Case "THESAURUS": Queries Which Use Thesauri, Dictionaries, and Taxonomies
    7.1 Description
    7.2 Queries and Results
        7.2.1 Q1 Query on Synonyms Identified by a Thesaurus
        7.2.2 Q2 Query on Narrower Terms Identified by a Thesaurus
        7.2.3 Q3 Query on Broader Terms Identified by a Thesaurus
        7.2.4 Q4 Query on Word Which Sounds Like Other Words
        7.2.5 Q5 Query on Word Spelled Similarly to Other Words
        7.2.6 Q6 Query on Subordinate Terms Identified by a Taxonomy
8 Use Case "STOP-WORD": Queries on Stop Words
    8.1 Description
    8.2 Queries and Results
        8.2.1 Q1 Query on Stop Word Treated as a Stop Word
        8.2.2 Q2 Query on Stop Word Not Treated as a Stop Word
        8.2.3 Q3 Query Excluding a Stop Word on a Stop Word List
9 Use Case "CHARACTER": Queries Specifying Normalized Forms of Characters and Tokenized Words
    9.1 Description
    9.2 Queries and Results
        9.2.1 Q1 Query on Word with Characters with Diacritics
        9.2.2 Q2 Query on Word with Characters with and Without Diacritics
        9.2.3 Q3 Query on Word with Upper Case Characters
        9.2.4 Q4 Query on Word with Upper Case and Lower Case Characters
10 Use Case "LOGICAL": Queries with Logical Expressions (Or, And, and Not Queries)
    10.1 Description
    10.2 Queries and Results
        10.2.1 Q1 Or Query
        10.2.2 Q2 And Query
        10.2.3 Q3 And Query Ordered
        10.2.4 Q4 Unary Not Query
        10.2.5 Q5 And Not Query
        10.2.6 Q6 And Not Query Where Second Operand Is a Subset of the First Operand
        10.2.7 Q7 Mild Not Query Where Second Operand Is a Subset of the First Operand
11 Use Case "CARDINALITY": Queries in Same, Any, Every Instance of an Element, and Occurrence Count Query
    11.1 Description
    11.2 Queries and Results
        11.2.1 Q1 Query in Same Instance of an Element
        11.2.2 Q2 Query in Any Instance of an Element (Existential Quantification)
        11.2.3 Q3 Query in Every Instance of an Element (Universal Quantification)
        11.2.4 Q4 Occurrence Count Query
12 Use Case "PROXIMITY": Queries on Proximity Relationships Including Distance, Window, Sentence, and Paragraph
    12.1 Description
    12.2 Queries and Results
        12.2.1 Q1 Unordered Distance Query
        12.2.2 Q2 Ordered Distance Query
        12.2.3 Q3 Ordered Window Query
        12.2.4 Q4 Unordered Within a Sentence Query
        12.2.5 Q5 Unordered Within a Paragraph Query
13 Use Case "AXES": Queries Using Relative XPath Axes
    13.1 Description
    13.2 Queries and Results
        13.2.1 Q1 Query on Element and Its Children
        13.2.2 Q2 Query on Element Returning Its First Two Children
        13.2.3 Q3 Query on Element and Its Ancestors
        13.2.4 Q4 Query on Element and Its Right Siblings
14 Use Case "IGNORE": Queries Ignoring Descendant Element Content
    14.1 Description
    14.2 Queries and Results
        14.2.1 Q1 Distance Query Ignoring Content of All Descendant Elements
        14.2.2 Q2 Phrase Query Ignoring Content of Descendant Element Specified by XPath Expression
        14.2.3 Q3 Phrase Query Ignoring Content of Descendant Element Specified by Full-Text Query
        14.2.4 Q4 Distance Query Ignoring Content of Descendant Elements Level by Level
15 Use Case "FULL-TEXT-COMPOSABILITY": Queries Illustrating Composability of Full-Text with Itself
    15.1 Description
    15.2 Queries and Results
        15.2.1 Q1 Query on Words and Phrases in Two Languages
        15.2.2 Q2 Phrase and Distance Query in an Instance of an Element with Stemming
        15.2.3 Q3 Nested Distance Query with Wildcards, Stemming, and Thesaurus Support
        15.2.4 Q4 Window Query with Wildcards and Stemming Ignoring Content of a Descendant Element
        15.2.5 Q5 Query on Different Elements in Different Sub-Trees with Conditional Return
16 Use Case "XQUERY-XPATH-COMPOSABILITY": Queries Illustrating Composability of Full-Text with Other XQuery and XPath Functionalities
    16.1 Description
    16.2 Queries and Results
        16.2.1 Q1 Full-Text Query Constructing New Element
        16.2.2 Q2 Full-Text Query Returning Count of Descendant Element Occurrences
        16.2.3 Q3 Full-Text Query with Conditional Return
        16.2.4 Q4 Full-Text Query with Numeric Value Comparison
        16.2.5 Q5 Full-Text Query with Character String Query
        16.2.6 Q6 Full-Text Query with Conditional Return of Boolean Values
        16.2.7 Q7 Full-Text Query with Date Comparison and Element Occurrence Count
        16.2.8 Q8 Query with XPath Expression Within Full-Text Expression
        16.2.9 Q9 Query Using an XQuery Expression to Determine the Number of Words Allowed in a Window
17 Use Case "SCORE": All Queries May Be Written with Score, Queries in this Section Must Be Written with Score
    17.1 Description
    17.2 Queries and Results
        17.2.1 Q1 Query Returning Scores
        17.2.2 Q2 Query Returning Results with Top Scores
        17.2.3 Q3 Query Filtering on Scores
        17.2.4 Q4 Query Combining Score and XML Structure with a Conditional Return
        17.2.5 Q5 Query Returning All Books Ordered by Score
        17.2.6 Q6 Query with Weight Declaration

Appendices

A Acknowledgements
B References
    B.1 References (Primary)
    B.2 References (Background)
C Issues
D Change Log


1 Full-Text Use Cases: Preliminaries

1.1 Proper Display of this Unicode Document

(1) Use a current operating system and browser.

(2) If necessary, set the character encoding in the browser manually to Unicode or UTF-8. Often this setting may be changed from the View menu.

(3) If after setting the character encoding to Unicode, the Chinese characters in the subject elements of the sample data still do not display, it is likely that the browser cannot locate a font that contains Chinese characters in Unicode encoding. It might be necessary to add a Unicode font, preferably Arial Unicode MS.

1.2 Introduction

The use cases listed below were created by the XML Query Working Group and the XSL Working Group to illustrate important applications of full-text querying within an XML query language. Each use case exercises a specific functionality relevant to full-text querying. An XML Schema and sample input data are provided. Each use case specifies a query applied to the input data, a solution in XQuery, a solution in XPath (when possible), and the expected results.

The document supplements the XML Query Use Cases which can be found in the W3C XML Query Use Cases [XML Query Use Cases]. Use cases for character string querying are included in the XML Query Use Cases, not in this document.

The full-text queries in the following use cases are performed on text which has been tokenized, i.e., broken into a sequence of words, units of punctuation, and spaces.

A word is defined as any character, n-gram, or sequence of characters returned by a tokenizer as a basic unit to be queried. Each instance of a word consists of zero or more consecutive characters. Beyond that words are implementation-defined. Note that consecutive words need not be separated by either punctuation or space, and words may overlap. A phrase is an ordered list of words. A phrase may contain any number of words.

Tokenization enables functions and operators which work with the relative positioning of words (e.g., proximity operators). Tokenization also enables functions and operators which operate on a part or the root of the word (e.g., wildcards, stemming).

These use cases:

(1) Present some possible functions and features for tokenized text support in XQuery and XPath. None are yet available in XQuery or XPath. Please comment on these use cases and recommend others.

(2) Illustrate simple and complex queries. The more complex queries would normally only be constructed by programmers, librarians, and other expert users. Sometimes they may be provided for novice users via saved queries and graphical user interfaces. Each query illustrates a single functionality. Queries may overlap in their functionalities (e.g., phrases and ordered distance queries allowing no intervening words). Overlapping and similar functionalities are noted in the comments on query behavior.

(3) Draw from sample data which are almost entirely in English. Use cases in other languages are solicited, especially where they illustrate language-specific implementations of functions and features. Among the most sought after are use cases for queries using prefix and infix wild cards, proximity queries, and operators and queries requiring functionality which may not have Western language equivalents.

(4) Include queries which in most instances can be written with pure Boolean full-text predicates or with scoring (e.g., scoring on the number of occurrences of a word or phrase, scoring on how close words are to one another within a distance query, scoring on how similar a word is to the one being stemmed) [BYR99] [HTK00]. A few, those in Section 17 (SCORE), cannot be written with Boolean full-text predicates. Scoring methodologies will not be defined in this recommendation. Scoring will be implementation-defined. Results are provided in document order, except those in Section 17 (SCORE). Results could be returned ordered differently, such as by relevance (based on implementation-defined scoring) or explicitly by element.

(5) Query element content. See Section 4 (OTHER) for explicit queries on attribute values.

(6) Include queries which are case-insensitive. When returning a paragraph, the text is returned as it occurs in the data model. This approach was chosen to keep the sample data short and the expected results meaningful. It would have been equally valid to return only the character queried. A case-sensitive query is found in Section 9 (CHARACTER).

(7) Include queries which when they target XML elements are understood, unless otherwise stated, to query text within any text node descendant of the element.

(8) Include queries which return only elements and attributes which meet all the conditions specified in the query. In particular, pure Boolean full-text predicate queries return results where the Boolean conditions in the query are satisfied, i.e., are used to select what is being returned to users.

Query results may be returned in different ways. From a query for books containing the word "usability", users might be interested in returning, for each book containing the word "usability", its number and its entire content. In another situation for the same query, users might be interested in returning, for each book containing the word "usability", its number and only the elements and attributes in the content which contain the word "usability". As in this second situation, the queries in these use cases return only elements and attributes which meet all the conditions specified in the query.

The Return clause may also include additional or different elements and attributes if specified, and may construct new elements.

(9) Include queries which provide some of the basic functionality of fuzzy match querying (e.g., wildcards, stemming, thesaurus support, proximity).

(10) Provide highlighting of found words and phrases in the expected results of queries as an aid to users. The presence of highlighting says nothing about whether highlighting will be a feature of XQuery or XPath full-text querying.

(11) Display query solutions in XQuery and when possible in XPath. Queries that may not be written in XPath include those that contain element constructors and that cannot be written without let and order by clauses.

Examples of full-text querying functionalities for XML query languages can be found in [FGR01], [HTK00], [MJK98], [SCH01] and [TWE00].

To make the output more readable, the output of queries has been formatted using white space which may not be returned by a query processor. This white space should not be considered normative for the correctness of results.

These use cases represent a snapshot of an ongoing work. Some important operators and features are not yet adequately covered by a use case. The XML Query and XSL Working Groups reserve the right to add, delete, or modify individual queries or whole use cases as the work progresses. The presence of a query in this set of use cases does not necessarily indicate that the query will be expressible in XQuery [XQuery 1.0: An XML Query Language] and/or XPath [XML Path Language (XPath) 2.0] to be created by the XML Query and XSL Working Groups.

1.3 Presentation of Use Cases

The queries in these use cases are presented in the following format:

Query number   Query title

User statement of query

Statement of functionality illustrated by query

  • Operands: Parts of words, words, phrases

  • Functionality: Operators, functions, collations, other functionality

  • Data context: One XPath expression locating the data being queried.

  • Query context: One or more XPath expressions locating the elements and attributes to be queried. The context of elements and attributes used in the Query context is relative to the Data context defined above.

  • Return: One or more XPath expressions which are returned only if the conditions specified in the query are met. Returned elements or attributes may differ from those specified in the Query context. Newly constructed elements might be returned. As in the Query context, the context of elements and attributes in Return statements is relative to the Data context defined above.

  • Comments: Comments on query behavior in general, and against the sample data in particular, plus the rationale for including this query in the use cases.

Solution in XQuery:

Solutions illustrating XQuery Full-Text syntax  
appear here. All queries may be written in XQuery.

Solutions are written with pure Boolean full-text predicates 
and not to invoke scoring, except for those in Section 17 (SCORE), 
however all the queries in the document may be written as scored 
queries with the addition of a score variable.

All queries are written assuming the default function namespace, 
without the fn: prefix.

Solution in XPath:

Solutions illustrating XPath Full-Text syntax appear 
(when the query may be written in XPath) here.

Solutions are written with pure Boolean full-text predicates 
and not to invoke scoring, except for those in Section 17 (SCORE), 
however most of the queries in the document may be written as 
scored queries with the addition of a score variable.

All queries are written assuming the default function namespace, 
without the fn: prefix.

Expected Result:

Results are provided here.
                                
Found words and phrases are highlighted. 
                                
For brevity, only the elements and attributes which meet 
the conditions specified in the query are displayed. Others are
replaced with ...s.

Results are provided in document order, except those 
in Section 17 (SCORE)

See Issue 1 [staticErrorTesting]: The queries in the Full-Text Use Cases have not yet been tested to ensure they do not cause static errors, such as cardinality errors.

1.4 Schema for Sample Data

The example queries in these use cases are based on a collection with the following XML Schema:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
version="1.0">
<xs:import namespace="http://www.w3.org/XML/1998/namespace" 
schemaLocation = "http://www.w3.org/2001/xml.xsd"/>
   <xs:element name="books">
      <xs:annotation>
         <xs:documentation>A possible XML Schema for Sample Data 
         in XQuery and XPath Full-Text Use Cases
         </xs:documentation>
      </xs:annotation>
      <xs:complexType>
         <xs:sequence maxOccurs="unbounded">
            <xs:element name="book">
               <xs:complexType>
                  <xs:sequence>
                     <xs:element name="metadata" 
                     type="metadataType"/>
                     <xs:element name="content" 
                     type="contentType"/>
                  </xs:sequence>
                  <xs:attribute name="number" type="xs:integer"/>
               </xs:complexType>
            </xs:element>
         </xs:sequence>
      </xs:complexType>
   </xs:element>
   <xs:complexType name="anyXMLTextType" mixed="true">
      <xs:annotation>
         <xs:documentation>free text, contains any well-formed 
         XML</xs:documentation>
      </xs:annotation>
      <xs:sequence>
         <xs:any processContents="skip" minOccurs="0" 
         maxOccurs="unbounded"/>
      </xs:sequence>
   </xs:complexType>
   <xs:complexType name="metadataType">
      <xs:sequence>
         <xs:element name="title">
            <xs:complexType>
               <xs:simpleContent>
                  <xs:extension base="xs:string">
                     <xs:attribute name="shortTitle" 
                     type="xs:string"/>
                  </xs:extension>
               </xs:simpleContent>
            </xs:complexType>
         </xs:element>
         <xs:element name="author" type="xs:string" 
         minOccurs="0" 
         maxOccurs="unbounded"/>
         <xs:element name="publicationInfo" 
         type="publicationInfoType"/>
         <xs:element name="price" minOccurs="0">
            <xs:simpleType>
               <xs:restriction base="xs:float">
                  <xs:minInclusive value="0"/>
                  <xs:maxInclusive value="10000"/>
               </xs:restriction>
            </xs:simpleType>
         </xs:element>
         <xs:element name="subjects" 
         maxOccurs="unbounded">
            <xs:sequence>
               <xs:element name="subject" type="xs:string" 
               maxOccurs="unbounded"/>
            </xs:sequence>
               <xs:attribute ref="xml:lang"/>
         </xs:element>
      </xs:sequence>
   </xs:complexType>
   <xs:complexType name="publicationInfoType">
      <xs:sequence>
         <xs:element name="place" type="xs:string" 
         minOccurs="0"/>
         <xs:element name="publisher" type="xs:string" 
         maxOccurs="unbounded"/>
         <xs:element name="dateIssued" type="xs:string"/>
         <xs:element name="dateRevised" type="xs:string"/>
      </xs:sequence>
   </xs:complexType>
   <xs:complexType name="contentType">
      <xs:sequence>
         <xs:element name="introduction" 
         type="introductionType" 
         minOccurs="0"/>
         <xs:element name="part" type="partType" 
         maxOccurs="unbounded"/>
      </xs:sequence>
   </xs:complexType>
   <xs:complexType name="introductionType">
      <xs:sequence>
         <xs:element name="author" type="xs:string" 
         minOccurs="0"/>
         <xs:element name="p" maxOccurs="unbounded">
            <xs:complexType mixed="true">
               <xs:choice minOccurs="0" 
               maxOccurs="unbounded">
                  <xs:element name="b"/>
                  <xs:element name="emph"/>
                  <xs:element name="i"/>
               </xs:choice>
            </xs:complexType>
         </xs:element>
      </xs:sequence>
   </xs:complexType>
   <xs:complexType name="partType">
      <xs:sequence>
         <xs:element name="container" type="xs:string" 
         minOccurs="0">
             <xs:complexType>
               <xs:simpleContent>
                  <xs:extension base="xs:string">
                     <xs:attribute name="type" type="xs:string"/>
                  </xs:extension>
               </xs:simpleContent>
            </xs:complexType>
         </xs:element>
         <xs:element name="title" type="titleType" 
         minOccurs="0"/>
         <xs:element name="introduction" 
         type="introductionType" 
         minOccurs="0"/>
         <xs:element name="chapter" type="chapterType" 
         minOccurs="0" maxOccurs="unbounded"/>
         <xs:element name="component" 
         type="componentType" 
         minOccurs="0" maxOccurs="unbounded"/>
      </xs:sequence>
      <xs:attribute name="number" type="xs:string"/>
   </xs:complexType>
   <xs:complexType name="chapterType">
      <xs:sequence>
         <xs:element name="title" type="xs:string"/>
         <xs:element name="p" type="anyXMLTextType" 
         maxOccurs="unbounded"/>
      </xs:sequence>
   </xs:complexType>
   <xs:complexType name="footnoteType" mixed="true">
      <xs:sequence>
         <xs:element name="citation" type="xs:string"
         minOccurs="0" maxOccurs="unbounded">
            <xs:complexType>
               <xs:simpleContent>
                  <xs:extension base="xs:string">
                     <xs:attribute name="url" type="xs:anyURI"/>
                  </xs:extension>
               </xs:simpleContent>
            </xs:complexType>
         </xs:element>
      </xs:sequence>
   </xs:complexType>
   <xs:complexType name="componentType">
      <xs:sequence>
         <xs:element name="container" type="xs:string" 
         minOccurs="0">
            <xs:complexType>
               <xs:simpleContent>
                  <xs:extension base="xs:string">
                     <xs:attribute name="type" type="xs:string"/>
                  </xs:extension>
               </xs:simpleContent>
            </xs:complexType>
         </xs:element>
         <xs:element name="componentTitle" 
         type="componentTitleType"/>
         <xs:element name="subComponent" 
         type="subComponentType" 
         minOccurs="0" maxOccurs="unbounded"/>
      </xs:sequence>
   </xs:complexType>
   <xs:complexType name="titleType" mixed="true">
      <xs:all minOccurs="0">
         <xs:element name="date" type="xs:string">
            <xs:complexType>
               <xs:simpleContent>
                  <xs:extension base="xs:string">
                     <xs:attribute name="normalize" 
                     type="xs:string"/>
                  </xs:extension>
               </xs:simpleContent>
            </xs:complexType>
         </xs:element>
      </xs:all>
   </xs:complexType>
   <xs:complexType name="componentTitleType" 
   mixed="true">
      <xs:sequence>
         <xs:element name="componentDate" 
         type="xs:string" 
        minOccurs="0">
            <xs:complexType>
               <xs:simpleContent>
                  <xs:extension base="xs:string">
                     <xs:attribute name="normalize" 
                     type="xs:string"
                      use="optional"/>
                  </xs:extension>
               </xs:simpleContent>
            </xs:complexType> 
         </xs:element>
      </xs:sequence>
   </xs:complexType>
   <xs:complexType name="subComponentType">
      <xs:sequence>
         <xs:element name="container" type="xs:string" 
         minOccurs="0">
            <xs:complexType>
               <xs:simpleContent>
                  <xs:extension base="xs:string">
                     <xs:attribute name="type" type="xs:string"/>
                  </xs:extension>
               </xs:simpleContent>
            </xs:complexType> 
        </xs:element>
        <xs:element type="componentTitleType"/>
        <xs:element name="subsubComponent" 
        type="subSubComponentType" 
        minOccurs="0" maxOccurs="unbounded"/>
      </xs:sequence>
   </xs:complexType>
   <xs:complexType name="subSubComponentType">
      <xs:sequence>
         <xs:element name="container" type="xs:string" 
         minOccurs="0">
           <xs:complexType>
              <xs:simpleContent>
                 <xs:extension base="xs:string">
                    <xs:attribute name="type" type="xs:string"/>
                 </xs:extension>
              </xs:simpleContent>
           </xs:complexType> 
        </xs:element>
        <xs:element name="componentTitle" 
        type="componentTitleType"/>
      </xs:sequence>
   </xs:complexType>
</xs:schema>

1.5 Sample Data

The data consists of a collection of three books. Two are primarily instructive text. The third is a guide to a manuscript collection. All contain metadata and full text.

The sample data binds to this URL: "http://bstore1.example.com/full-text.html".

<books>
<book number="1">
   <metadata>
      <title shortTitle="Improving Web Site Usability">Improving 
      the Usability of a Web Site Through Expert Reviews and 
      Usability Testing</title>
      <author>Millicent Marigold</author>
      <author>Montana Marigold</author>
      <publicationInfo>
         <place>New York</place>
         <publisher>Ersatz Publications</publisher>
         <dateIssued>2001</dateIssued>
         <dateRevised>2002</dateRevised>
      </publicationInfo>
      <price>25.99</price>   
      <subjects xml:lang="en">
         <subject>Usability testing</subject>
         <subject>Web site development</subject>        
         <subject>Heuristic evaluation</subject>
         <subject>Cognitive walk-through</subject>
         <subject>Web site usability</subject>
      </subjects>
      <subjects xml:lang="fr">        
         <subject>Tests d'ergonomie</subject>
         <subject>Développement de site web</subject>        
         <subject>Évaluation heuristique</subject>
         <subject>Parcours cognitif</subject>
         <subject>Ergonomie de site web</subject>     
      </subjects>
      <subjects xml:lang="zh">    
         <subject>可用性测试</subject>
         <subject>网站建置</subject>        
         <subject>启发式评价</subject>
         <subject>认知推演</subject>
         <subject>网站可用性</subject>
      </subjects>
   </metadata>
   <content>
      <introduction>
         <author>Elina Rose</author>
         <p>The usability of a Web site is how well the 
         site supports the user in achieving specified 
         goals. A Web site should facilitate learning, 
         and enable efficient and effective task 
         completion, while propagating few errors. 
         Satisfaction with the site is also important. 
         The user must not only be well-served, but must 
         feel well-served.</p> 
         <p>Expert reviews and usability testing are 
         methods of identifying problems in layout, 
         terminology, and navigation before they frustrate
         users and drive them away from your site.</p>
         <p>The most successful projects employ multiple 
         methods in multiple iterations. As Millicent 
         Marigold remarked during a recent conference, 
         "Don't stop. Iterate, iterate, then iterate 
         again."</p>
         <p>This book has been approved by the Web Site 
         Users Association.</p>
      </introduction>
      <part number="1">
         <title>Expert Reviews</title>
         <introduction>
            <p>Expert reviewers identify problems 
            and recommend changes to web sites based 
            on research in human computer interaction 
            and their experience in the field.</p> 
            <p>Two expert review methods are discussed 
            here. They are heuristic evaluation and 
            cognitive walk-through.</p> 
            <p>Expert review methods should be 
            initiated early in the development process, 
            as soon as paper <b>p</b>rototypes 
            (hand-drawn pictures of Web pages) or 
            <b>w</b>ireframes (electronic mockups) are 
            available. They should be conducted using 
            the hardware and software similar to that 
            employed by users.</p>
         </introduction>
         <chapter>
            <title>Heuristic Evaluation</title>
            <p>Expert reviewers critique an interface to 
            determine conformance with recognized 
            usability principles. <footnote>One of the 
            best known lists of heuristics is <citation 
            url="http://www.useit.com/papers/heuristic
            /heuristic_list.html">Ten Usability 
            Heuristics by Jacob Nielson</citation>. Another 
            is <citation url="http://usability.gov
            /guidelines/index.html"> Research-Based Web 
            Design and Usability Guidelines</citation>
            </footnote></p> 
         </chapter>
         <chapter>
            <title>Cognitive Walk-Through</title>
            <p>Expert reviewers evaluate Web site 
            understandability and ease of learning while 
            performing specified tasks. They walk through 
            the site answering questions such as "Would a 
            user know by looking at the screen how to 
            complete the first step of the task?" and "If 
            the user completed the first step, would the 
            user know what to do next?," with the goal of 
            identifying any obstacles to completing the 
            task and assessing whether the user would 
            cognitively be aware that he was successful in 
            completing a step in the process.</p>
         </chapter>
      </part>
      <part number="2">
         <chapter>
            <title>Usability Testing</title>
            <p>Once the problems identified by expert 
            reviews have been corrected, it is time to 
            conduct some tests of the site with your unique 
            audience or audiences by conducting usability 
            testing.</p>
            <p>Users are asked to complete tasks which 
            measure the success of the information 
            architecture and navigational elements of the 
            site.</p>
            <p>Then changes are made to improve service to 
            users.</p>
         </chapter>
      </part> 
   </content>
</book>

<book number="2">
   <metadata>
      <title shortTitle="Usability Basics">Usability 
      Basics: How to Plan for and Conduct Usability Tests 
      on Web Site Thereby Improving the Usability of Your 
      Web Site</title>
      <publicationInfo>
         <place>New York</place>
         <publisher>Ersatz Publications</publisher>
         <publisher>Electronic BookWorks</publisher>         
         <dateIssued>2000</dateIssued>
         <dateRevised>2001</dateRevised>
      </publicationInfo>
      <price>174.00</price>   
      <subjects xml:lang="en">
         <subject>Usability testing</subject>
         <subject>Web site development</subject>
         <subject>Guides and finding aids</subject>
      </subjects>
      <subjects xml:lang="fr">
         <subject>Tests d'ergonomie</subject>
         <subject>Développement de site web</subject>
         <subject>Guides et outils de recherche</subject>
      </subjects>
      <subjects xml:lang="zh">
         <subject>可用性测试</subject>
         <subject>网站建置</subject>
         <subject>指南和检索工具</subject>
      </subjects>
   </metadata>
   <content>
      <introduction>
         <p>This is a basic handbook for planning and 
         conducting usability tests on Web sites. Usability 
         testing should be used in conjunction with other 
         expert review methods.</p>
         <p>This book has not been approved by the Web Site 
         Users Association.</p>
      </introduction>
      <part number="1">
         <chapter>
            <title>Planning then Conducting Usability 
            Tests</title> 
            <p>Take the following steps to plan usability 
            testing. <step number="1">Clarify and 
            articulate the goal of the usability testing.
            </step> <step number="2">Identify tasks which 
            are critical for users to be able to complete 
            successfully.</step> <step number="3">Compile 
            a script of questions or instructions which 
            will prompt the user to attempt those 
            tasks.</step> <step number="4">Identify your 
            users and begin recruiting them.</step> <step 
            number="5">Conduct a pretest on a few users.
            </step> <step number="6">Edit the script based 
            on insights gleaned from the pretest.</step> 
            <step number="7">Resume testing.</step></p>
         </chapter>
      </part>
      <part number="2">
         <chapter>
            <title>Conducting Usability Tests</title> 
         <p>Users can be tested at any computer 
            workstation <footnote>They may be more 
            comfortable at their own workstation than in 
            a lab.</footnote> or in a lab.</p>
            <p>Give the user the script, then assure them 
            that you are testing the Web site, not them. 
            Users are asked to verbalize their thoughts as 
            they complete the tasks. The event is recorded 
            or someone takes notes. It is often preferable 
            to have two testers, <footnote>Usability 
            testing can be done at great expense or on a 
            shoe string, using <testingProcedure>in-house 
            expertise</testingProcedure> or 
            <testingProcedure>contracting with human 
            computer interaction professionals
            </testingProcedure>.</footnote> one to ask the 
            questions, another to take notes. Testers should 
            offer no guidance or comments to the user. Mouse 
            movements, typing, expressions, and the user's 
            words should be recorded.</p>
         </chapter>
         <chapter>
            <title>Evaluating and Implementing Results</title> 
            <p>Compile the results and review collectively. 
            Make changes to the site to alleviate the problems 
            found in Web site components which were propagating 
            the largest number of or the most devastating errors. 
            Begin new iterations of testing and changes, until 
            users are successful in the accomplishing the 
            tasks.</p>
         </chapter>
      </part>
   </content>
</book>

<book number="3">
   <metadata>
      <title shortTitle="Usabilityguy Manuscript 
      Guide">John Wesley Usabilityguy: A Register of His 
      Papers</title>
      <author>Millicent Marigold</author>
      <author>Morty Marigold</author>
      <publicationInfo>  
         <place>Washington, D.C.</place>    
         <publisher>Ersatz Manuscript Library</publisher>
         <dateIssued>1998</dateIssued>
         <dateRevised>2002</dateRevised>
      </publicationInfo>
      <price>21.49</price>   
      <subjects xml:lang="en">
         <subject>Computers</subject>
         <subject>Software evaluation</subject>
         <subject>Usability testing</subject>
         <subject>Manuscript collections</subject>
      </subjects>
      <subjects xml:lang="fr">
         <subject>Ordinateurs</subject>
         <subject>Évaluation de logiciels</subject>
         <subject>Tests d'ergonomie</subject>
         <subject>Collections de manuscrits</subject>
      </subjects>
      <subjects xml:lang="zh">
         <subject>计算机</subject>
         <subject>软件评价</subject>
         <subject>可用性测试</subject>
         <subject>手稿专藏</subject>
      </subjects>
   </metadata>
   <content>
      <introduction>
         <p>The papers of John Wesley Usabilityguy span the 
         years 1946-2001, with the bulk of the items 
         concentrated in the period from 1985 to 2001. The 
         papers feature his career as a developer of software 
         applications and usability specialist. The collection 
         consists of correspondence, memoranda, journals, 
         speeches, article drafts, book drafts, notes, charts, 
         graphs, family papers, clippings, printed matter, 
         photographs, résumés and other materials.</p>
      </introduction>
      <part number="1"><container type="box">1-12</container>
         <title>Subject File, <date normalize="1930/1974">
         1930-1974</date></title>
         <introduction>
            <p>Correspondence, telegrams, memoranda, journals, 
            logs, testimony, approved travel orders, invitations, 
            charts, graphs, forms, biographical data, photographs, 
            book drafts, clippings and other printed matter, 
            résumés and miscellaneous material. Organized by 
            name of person or organization, topic, or type of 
            material.</p>
         </introduction>
         <component><container type="box">1</container>
           <componentTitle>Computers</componentTitle>
           <subComponent>
              <componentTitle>Software, 
              <componentDate normalize="1946/1947">1946-1947
              </componentDate>
              </componentTitle>
           </subComponent>
           <subComponent>
              <componentTitle>Human Computer Interaction 
              research, <componentDate normalize="1945/1952">
              1945-1952</componentDate>
              </componentTitle>
              <subsubComponent>
                 <componentTitle>Flow diagram, 
                 <componentDate normalize="1950">1950
                 </componentDate>
                 </componentTitle>
              </subsubComponent>
              <subsubComponent>
                 <componentTitle>General, 
                 <componentDate normalize="1947/1951">1947-1951
                 </componentDate>
                 </componentTitle>
              </subsubComponent>
              <subsubComponent><container type="box">2</container>
                 <componentTitle>Eye Movement research,
                 <componentDate normalize="1949/1950">1949-1950
                 </componentDate>
                 </componentTitle>
              </subsubComponent> 
              <subsubComponent>
                 <componentTitle>User profiling, 
                 <componentDate normalize="1950/1959">1950s
                 </componentDate>
                 </componentTitle>
              </subsubComponent>
            </subComponent>
         </component>
         <component>
           <componentTitle>Web User Appreciation Award, 
           <componentDate normalize="1956">1956</componentDate>
           </componentTitle>
         </component>
      </part>
      <part number="2"><container type="box">3-5</container>
         <title>Writings File, 
         <date normalize="1985/1999">1985-1999</date>
         </title>
         <introduction>
            <p>Correspondence, articles, book drafts, notes, 
            contracts, clippings, and printed matter. Arranged 
            alphabetically by type (articles, books, reports, 
            and miscellaneous) and therein alphabetically by 
            type of material, subject, or title.</p>
         </introduction>
         <component>
            <componentTitle>Writings by Usabilityguy
            </componentTitle>
            <subComponent>
               <componentTitle><componentDate normalize="1996">
               1996</componentDate>
               </componentTitle> 
               <subsubComponent>
                  <componentTitle>"How Many Users Are Enough 
                  for User Testing?"</componentTitle>
               </subsubComponent> 
               <subsubComponent>
                  <componentTitle>"How to Evaluate Results from 
                  User Tests."</componentTitle>
               </subsubComponent>
               <subsubComponent>
                  <container type="box">5</container>
                  <componentTitle>"When Are You Done Testing?"
                  </componentTitle>
               </subsubComponent>
               <subsubComponent>
                  <componentTitle>"Do-It-Yourself User Testing"
                  </componentTitle>
               </subsubComponent> 
            </subComponent>
         </component>
         <component>
            <componentTitle>Charitable Contributions
            </componentTitle> 
            <subComponent>
               <componentTitle>Diseases: AIDS, Hepatitis, 
               Tuberculosis <componentDate normalize=
               "1990/1999">1990-1999</componentDate>
               </componentTitle>
            </subComponent> 
            <subComponent>
               <componentTitle>Environmental Conservation: 
               Rivers <componentDate normalize="1995">1995
               </componentDate>
               </componentTitle>
            </subComponent>
         </component>
      </part>
   </content>
</book>
</books>

2 Use Case "ELEMENT": Queries on XML Elements with Simple Content

2.1 Description

These use cases query words and phrases in XML elements with simple content.

These use cases begin with the simplest queries possible. They query a word or phrase in an element with simple content and no descendants. One of these queries is on Chinese characters. Some queries return additional or different elements than were queried. A query queries and returns the full document. Others find a phrase only when it starts an element and find a exact phrase when it is the entire content of an element, allowing full-text variations, such as case, diacritics, and wildcards.

2.2 Queries and Results

2.2.1 Q1 Word Query in an Element

Find all book titles containing the word "usability".

This query finds a word in an element.

  • Operands: "usability"

  • Functionality: word query

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: ./metadata/title

  • Return: ./metadata/title

  • Comments: This is the simplest query possible, a query on a word in an element. This query does not employ wildcards, stemming, or thesaurus support. While this query finds useful results in the sample data, many queries such as one on the word "test" would not. A query on the word "test" would return no results, missing the word variants which exist in the sample data: "pretest", "tested", "testers", "testimony", "testing", and "tests".

Solution in XQuery:

doc("http://bstore1.example.com/full-text.xml")
   /books/book/metadata/title[. ftcontains "usability"]

Solution in XPath:

doc("http://bstore1.example.com/full-text.xml")
/books/book/metadata/title[. ftcontains "usability"]

Expected Result:

<title shortTitle="Improving Web Site Usability">Improving 
the Usability of a Web Site Through Expert Reviews 
and Usability Testing</title>

<title shortTitle="Usability Basics">Usability 
Basics: How to Plan for and Conduct Usability Tests 
on Web Site Thereby Improving the Usability of Your 
Web Site</title>

2.2.2 Q2 Phrase Query in an Element

Find all book subjects containing the phrase "usability testing".

This query finds a phrase in an element.

  • Operands: "usability testing"

  • Functionality: phrase query

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: ./metadata/subjects/subject

  • Return: ./metadata/subjects/subject

  • Comments: This is a simple query on a phrase in an element. Like an ordered distance query allowing no intervening words, the words in this phrase query must be adjacent to each other and must appear in the order specified. While this query finds useful results in the sample data, many queries such as one on "software developer" would not. A query on the phrase "software developer" would return no results, missing "developer of software" which exists in the sample data.

Solution in XQuery:

doc("http://bstore1.example.com/full-text.xml")
   /books/book/metadata/subjects/subject[. ftcontains 
   "usability testing"]

Solution in XPath:

doc("http://bstore1.example.com/full-text.xml")
/books/book/metadata/subjects/subject[. ftcontains 
"usability testing"]

Expected Result:

<subject>Usability testing</subject>
                                                
<subject>Usability testing</subject>

<subject>Usability testing</subject>

2.2.3 Q3 Phrase Query on Chinese Characters in an Element

Find all book subjects containing the phrase (n-gram) "网站".

This query finds a phrase (n-gram) in an element.

  • Operands: "网站"

  • Functionality: phrase query, language qualifier

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: ./metadata/subjects/subject

  • Return: ./metadata/subjects/subject

  • Comments: This query finds a phrase (n-gram) consisting of two Chinese characters. It assumes a specific language dependent tokenization.

Solution in XQuery:

doc("http://bstore1.example.com/full-text.xml")
   /books/book/metadata/subjects/subject[. ftcontains 
   "网站" language "zh"]

Solution in XPath:

doc("http://bstore1.example.com/full-text.xml")
/books/book/metadata/subjects/subject[. ftcontains 
"网站" language "zh"]

Expected Result:

<subject>网站建置</subject>  
                                            
<subject>网站可用性</subject>

<subject>网站建置</subject>

2.2.4 Q4 Query in Different Elements

Find all books with "usability tests" in book or chapter titles.

This query finds a phrase in different elements.

  • Operands: "usability tests"

  • Functionality: phrase query

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: ./metadata/title, ./content/part/chapter/title

  • Return: .

  • Comments: This query is an example of a query in two different elements.

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $title := $book/metadata/title[. ftcontains "usability tests"] 
   union $book/content/part/chapter/title[. ftcontains "usability 
   tests"] 
where count($title) > 0
return $book

Solution in XPath:

doc("http://bstore1.example.com/full-text.xml")
/books/book[count(./metadata/title[. ftcontains "usability tests"] 
union ./content/part/chapter/title[. ftcontains "usability tests"])>0]

Expected Result:

<book number="2">
   <metadata>
      ...
      <title shortTitle="Usability Basics">Usability 
      Basics: How to Plan for and Conduct Usability Tests 
      on Web Site Thereby Improving the Usability of 
      Your Web Site</title> 
      ...
   </metadata>
   <content>
      ...
      <part number="1">
         <chapter>
            <title>Planning then Conducting Usability
            Tests</title> 
            ...
         </chapter>
      </part>
      <part number="2">
         <chapter>
            <title>Conducting Usability Tests</title>
            ...
         </chapter>
      </part>
      .... 
   </content>
</book>

2.2.5 Q5 Query in an Element Returning Different Elements

Find all books with the phrase "usability testing" in some subject.

This query finds a phrase in an element and returns different elements from the same document.

  • Operands: "usability testing"

  • Functionality: phrase query

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: ./metadata/subjects/subject

  • Return: ./metadata/title, ./metadata/author

  • Comments: This query queries the subject element, but does not return it. It returns two different elements.

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
where $book//subject ftcontains "usability testing"
return $book/metadata/(title|author)

Solution in XPath:

doc("http://bstore1.example.com/full-text.xml")
/books/book[./metadata/subjects/subject 
ftcontains "usability testing"]/metadata/(title|author)

Expected Result:

<title shortTitle="Improving Web Site Usability">Improving 
the Usability of a Web Site Through Expert Reviews 
and Usability Testing</title> 
<author>Millicent Marigold</author>     
<author>Montana Marigold</author> 
   
<title shortTitle="Usability Basics">Usability 
Basics: How to Plan for and Conduct Usability Tests 
on Web Site Thereby Improving the Usability of Your 
Web Site</title>
   
<title shortTitle="Usabilityguy Manuscript 
Guide">John Wesley Usabilityguy: A Register of His 
Papers</title>
<author>Millicent Marigold</author>
<author>Morty Marigold</author>

2.2.6 Q6 Starts-with Query

Find all book titles which start with "improving" followed within 2 words by "usability".

This query finds an element which starts with specific words.

  • Operands: "improving" "usability"

  • Functionality: word queries, ordered distance (0 to 2 intervening words), starts-with functionality

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: ./metadata/title

  • Return: ./metadata/title

  • Comments: The starts-with functionality restricts the query to the first words or phrase in an element. It is especially useful in querying journal titles (e.g., Journal of Psychology) in large library collections. This query does not find Book 2 which contains the phrase "improving the usability" in the title element, because the title element does not start with "improving" followed within 2 words by "usability".

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $title := $book/metadata/title[. ftcontains 
"improving" ftand "usability" ordered  
distance at most 2 words at start]
where count($title)>0
return $title

Solution in XPath:

doc("http://bstore1.example.com/full-text.xml")
/books/book/metadata/title[count(. ftcontains 
"improving" ftand "usability" ordered 
distance at most 2 words  at start)>0]

Expected Result:

<title shortTitle="Improving Web Site Usability">Improving 
the Usability of a Web Site Through Expert Reviews and 
Usability Testing</title>

2.2.7 Q7 Entire Element Content Query

Find all books with the entire title "improve the usability of a web site through expert reviews and usability testing", allowing any form of the word "improve".

This query finds the phrase when it is the entire content of an element.

  • Operands: "improve the usability of a web site through expert reviews and usability testing"

  • Functionality: phrase query, character wildcard (suffix) (0 or more), entire element content functionality

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: ./metadata/title

  • Return: ./metadata/title

  • Comments: This query insists that the element contains the entire phrase being queried, no more and no less. It allows full-text variations, such as case, diacritics, and wildcards.

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $exactTitle := $book/metadata/title[. ftcontains 
   "improv.* the usability of a web site through expert 
   reviews and usability testing" entire content]
where count($exactTitle)>0
return $exactTitle

Solution in XPath:

doc("http://bstore1.example.com/full-text.xml")
/books/book/metadata/title[count(. ftcontains 
"improv.* the usability of a web site through expert 
reviews and usability testing" entire content)>0]

Expected Result:

<title shortTitle="Improving Web Site Usability">Improving 
the Usability of a Web Site Through Expert Reviews and 
Usability Testing</title>

3 Use Case "ACROSS": Queries Across XML Element Boundaries

3.1 Description

These use cases by default query across XML element boundaries.

Boundaries include XML tags: Start-Tags, End-Tags, and Empty-Element Tags. Descendant XML tags and attribute values are removed from the string to be queried by tokenization before the query. At the XQuery Data Model level tags are a syntactic element.

Find queries in an element which do not query some or all of its descendant elements in Section 14 (IGNORE).

3.2 Queries and Results

3.2.1 Q1 Query Across Descendant Elements (No Element Content)

Find all book chapters containing the phrase "one of the best known lists of heuristics is Ten Usability Heuristics".

This query crosses element boundaries.

  • Operands: "one of the best known lists of heuristics is Ten Usability Heuristics"

  • Functionality: phrase query

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: ./content/part/chapter

  • Return: .

  • Comments: Querying across element boundaries is similar to an XQuery and XPath character string function converting the sub-tree under an element into a string by removing all markup. The citation element tags, including element name and attribute values, have been removed by tokenization.

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $chap := $book//chapter[. ftcontains 
   "one of the best known lists of heuristics is 
   Ten Usability Heuristics"]
where count($chap) > 0
return $book

Solution in XPath:

doc("http://bstore1.example.com/full-text.xml")
/books/book[count(.//chapter ftcontains "one of 
the best known lists of heuristics is Ten Usability 
Heuristics")>0]

Expected Result:

<book number="1">
   <metadata>
      ...
   </metadata>
   <content>
      ...
      <part number="1">
         ...
         <chapter> 
            <title>Heuristic Evaluation</title> 
            <p>Expert reviewers critique an interface to
            determine conformance with recognized 
            usability principles. <footnote>One of the
            best known lists of heuristics is <citation
            url="http://www.useit.com/papers/heuristic
            /heuristic_list.html"> Ten Usability 
            Heuristics by Jacob Nielson</citation>. Another
            is <citation url="http://usability.gov
            /guidelines/index.html"> Research-Based Web
            Design and Usability Guidelines</citation>
            </footnote></p> 
         </chapter>
         ...
      </part>
      ...
   </content>
</book>

3.2.2 Q2 Query Across Descendant Elements (Highlighting Tags)

Find all part introductions containing the word "prototypes".

This query crosses element boundaries.

  • Operands: "prototypes"

  • Functionality: word query

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: ./content/part/introduction

  • Return: .

  • Comments: Querying across element boundaries is similar to an XQuery and XPath character string function converting the sub-tree under an element into a string by removing all markup. The bold element tags, including element name, have been removed by tokenization.

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $intro := $book/content/part/introduction[. ftcontains 
   "prototypes"]
where count($intro)>0
return $book

Solution in XPath:

doc("http://bstore1.example.com/full-text.xml")
/books/book[count(./content/part/introduction ftcontains 
"prototypes")>0]

Expected Result:

<book number="1"> 
   <metadata>
      ...
   </metadata>
   <content>
      ...
      <part number="1">
         <introduction>
            <p>Expert review methods should be
            initiated early in the development process, 
            as soon as paper <b>p</b>rototypes
            (hand-drawn pictures of Web pages) or
            <b>w</b>ireframes (electronic mockups) are
            available. They should be conducted using
            the hardware and software similar to that 
            employed by users.</p>
         </introduction>
         ...
      </part>
      ...
   </content>  
</book>

3.2.3 Q3 Query Across Descendant Elements (Substantive Tags)

Find all book text with the word "tests".

This query finds a word in an element and its descendants.

  • Operands: "tests"

  • Functionality: word query

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: ./content

  • Return: .

  • Comments: Querying across element boundaries is similar to an XQuery and XPath character string function converting the sub-tree under an element into a string by removing all markup. Element tags, including element name and attribute values, have been removed by tokenization, including part, chapter, title, p, component, and componentTitle tags.

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $cont := $book/content[. ftcontains "tests"]
where count($cont)>0
return $book

Solution in XPath:

doc("http://bstore1.example.com/full-text.xml")
/books/book[count(./content ftcontains "tests")>0]

Expected Result:

<book number="1">
   <metadata>
      ...
   </metadata>
   <content>
      ...
      <part number="2">
         <chapter>
            <title>Usability Testing</title>
            <p>Once the problems identified by expert 
            reviews have been corrected, it is time to 
            conduct some tests of the site with your unique 
            audience or audiences by conducting usability 
            testing.</p>
            ...
         </chapter>
      </part> 
      ...
   </content>
</book>      
   
<book number="2">
   <metadata>
      ...
   </metadata>
   <content>
      <introduction>
         <p>This is a basic handbook for planning and 
         conducting usability tests on Web sites. Usability 
         testing should be used in conjunction with other 
         expert review methods.</p>
          ...
      </introduction>
      <part number="1">
         <chapter>
            <title>Planning then Conducting Usability 
            Tests</title>   
            ...
         </chapter>
      </part>   
      ...
   </content>
</book>   

<book number="3">
   <metadata>
      ...
   </metadata>     
   <content>
      ...
      <component>
         <componentTitle>Writings by Usabilityguy
         </componentTitle>
         <subComponent>
           <componentTitle><componentDate normalize="1996">
           1996</componentDate>
           </componentTitle> 
           ...
           <subsubComponent>
           <componentTitle>"How to Evaluate Results from 
           User Tests."</componentTitle>
           </subsubComponent>
         </subComponent>
         ...
      <component>
      ...
   </content>
</book>

3.2.4 Q4 Query Across Siblings

Find all book text with the phrase "usability testing once the problems".

This query finds a phrase which begins in one element and ends in a sibling.

  • Operands: "usability testing once the problems"

  • Functionality: phrase query

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: ./content

  • Return: .

  • Comments: Querying across element boundaries is similar to an XQuery and XPath character string function converting the sub-tree under an element into a string by removing all markup. Element tags, including element name and attribute values, have been removed by tokenization, including title and p tags.

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $cont := $book//content[. ftcontains 
   "usability testing once the problems"]
where count($cont)>0
return $book

Solution in XPath:

doc("http://bstore1.example.com/full-text.xml")
/books/book[count(.//content ftcontains "usability 
testing once the problems")>0]

Expected Result:

<book number="1">
   <metadata>
      ...
   </metadata> 
   <content>
      ...   
      <part number="2">
         <chapter>
            <title>Usability Testing</title>
            <p>Once the problems identified by expert 
            reviews have been corrected, it is time to 
            conduct some tests of the site with your unique 
            audience or audiences by conducting usability 
            testing.</p>
            ...
         </chapter>
      </part> 
   </content>
</book>

3.2.5 Q5 Query in Different Sub-Trees

Find all books with word "identify" in book introductions or part introductions.

This query finds a word in an element in different sub-trees.

  • Operands: "identify"

  • Functionality: word query, character wildcard (suffix) (0 or more)

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: ./content/introduction, ./content/part/introduction

  • Return: .

  • Comments: This query looks for a word in multiple instances of the introduction element which appear as children of the content or part elements.

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $bi := $book/content/introduction[./p ftcontains 
   "identif.*" with wildcards]
let $pi := $book/content/part/introduction[./p ftcontains 
   "identif.*" with wildcards]
where count($bi)>0 and count($pi)>0
return $book

Solution in XPath:

doc("http://bstore1.example.com/full-text.xml")
/books/book[count(./content/introduction ftcontains 
"identif.*" with wildcards and ./content/part/introduction 
ftcontains "identif.*" with wildcards)>0]

Expected Result:

<book number="1">  
   <metadata>
      ...
   </metadata>
   <content>                                          
      <introduction>
         ...
         <p>Expert reviews and usability testing are 
         methods of identifying problems in layout, 
         terminology, and navigation before they frustrate
         users and drive them away from your site.</p>
         ...
      </introduction>
      <part number="1">
         <title>Expert Reviews</title>    
         <introduction>
             <p>Expert reviewers identify problems 
             and recommend changes to web sites based 
             on research in human computer interaction 
             and their experience in the field.</p> 
             ...
         </introduction>
         ...
      </part> 
   </content>
</book> 

3.2.6 Q6 Query on Entire Document

Find all books if any one contains the word "mouse".

This query finds a word in a document (anywhere in the document), crossing all element boundaries

  • Operands: "mouse"

  • Functionality: word query

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books

  • Query context: .

  • Return: .

  • Comments: It queries the root element and all its descendants. Querying across element boundaries is similar to an XQuery and XPath character string function converting the sub-tree under an element into a string by removing all markup. Element tags, including element name and attribute values, have been removed by tokenization. This query looks for a word inside an entire document and returns the entire document if the word exists. It does not employ wildcards, stemming, or thesaurus support. It is similar to search engine queries that search a collection of documents and return a subset of the searched collection.

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
where $book ftcontains "mouse"
return $book

Solution in XPath:

doc("http://bstore1.example.com/full-text.xml")
/books/book[. ftcontains "mouse"]

Expected Result:

<book number="1">
   <metadata>
      ...
   </metadata>
   <content>
      ...
   </content>
</book>

<book number="2">
   <metadata>
      ...
   </metadata>
   <content>
      ...
      <part number="2">
         <chapter>
            <title>Conducting Usability Tests</title> 
            ...
            <p>Give the user the script, then assure them 
            that you are testing the Web site, not them. 
            Users are asked to verbalize their thoughts as 
            they complete the tasks. The event is recorded 
            or someone takes notes. It is often preferable 
            to have two testers, <footnote>Usability 
            testing can be done at great expense or on a 
            shoe string, using <testingProcedure>in-house 
            expertise</testingProcedure> or 
            <testingProcedure>contracting with human 
            computer interaction professionals
            </testingProcedure>.</footnote> one to ask the 
            questions, another to take notes. Testers should 
            offer no guidance or comments to the user. Mouse 
            movements, typing, expressions, and the user's 
            words should be recorded.</p>
         </chapter>
         ...
      </part>
   </content>
</book>

<book number="3">
   <metadata>
      ...
   </metadata>
   <content>
      ...
   </content>
</book>

4 Use Case "OTHER": Queries on Attribute Values

4.1 Description

Unlike all the other use cases in this document which query element content implicitly, these use cases query XML attribute values. Attribute values are not queried implicitly; they are queried explicitly.

4.2 Queries and Results

4.2.1 Q1 Query on Attribute

Find all books with "improve" "web" "usability" in the short title.

This query finds multiple words in an attribute allowing word variants and allowing the words in any order with up to a specified number of intervening words.

  • Operands: "improve" "web" "usability"

  • Functionality: word queries, stemming, unordered distance (0 to 2 intervening words)

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: ./metadata/title/@shortTitle

  • Return: ./metadata/title

  • Comments: This query illustrates full-text querying in an attribute.

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
where $book/metadata/title/@shortTitle ftcontains "improve" 
   ftand "web" ftand "usability" with stemming distance at most 2 words    
return $book/metadata/title

Solution in XPath:

doc("http://bstore1.example.com/full-text.xml")
/books/book[count(./metadata/title/@shortTitle ftcontains 
"improve" ftand "web" ftand "usability" with stemming  
distance at most 2 words)>0]/metadata/title

Expected Result:

<title shortTitle="Improving Web 
Site Usability">Improving the Usability of a 
Web Site Through Expert Reviews and Usability Testing</title>

4.2.2 Q2 Query on Element and Attribute

Find all books with the phrase "manuscript guides" in the short title and the phrase "user profiling" in a component title.

This query finds a phrase in an attribute and a phrase in an element.

  • Operands: "manuscript guides" "user profiling"

  • Functionality: phrase queries, stemming, and query

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: ./metadata/title/@shortTitle, ./componentTitle

  • Return: ./metadata/title/@shortTitle/text()

  • Comments: This query combines querying in an element with querying in an attribute.

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $stitle := $book/metadata/title[./@shortTitle ftcontains 
   "manuscript guides" with stemming]
let $cont := $book//componentTitle[. ftcontains 
   "user profiling" with stemming]
where count($stitle)>0 and count($cont)>0
return data($book/metadata/title/@shortTitle)

Solution in XPath: None

Expected Result:

Usabilityguy Manuscript Guide

5 Use Case "WILDCARD": Character Wildcard Queries

5.1 Description

These use cases illustrate queries which use wildcards to append or insert a character or sequence of characters to a word or a part of a word. Character wildcards may be prefix (appended before the first character), infix (inserted into a word), or suffix (appended after the last character).

5.2 Queries and Results

5.2.1 Q1 One Character Suffix Wildcard Query

Find all books with the word "test" with a one character suffix in the text.

This query finds a word with a one character suffix (one character after the last character).

  • Operands: "test"

  • Functionality: word query, character wildcard (suffix) (1)

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: ./content

  • Return: .

  • Comments: This query finds "tests", but not "pretest, "tested", "testers", "testimony", and "testing" which also appear in the sample data. There is no "test" in the sample data, but if there was, this query would not have found it.

solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $cont := $book/content[. ftcontains "test." 
  with wildcards]
where count($cont)>0
return $book

Solution in XPath:

doc("http://bstore1.example.com/full-text.xml")
/books/book[count(./content ftcontains "test." 
with wildcards)>0]

Expected Result:

<book number="1">
   <metadata>
      ...
   </metadata> 
   <content>
      ...   
      <part number="2">
         <chapter>
            <title>Usability Testing</title>
            <p>Once the problems identified by expert 
            reviews have been corrected, it is time to 
            conduct some tests of the site with your unique 
            audience or audiences by conducting usability 
            testing.</p>
            ...
         </chapter>
      </part>   
   </content>
</book>      

<book number="2">
   <metadata>
      ...
   </metadata> 
   <content>
      <introduction>
         <p>This is a basic handbook for planning and 
         conducting usability tests on Web sites. Usability 
         testing should be used in conjunction with other 
         expert review methods.</p>
         <p>This book has not been approved by the Web Site 
         Users Association.</p>
      </introduction>
      <part number="1">
         <chapter>
            <title>Planning then Conducting Usability 
            Tests</title> 
             ...
         </chapter>
      </part>
      <part number="2">
         <chapter>
            <title>Conducting Usability Tests</title>  
            ...  
         </chapter>
         ...  
      </part>      
      ...                                         
   </content> 
</book>     
   
<book number="3">
   <metadata>
      ...
   </metadata> 
   <content>
      ...   
     <part number="2"><container type="box">3-5</container>
         <title>Writings File, 
         <date normalize="1985/1999">1985-1999</date>
         </title>
         ...
         <component>
            <componentTitle>Writings by Usabilityguy
            </componentTitle>
            <subComponent>
               <componentTitle><componentDate normalize="1996">
               1996</componentDate>
               </componentTitle> 
               ...
               <subsubComponent>
                  <componentTitle>"How to Evaluate Results from 
                  User Tests."</componentTitle>
               </subsubComponent>
               ...
            </subComponent>
            ...
         </component>
         ...
      </part>
      ...
   </content>
</book>

5.2.2 Q2 Zero or One Character Prefix Wildcard Query

Find all books with the word "way" with no prefix or a one character prefix in the text.

This query finds a word with no prefix or a one character prefix (zero or one character before the first character).

  • Operands: "way"

  • Functionality: word query, character wildcard (prefix) (0 or 1)

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: ./content

  • Return: .

  • Comments: There is no "way" in the sample data but if there was, this query would have found it.

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $cont := $book//content[. ftcontains ".?way" 
   with wildcards]
where count($cont)>0
return $book

Solution in XPath:

doc("http://bstore1.example.com/full-text.xml")
/books/book[count(.//content ftcontains ".?way" 
with wildcards)>0]

Expected Result:

<book number="1">
   <metadata>
      ...
   </metadata> 
   <content>
      <introduction>
         ... 
         <p>Expert reviews and usability testing are 
         methods of identifying problems in layout, 
         terminology, and navigation before they frustrate
         users and drive them away from your site.</p>
         ...                
      </introduction>
      ...
   </content>     
</book>

5.2.3 Q3 Zero or More Character Infix Wildcard Query

Find all books with the words "serve" or "service" in the text.

This query finds words with no infix character or any number of infix characters (zero or more characters inserted in the middle of a word).

  • Operands: "serv", "e"

  • Functionality: word query, character wildcard (infix) (0 or more)

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: ./content

  • Return: ./@number, ./metadata/title/text(), ./content

  • Comments: This query returns the word "service" and would return the word "serve" if it existed in the sample data. It does not return the word "served" which exists in the sample data.

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $cont := $book//content[. ftcontains "serv.*e" 
   with wildcards]
where count($cont)>0
return $book/@number, $book/metadata/title/text(), $cont

Solution in XPath:

doc("http://bstore1.example.com/full-text.xml")
/books/book[count(.//content ftcontains "serv.*e" 
with wildcards)>0]/(@number|./metadata/title/text()
|./content)

Expected Result:

<book number="1"></book>
<title>Improving the Usability of a Web Site Through 
Expert Reviews and Usability Testing</title>
<content>
   ...      
   <part number="2">
      <chapter>
        <title>Usability Testing</title>
        ...
        <p>Then changes are made to improve service to 
        users.</p>
      </chapter>
   </part> 
</content>

5.2.4 Q4 One or More Character Suffix Wildcard Query on Part of a Word

Find all books with the phrases "usability testing" or "user testing" in the text.

This query finds a phrase allowing a suffix of one or more characters (one or more characters after the last character) on a part of one of the words.

  • Operands: "us testing"

  • Functionality: phrase query, character wildcard (suffix) (1 or more)

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: ./content

  • Return: ./@number, ./metadata/title/text(), ./content

  • Comments: This is a suffix query on a part of a word "us" which is not one of the words or one of the roots of the words desired in the results. The query on "us" will find "usability" and "user". Where stemmed queries (Section 6 (STEMMING)) attempt to return linguistic variants of a word or the root of a word, wildcards may be applied to any part of a word and will return all character combinations found.

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $cont := $book//content[. ftcontains "us.+ testing" 
   with wildcards]
where count($cont)>0
return $book/@number, $book/metadata/title/text(), $cont

Solution in XPath:

doc("http://bstore1.example.com/full-text.xml")
/books/book[count(.//content ftcontains "us.+ testing" 
with wildcards)>0]/(@number|./metadata/title/text()|./content)

Expected Result:

<book number="1"></book>  
<title>Improving the Usability of a Web Site Through 
Expert Reviews and Usability Testing</title>
<content>
   <introduction>
      ...
      <p>Expert reviews and usability testing are 
      methods of identifying problems in layout, 
      terminology, and navigation before they frustrate
      users and drive them away from your site.</p>
      ...
   </introduction>
   ...
   <part number="2">
      ...
      <chapter>
         <title>Usability Testing</title>
         <p>Once the problems identified by expert 
         reviews have been corrected, it is time to 
         conduct some tests of the site with your unique 
         audience or audiences by conducting usability 
         testing.</p>
         ...
      </chapter>
   </part> 
</content>
   
<book number="2"></book>  
<title>Usability Basics: How to Plan for and Conduct 
Usability Tests on Web Site Thereby Improving the 
Usability of Your Web Site</title> 
<content>
   <introduction>
      <p>This is a basic handbook for planning and 
      conducting usability tests on Web sites. Usability
      testing should be used in conjunction with other 
      expert review methods.</p>
      ...
   </introduction>
   <part number="1">
      ...
      <chapter>
         <p>Take the following steps to plan usability
         testing. <step number="1">Clarify and 
         articulate the goal of the usability testing. 
         <step number="1">Clarify and 
         articulate the goal of the usability testing.
         </step> <step number="2">Identify tasks which 
         are critical for users to be able to complete 
         successfully.</step> <step number="3">Compile 
         a script of questions or instructions which 
         will prompt the user to attempt those 
         tasks.</step> <step number="4">Identify your 
         users and begin recruiting them.</step> <step 
         number="5">Conduct a pretest on a few users.
         </step> <step number="6">Edit the script based 
         on insights gleaned from the pretest.</step> 
         <step number="7">Resume testing.</step></p>
      </chapter>
   </part>
   <part number="2">
      <chapter>
         <title>Conducting Usability Tests</title> 
         ...
         <p>Give the user the script, then assure them 
         that you are testing the Web site, not them. 
         Users are asked to verbalize their thoughts as 
         they complete the tasks. The event is recorded 
         or someone takes notes. It is often preferable 
         to have two testers, <footnote>Usability
         testing can be done at great expense or on a 
         shoe string, using <testingProcedure>in-house 
         expertise</testingProcedure> or 
         <testingProcedure>contracting with human 
         computer interaction professionals
         </testingProcedure>.</footnote> one to ask the 
         questions, another to take notes. Testers should 
         offer no guidance or comments to the user. Mouse 
         movements, typing, expressions, and the user's 
         words should be recorded.</p>
      </chapter>
      ...
   </part>
</content>

<book number="3"></book>  
<title>John Wesley Usabilityguy: A Register of His 
Papers</title>   
<content>
   ...
   <part number="2"><container type="box">3-5</container>
      <title>Writings File, 
      <date normalize="1985/1999">1985-1999</date>
      </title>
      ...
      <component>
         <componentTitle>Writings by Usabilityguy
         </componentTitle>
         <subComponent>
            <componentTitle><componentDate normalize="1996">
            1996</componentDate>
            </componentTitle> 
            <subsubComponent>
               <componentTitle>"How Many Users Are Enough 
               for User Testing?"</componentTitle>
            </subsubComponent> 
            ...
            <subsubComponent>
               <subsubComponent><componentTitle>"Do-It-
               Yourself User Testing"
               </componentTitle>
            </subsubComponent> 
         </subComponent>
      </component>
      ...
   </part>      
</content>

5.2.5 Q5 Specified Range of Characters Suffix Wildcard Query

Find all books with the word "test" with a three to four character suffix in the text.

This query finds a word with a number of characters within a specified range in a suffix (specified range of characters after the last character).

  • Operands: "test"

  • Functionality: word query, character wildcard (suffix) (3 to 4)

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: ./content

  • Return: ./@number, ./content

  • Comments: This query allows any three or four character suffix. It returns "testers" and "testing", but not "pretest" "tests" and "tested" which also appear in the sample data. There is no "test" in the sample data, but if there was, this query would not have found it.

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $cont := $book//content[. ftcontains "test.{3,4}" 
   with wildcards]
where count($cont)>0
return $book/@number, $cont

Solution in XPath:

doc("http://bstore1.example.com/full-text.xml")
/books/book[count(./content ftcontains "test.{3,4}" 
with wildcards)>0]/(@number|./content)

Expected Result:

<book number="1"></book>
<content>
   <introduction>
      ...
      <p>Expert reviews and usability testing are 
      methods of identifying problems in layout, 
      terminology, and navigation before they frustrate
      users and drive them away from your site.</p>
      ...
   </introduction>
   ...
   <part number="2">
      <chapter>
         <title>Usability Testing</title>
         <p>Once the problems identified by expert 
         reviews have been corrected, it is time to 
         conduct some tests of the site with your unique 
         audience or audiences by conducting usability 
         testing.</p>
         ...
      </chapter>
   </part> 
</content>
                                                
<book number="2"></book>
<content>
   <introduction>
      <p>This is a basic handbook for planning and 
      conducting usability tests on Web sites. Usability
      testing should be used in conjunction with other 
      expert review methods.</p>
      ...
   </introduction>
   <part number="1">
      <chapter>
         <p>Take the following steps to plan >usability
         testing. <step number="1">Clarify and 
         articulate the goal of the >usability testing. 
         <step number="1">Clarify and 
         articulate the goal of the usability testing.
         </step> <step number="2">Identify tasks which 
         are critical for users to be able to complete 
         successfully.</step> <step number="3">Compile 
         a script of questions or instructions which 
         will prompt the user to attempt those 
         tasks.</step> <step number="4">Identify your 
         users and begin recruiting them.</step> <step 
         number="5">Conduct a pretest on a few users.
         </step> <step number="6">Edit the script based 
         on insights gleaned from the pretest.</step> 
         <step number="7">Resume testing.</step></p>
      </chapter>
   </part>
   <part number="2">
      <chapter>
         <title>Conducting Usability Tests</title> 
         ...
         <p>Give the user the script, then assure them 
         that you are testing the Web site, not them. 
         Users are asked to verbalize their thoughts as 
         they complete the tasks. The event is recorded 
         or someone takes notes. It is often preferable 
         to have two testers, <footnote>Usability
         testing can be done at great expense or on a 
         shoe string, using <testingProcedure>in-house 
         expertise</testingProcedure> or 
         <testingProcedure>contracting with human 
         computer interaction professionals
         </testingProcedure>.</footnote> one to ask the 
         questions, another to take notes. Testers should 
         offer no guidance or comments to the user. Mouse 
         movements, typing, expressions, and the user's 
         words should be recorded.</p>
      </chapter>
      <chapter>
         <title>Evaluating and Implementing Results</title> 
         <p>Compile the results and review collectively. 
         Make changes to the site to alleviate the problems 
         found in Web site components which were propagating 
         the largest number of or the most devastating errors. 
         Begin new iterations of testing and changes, until 
         users are successful in the accomplishing the 
         tasks.</p>
      </chapter>
   </part>
</content>

<book number="3"></book>
<content>
   ...
   <part number="2"><container type="box">3-5</container>
      <title>Writings File, 
      <date normalize="1985/1999">1985-1999</date>
      </title>
      ...
      <component>
         <componentTitle>Writings by Usabilityguy
         </componentTitle>
         <subComponent>
            <componentTitle><componentDate normalize="1996">
            1996</componentDate>
            </componentTitle> 
            <subsubComponent>
               <componentTitle>"How Many Users Are Enough 
               for User Testing?"</componentTitle>
            </subsubComponent> 
            ...
            <subsubComponent>
               <componentTitle>"When Are You Done Testing?"
               </componentTitle>
            </subsubComponent>
            <subsubComponent>
               <componentTitle>"Do-It-Yourself User Testing"
               </componentTitle>
            </subsubComponent> 
         </subComponent>
      </component>
      ...
   </part>      
</content>

6 Use Case "STEMMING": Word Stemming Queries

6.1 Description

These use cases invoke a stemming algorithm (e.g., Porter) which returns noun, verb, adjective, and adverb forms of a word or root of a word in singular and plural.

6.2 Queries and Results

6.2.1 Q1 Query Stemming on Word Root

Find all books with the word "test" in the text.

This query finds a word and its variants applying a stemming algorithm.

  • Operands: "test"

  • Functionality: word query, stemming

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: ./content

  • Return: .

  • Comments: Unlike the wildcard queries in Section 5 (WILDCARD) which allow any suffix, this query will not return the word "testimony" which occurs in the sample data.

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $cont := $book//content[. ftcontains "test" 
   with stemming]
where count($cont)>0
return $book

Solution in XPath:

doc("http://bstore1.example.com/full-text.xml")
/books/book[count(.//content ftcontains "test" 
with stemming)>0]

Expected Result:

<book number="1">
   <metadata>
      ...
   </metadata> 
   <content>
      <introduction>
         ...
         <p>Expert reviews and usability testing are 
         methods of identifying problems in layout, 
         terminology, and navigation before they frustrate
         users and drive them away from your site.</p>
         ...
      </introduction>
      ...
      <part number="2">
         <chapter>
            <title>Usability Testing</title>
            <p>Once the problems identified by expert 
            reviews have been corrected, it is time to 
            conduct some tests of the site with your unique 
            audience or audiences by conducting usability 
            testing.</p>
            ...
         </chapter>
      </part> 
   </content>
</book>                                                   

<book number="2">
   <metadata>
      ...
   </metadata> 
   <content>
      <introduction>
         <p>This is a basic handbook for planning and 
         conducting usability tests on Web sites. Usability 
         testing should be used in conjunction with other 
         expert review methods.</p>
         ...
      </introduction>
      <part number="1">
         <chapter>
            <title>Planning then Conducting Usability 
            Tests</title> 
            <p>Take the following steps to plan usability 
            testing. <step number="1">Clarify and 
            articulate the goal of the usability testing.
            </step> <step number="2">Identify tasks which 
            are critical for users to be able to complete 
            successfully.</step> <step number="3">Compile 
            a script of questions or instructions which 
            will prompt the user to attempt those 
            tasks.</step> <step number="4">Identify your 
            users and begin recruiting them.</step> <step 
            number="5">Conduct a pretest on a few users.
            </step> <step number="6">Edit the script based 
            on insights gleaned from the pretest.</step> 
            <step number="7">Resume testing.</step></p>
         </chapter>
      </part>
      <part number="2">
         <chapter>
            <title>Conducting Usability Tests</title> 
            <p>Users can be tested at any computer 
            workstation <footnote>They may be more 
            comfortable at their own workstation than in 
            a lab.</footnote> or in a lab.</p>
            <p>Give the user the script, then assure them 
            that you are testing the Web site, not them. 
            Users are asked to verbalize their thoughts as 
            they complete the tasks. The event is recorded 
            or someone takes notes. It is often preferable 
            to have two testers, <footnote>Usability 
            testing can be done at great expense or on a 
            shoe string, using <testingProcedure>in-house 
            expertise</testingProcedure> or 
            <testingProcedure>contracting with human 
            computer interaction professionals
            </testingProcedure>.</footnote> one to ask the 
            questions, another to take notes. Testers should 
            offer no guidance or comments to the user. Mouse 
            movements, typing, expressions, and the user's 
            words should be recorded.</p>
         </chapter>
         <chapter>
            <title>Evaluating and Implementing Results</title> 
            <p>Compile the results and review collectively. 
            Make changes to the site to alleviate the problems 
            found in Web site components which were propagating 
            the largest number of or the most devastating errors. 
            Begin new iterations of testing and changes, until  
            users are successful in the accomplishing the 
            tasks.</p>
         </chapter>
      </part>
   </content>
</book>    

<book number="3">
   <metadata>
      ...
   </metadata> 
   <content>
      ...   
      <part number="2"><container type="box">3-5</container>
         <title>Writings File, 
         <date normalize="1985/1999">1985-1999</date>
         </title>
         ...
         <component>
            <componentTitle>Writings by Usabilityguy
            </componentTitle>
            <subComponent>
               <componentTitle><componentDate normalize="1996">
               1996</componentDate>
               </componentTitle> 
               <subsubComponent>
                  <componentTitle>"How Many Users Are Enough 
                  for User Testing?"</componentTitle>
               </subsubComponent> 
               <subsubComponent>
                  <componentTitle>"How to Evaluate Results from 
                  User Tests."</componentTitle>
               </subsubComponent>
               <subsubComponent>
                  <container type="box">5</container>
                  <componentTitle>"When Are You Done Testing?
                  </componentTitle>
               </subsubComponent>
               <subsubComponent>
                  <componentTitle>"Do-It-Yourself User Testing"
                  </componentTitle>
               </subsubComponent> 
            </subComponent>
         </component>
         ...
      </part>   
   </content>
</book>

6.2.2 Q2 Query Stemming on Multiple Word Roots

Find all books with the phrases "usability testing" or "user testing" in the text.

This query finds phrases applying a stemming algorithm to selected words within the phrases.

  • Operands: "usability testing" "use testing"

  • Functionality: phrase queries, stemming

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: ./content

  • Return: ./@number, ./metadata/title/text(), ./content

  • Comments: This query applies stemming to one word in a phrase. Unlike the wildcard queries in Section 5 (WILDCARD) which allow any suffix, a stemmed query on "us" will not return "user" and "usability", because they do not share the share root. This query uses an or query introduced in Section 10 (LOGICAL).

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $cont := $book//content[. ftcontains 
   (("usable" with stemming) ftand "testing" phrase) 
   ftor (("use" with stemming) ftand "testing" phrase)]
where count($cont)>0
return $book/@number, $book/metadata/title/text(), $cont

Solution in XPath:

doc("http://bstore1.example.com/full-text.xml")
/books/book[count(.//content ftcontains (("usable" with stemming) 
ftand "testing" phrase) ftor (("use" with stemming) 
ftand "testing" phrase))>0]/(@number|./metadata/title/text()
|./content)

Expected Result:

<book number="1"></book>  
<title>Improving the Usability of a Web Site Through 
Expert Reviews and Usability Testing</title>
<content>
   <introduction>
      ...
      <p>Expert reviews and usability testing are 
      methods of identifying problems in layout, 
      terminology, and navigation before they frustrate
      users and drive them away from your site.</p>
      ...
   </introduction>
   ...
   <part number="2">
      <chapter>
         <title>Usability Testing</title>
         <p>Once the problems identified by expert 
         reviews have been corrected, it is time to 
         conduct some tests of the site with your unique 
         audience or audiences by conducting usability 
         testing.</p>
         ...
      </chapter>
   </part> 
</content>
    
<book number="2"></book>  
<title>Usability Basics: How to Plan for and Conduct 
Usability Tests on Web Site Thereby Improving the 
Usability of Your Web Site</title> 
<content>
   <introduction>
      <p>This is a basic handbook for planning and 
      conducting usability tests on Web sites. Usability
      testing should be used in conjunction with other 
      expert review methods.</p>
      ...
   </introduction>
   <part number="1">
      <chapter>
         <p>Take the following steps to plan usability
      testing. <step number="1">Clarify and 
          articulate the goal of the usability testing. 
         <step number="1">Clarify and 
         articulate the goal of the usability testing.
         </step> <step number="2">Identify tasks which 
         are critical for users to be able to complete 
         successfully.</step> <step number="3">Compile 
         a script of questions or instructions which 
         will prompt the user to attempt those 
         tasks.</step> <step number="4">Identify your 
         users and begin recruiting them.</step> <step 
         number="5">Conduct a pretest on a few users.
         </step> <step number="6">Edit the script based 
         on insights gleaned from the pretest.</step> 
         <step number="7">Resume testing.</step></p>
      </chapter>
   </part>
   <part number="2">
      <chapter>
         <title>Conducting Usability Tests</title> 
         ...
         <p>Give the user the script, then assure them 
         that you are testing the Web site, not them. 
         Users are asked to verbalize their thoughts as 
         they complete the tasks. The event is recorded 
         or someone takes notes. It is often preferable 
         to have two testers, <footnote>Usability
         testing can be done at great expense or on a 
         shoe string, using <testingProcedure>in-house 
         expertise</testingProcedure> or 
         <testingProcedure>contracting with human 
         computer interaction professionals
         </testingProcedure>.</footnote> one to ask the 
         questions, another to take notes. Testers should 
         offer no guidance or comments to the user. Mouse 
         movements, typing, expressions, and the user's 
         words should be recorded.</p>
      </chapter>
      ...
   </part>
</content>

<book number="3"></book>  
<title>John Wesley Usabilityguy: A Register of His 
Papers</title>   
<content>
   ...
   <part number="2"><container type="box">3-5</container>
      <title>Writings File, 
      <date normalize="1985/1999">1985-1999</date>
      </title>
      ...
      <component>
         <componentTitle>Writings by Usabilityguy
         </componentTitle>
         <subComponent>
            <componentTitle><componentDate normalize="1996">
            1996</componentDate>
            </componentTitle> 
            <subsubComponent>
               <componentTitle>"How Many Users Are Enough 
               for User Testing?"</componentTitle>
            </subsubComponent> 
            ...
            <subsubComponent>
               <subsubComponent><componentTitle>"Do-It-
               Yourself User Testing"
               </componentTitle>
            </subsubComponent> 
         </subComponent>
      </component>
      ...
   </part>      
</content>

7 Use Case "THESAURUS": Queries Which Use Thesauri, Dictionaries, and Taxonomies

7.1 Description

These use cases illustrate queries which return synonyms or related words identified by thesauri, dictionaries, and taxonomies.

7.2 Queries and Results

7.2.1 Q1 Query on Synonyms Identified by a Thesaurus

Find all introductions which quote someone.

This query finds words and phrases using a thesaurus to return synonyms.

  • Operands: "quote"

  • Functionality: word query, thesaurus support

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: .//introduction

  • Return: .

  • Comments: This query uses thesaurus support to identify synonyms for the word "quote" via preferred and used for terms: "said", "says", "stated", "states", "spoke", "speaks", "replied", "replies", "reply", "remarks", "remarked", "responded", "response", "reports", "reported", "quotes", "quoted", "according to", "commented", "discussed", "expressed", and "told". These words and phrases become additional operands.

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $intro := $book//introduction[. ftcontains "quote" 
   with thesaurus at
   "http://bstore1.example.com/UsabilityThesaurus.xml" 
   relationship "synonyms"]
where count($intro)>0
return $book

Solution in XPath:

doc("http://bstore1.example.com/full-text.xml")
/books/book[count(.//introduction ftcontains "quote" 
with thesaurus at 
"http://bstore1.example.com/UsabilityThesaurus.xml" 
relationship "synonyms")>0]

Expected Result:

<book number="1">
   <metadata>
      ...
   </metadata> 
   <content>
      ...   
      <introduction>
         ...
         <p>The most successful projects employ multiple 
         methods in multiple iterations. As Millicent 
         Marigold remarked during a recent conference, 
         "Don't stop. Iterate, iterate, then iterate 
         again."</p>
         ...
      </introduction>
   </content>      
</book>

7.2.2 Q2 Query on Narrower Terms Identified by a Thesaurus

Find all books with text on improving "web site components".

This query finds words using a thesaurus to identify narrower terms.

  • Operands: "web site components"

  • Functionality: phrase query, thesaurus support

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: ./content

  • Return: .

  • Comments: This query employs a thesaurus to identify web site components via narrower terms: "layout", "terminology", "graphics", "menus", and "navigation". These words become additional operands.

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $cont := $book/content[. ftcontains "web site components" 
   with thesaurus at 
   "http://bstore1.example.com/UsabilityThesaurus.xml" 
   relationship "narrower terms" at most 2 levels]
where count($cont)>0
return $book

Solution in XPath:

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)>0]

Expected Result:

<book number="1">
   <metadata>
      ...
   </metadata> 
   <content>
      <introduction>
         ...   
         <p>Expert reviews and usability testing are 
         methods of identifying problems in layout, 
         terminology, and navigation before they frustrate
         users and drive them away from your site.</p> 
         ... 
      </introduction>                   
      ... 
   </content>  
</book>   
      
<book number="2">
   <metadata>
      ...
   </metadata> 
   <content>
      ... 
      <part number="2">
         ...
         <chapter>
            <title>Evaluating and Implementing Results</title>   
            <p>Compile the results and review collectively. 
            Make changes to the site to alleviate the problems 
            found in Web site components which were propagating 
            the largest number of or the most devastating errors. 
            Begin new iterations of testing and changes, until 
            users are successful in the accomplishing the 
            tasks.</p>  
         </chapter>
      </part>       
   </content>
</book>

7.2.3 Q3 Query on Broader Terms Identified by a Thesaurus

Are there any "letters" or "holiday cards" in John Wesley Usabilityguy's papers?

This query finds words and phrases using a thesaurus to identify broader terms.

  • Operands: "letters" "holiday cards"

  • Functionality: word query, phrase query, thesaurus support

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book[@number="3"]

  • Query context: ./content

  • Return: .

  • Comments: This query employs a thesaurus to identify the broader term "correspondence". It becomes an additional operand.

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book[@number="3"]
let $cont := $book/content[. ftcontains 
   "letters" ftor "holiday cards" with thesaurus at 
   "http://bstore1.example.com/UsabilityThesaurus.xml" 
   relationship "BT" exactly 1 levels]
where count($cont)>0
return $book

Solution in XPath:

doc("http://bstore1.example.com/full-text.xml")
/books/book[count(./content ftcontains "letters" 
ftor "holiday cards" with thesaurus at 
"http://bstore1.example.com/UsabilityThesaurus.xml" 
relationship "BT" exactly 1 levels)>0]

Expected Result:

<book number="3">
   <metadata>
      ...
   </metadata> 
   <content>
      <introduction>
         <p>The papers of John Wesley Usabilityguy span the 
         years 1946-2001, with the bulk of the items 
         concentrated in the period from 1985 to 2001. The 
         papers feature his career as a developer of software 
         applications and usability specialist. The collection 
         consists of correspondence, memoranda, journals, 
         speeches, article drafts, book drafts, notes, charts, 
         graphs, family papers, clippings, printed matter, 
         photographs, résumés and other materials.</p>
      </introduction>
      <part number="1"><container type="box">1-12</container>
         <title>Subject File, <date normalize="1930/1974">
         1930-1974</date></title>
         <introduction>
            <p>Correspondence, telegrams, memoranda, journals, 
            logs, testimony, approved travel orders, invitations, 
            charts, graphs, forms, biographical data, photographs, 
            book drafts, clippings and other printed matter, 
            résumés and miscellaneous material. Organized by 
            name of person or organization, topic, or type of 
            material.</p>
         </introduction>            
      </part>
      <part number="2"><container type="box">3-5</container>
         <title>Writings File, 
         <date normalize="1985/1999">1985-1999</date>
         </title>
         <introduction>
            <p>Correspondence, articles, book drafts, notes,
            contracts, clippings, and printed matter. Arranged 
            alphabetically by type (articles, books, reports, 
            and miscellaneous) and therein alphabetically by 
            type of material, subject, or title.</p>
         </introduction>    
         ...        
      </part>
   </content>    
</book>

7.2.4 Q4 Query on Word Which Sounds Like Other Words

Find all books with words which sound like "Merrygould".

This query finds words using a dictionary of words which sound like the word queried.

  • Operands: "Merrygould"

  • Functionality: word query, sounds-like dictionary support

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: .

  • Return: .

  • Comments: This query uses sounds-like support to identify words which sound like the word "Merrygould". It returns the word "Marigold". Examples of how this query is implemented include keeping a list of similar words (akin to a thesaurus) or using a system based on phonetic similarity.

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book[. ftcontains "Merrygould" 
   with thesaurus at 
   "http://bstore1.example.com/UsabilitySoundex.xml" 
   relationship "sounds like"]
where count($cont)>0
return $book

Solution in XPath:

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")>0]

Expected Result:

<book number="1">
   <metadata>
      <title shortTitle="Improving Web Site Usability">Improving 
      the Usability of a Web Site Through Expert Reviews and 
      Usability Testing</title>
      <author>Millicent Marigold</author>
      <author>Montana Marigold</author>
      ...
   </metadata>
   <content>
      <introduction>
         ...
         <p>The most successful projects employ multiple 
         methods in multiple iterations. As Millicent 
         Marigold remarked during a recent conference, 
         "Don't stop. Iterate, iterate, then iterate 
         again."</p>
         ...
      </introduction>
   </content>   
</book>
   
<book number="3">
   <metadata>
      <title shortTitle="Usabilityguy Manuscript 
      Guide">John Wesley Usabilityguy: A Register of His 
      Papers</title>
      <author>Millicent Marigold</author>
      <author>Morty Marigold</author>
      ...
   </metadata>
   <content>
      ...   
   </content>   
</book>

7.2.5 Q5 Query on Word Spelled Similarly to Other Words

Find all books which contain words that are close in spelling to "sucessfull".

This query finds words using a dictionary of words that are spelled similarly.

  • Operands: "sucessfull"

  • Functionality: word query, similarly spelled dictionary support

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: .

  • Return: .

  • Comments: This query uses support for similarly spelled words to identify words close in spelling to "sucessfull". It returns the word "successful". Examples of how this query is implemented include keeping a list of similar words (akin to a thesaurus) or using a system based on spelling similarities.

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book[. ftcontains "sucessfull" 
   with thesaurus at 
   "http://bstore1.example.com/spellcheck.xml" 
   relationship "misspelling of"]
where count($cont)>0  
return $book

Solution in XPath:

doc("http://bstore1.example.com/full-text.xml")
/books/book[count(. ftcontains "sucessfull" 
with thesaurus at 
"http://bstore1.example.com/spellcheck.xml" 
relationship "misspelling of")>0]

Expected Result:

<book number="1">
   <metadata>
      ...
   </metadata> 
   <content>
      ...   
      <introduction>
         ...
         <p>The most successful projects employ multiple 
         methods in multiple iterations. As Millicent 
         Marigold remarked during a recent conference, 
         "Don't stop. Iterate, iterate, then iterate 
         again."</p>
         ...
      </introduction>
      <part number="1">
         <title>Expert Reviews</title>
         ...
         <chapter>
            <title>Cognitive Walk-Through</title>
            <p>Expert reviewers evaluate Web site 
            understandability and ease of learning while 
            performing specified tasks. They walk through 
            the site answering questions such as "Would a 
            user know by looking at the screen how to 
            complete the first step of the task?" and "If 
            the user completed the first step, would the 
            user know what to do next?," with the goal of 
            identifying any obstacles to completing the 
            task and assessing whether the user would 
            cognitively be aware that he was successful in 
            completing a step in the process.</p>
         </chapter>
      </part>   
      ...
   </content>  
</book>    

<book number="2">
   <metadata>
      ...
   </metadata> 
   <content>
      ...   
      <part number="2">
         ...
         <chapter>
            <title>Evaluating and Implementing Results</title> 
            <p>Compile the results and review collectively. 
            Make changes to the site to alleviate the problems 
            found in Web site components which were propagating 
            the largest number of or the most devastating errors. 
            Begin new iterations of testing and changes, until 
            users are successful in the accomplishing the 
            tasks.</p>
         </chapter>
      </part>
   </content>   
</book>

7.2.6 Q6 Query on Subordinate Terms Identified by a Taxonomy

Find out whether John Wesley Usabilityguy included research on "AIDS" and "other infectious diseases" among the charities he supported.

This query finds words using a taxonomy to identify subordinate terms.

  • Operands: "AIDS"

  • Functionality: word query, case-sensitivity (limited to upper case), taxonomy support

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book[@number="3"]

  • Query context: ./content/part/component

  • Return: .

  • Comments: This query uses a taxonomy to identify other infectious diseases: "Hepatitis" and "Tuberculosis". These words become additional operands.

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book[@number="3"]
let $comp := $book//component[. ftcontains "AIDS" uppercase 
   with thesaurus at 
   "http://bstore1.example.com/OurTaxonomy.xml" 
   relationship "disease in this category"]
where count($comp)>0
return $book

Solution in XPath:

doc("http://bstore1.example.com/full-text.xml")
/books/book[@number="3" and count(.//component ftcontains "AIDS" 
uppercase with thesaurus at 
"http://bstore1.example.com/OurTaxonomy.xml" 
relationship "disease in this category")>0]

Expected Result:

<book number="3"> 
   <metadata>
      ...
   </metadata> 
   <content>
      ...   
      <part number="2"><container type="box">3-5</container>
         <title>Writings File, 
         <date normalize="1985/1999">1985-1999</date>
         </title>
         ...
         <component>
            <componentTitle>Charitable Contributions
            </componentTitle> 
            <subComponent>
               <componentTitle>Diseases: AIDS, Hepatitis, 
               Tuberculosis<componentDate normalize=
               "1990/1999">1990-1999</componentDate>
               </componentTitle>
            </subComponent> 
            <subComponent>
               <componentTitle>Environmental Conservation: 
               Rivers <componentDate normalize="1995">1995
               </componentDate>
               </componentTitle>
            </subComponent>
         </component>
      </part>
   </content>      
</book>

8 Use Case "STOP-WORD": Queries on Stop Words

8.1 Description

These use cases query a phrase, one word of which has been identified as a stop word via a stop word list. The first treats the stop word as a stop word. The second does not, making it available again for querying. Another query calls a stop word list then excludes a word on the list making that word available for querying.

Words identified as stop words may be routinely eliminated from queries, allowing any word to be substituted.

8.2 Queries and Results

8.2.1 Q1 Query on Stop Word Treated as a Stop Word

Find all books with the phrase "planning then conducting" in the text where "then" is treated as a stop word.

This query finds a phrase substituting any word for a word which has been identified as a stop word via a stop word list.

  • Operands: "planning then conducting"

  • Functionality: stop word (then), phrase query

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: ./content

  • Return: .

  • Comments: Once the stop word "then" has been identified via the stop word list at http://bstore1.example.com/StopWordList.xml, this query is reduced to a query on the phrase "planning" any word "conducting", allowing any word as a substitute for the stop word. It finds both "planning and conducting" and "planning then conducting" in the sample data.

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $cont := $book//content[. ftcontains 
   "planning then conducting" with stop words 
   at "http://bstore1.example.com/StopWordList.xml"]
where count($cont)>0
return $book

Solution in XPath:

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")>0]

Expected Result:

<book number="2">
   <metadata>
      ...
   </metadata> 
   <content>
      <introduction>
         <p>This is a basic handbook for planning and 
         conducting usability tests on Web sites. Usability  
         testing should be used in conjunction with other 
         expert review methods.</p>
         <p>This book has not been approved by the Web Site 
         Users Association.</p>
      </introduction>
      <part number="1">
         <chapter>
            <title>Planning then Conducting Usability
            Tests</title> 
            ...
         </chapter>
      </part> 
      ...
   </content>
</book>

8.2.2 Q2 Query on Stop Word Not Treated as a Stop Word

Find all books with the phrase "planning then conducting" in the text where "then" is not treated as a stop word.

This query does not eliminate a word from the query even though it has been identified as a stop word in the stop word list, making it available again for querying.

  • Operands: "planning then conducting"

  • Functionality: stop word (then), phrase query

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: ./content

  • Return: .

  • Comments: Even though the word "then" has been identified as a stop word, this query makes it available again for querying. It finds only "planning then conducting" in the sample data.

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $cont := $book//content[. ftcontains 
   "planning then conducting" without stop words]
where count($cont)>0
return $book

Solution in XPath:

doc("http://bstore1.example.com/full-text.xml")
/books/book[count(.//content ftcontains "planning then 
conducting" without stop words)>0]

Expected Result:

<book number="2">
   <metadata>
      ...
   </metadata> 
   <content>
      ...
      <part number="1">
         <chapter>
            <title>Planning then Conducting Usability
            Tests</title> 
            ...
         </chapter>
      </part> 
      ...
   </content>
</book>

8.2.3 Q3 Query Excluding a Stop Word on a Stop Word List

Find books with the phrase "not been approved" in the text.

This query finds a phrase substituting any words for words which have been identified as stop words via a stop word list, removing the word "not" temporarily from the stop word list.

  • Operands: "not been approved"

  • Functionality: phrase query, stop word list (not, been), the stop word "not" is excluded from the list and used in the query

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: ./content

  • Return: ./metadata/title, ./content

  • Comments: The stop words "not" and "been" are identified via a stop word list, however the stop word "not" is removed temporarily from the stop word list and used as an operand in the query. The query becomes a query on the phrase "not" [any word] "approved", allowing any word as a substitute for the stop word "been". It does not return books with the word "approved" in the phrases "been approved" and "approved travel orders" in the sample data.

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $cont := $book/content[. ftcontains 
   "not been approved" with stop words at
   "http://bstore1.example.com/StopWordList.xml" 
   except ("not")]
where count($cont)>0
return $book/metadata/title, $book/content

Solution in XPath:

doc("http://bstore1.example.com/full-text.xml")
/books/book[count(./content ftcontains "not been 
approved" with stop words at 
"http://bstore1.example.com/StopWordList.xml" 
except ("not"))>0]/(./metadata/title|./content)

Expected Result:

<title shortTitle="Usability Basics">Usability 
Basics: How to Plan for and Conduct 
Usability Tests on Web Site Thereby Improving the 
Usability of Your Web Site</title>
<content>
   ...          
   <p>This book has not been approved by the Web Site 
   Users Association</p>
   ...     
</content>

9 Use Case "CHARACTER": Queries Specifying Normalized Forms of Characters and Tokenized Words

9.1 Description

These use cases illustrate queries on words entered with diacritics sometimes finding the same; other times finding words with and without diacritics. They query words entered in upper case sometimes finding the same; other times finding words in both upper and lower case.

9.2 Queries and Results

9.2.1 Q1 Query on Word with Characters with Diacritics

Verify the existence of a "résumé" in the papers of John Wesley Usabilityguy.

This query finds a word only when diacritics are present.

  • Operands: "résumé"

  • Functionality: word query, functionality requiring presence of characters with diacritics, character wildcard (suffix) (1)

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: ./content

  • Return: .

  • Comments: The desired results include only the words "résumé" and "résumés" with diacritics, not the more often used words "resume" (which is present in the sample data) and "resumes".

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $cont := $book//content[. ftcontains "résumé." 
   with wildcards with diacritics]
where count($cont) >0    
return $book

Solution in XPath:

doc("http://bstore1.example.com/full-text.xml")
/books/book[count(.//content ftcontains "résumé." 
with wildcards with diacritics)>0]

Expected Result:

<book number="3">
   <metadata>
      ...
   </metadata> 
   <content>
      <introduction>
         <p>The papers of John Wesley Usabilityguy span the 
         years 1946-2001, with the bulk of the items 
         concentrated in the period from 1985 to 2001. The 
         papers feature his career as a developer of software 
         applications and usability specialist. The collection 
         consists of correspondence, memoranda, journals, 
         speeches, article drafts, book drafts, notes, charts, 
         graphs, family papers, clippings, printed matter, 
         photographs, résumés and other materials.</p>
      </introduction>
      <part number="1"><container type="box">1-12</container>
         <title>Subject File, <date normalize="1930/1974">
         1930-1974</date></title>
         <introduction>
            <p>Correspondence, telegrams, memoranda, journals, 
            logs, testimony, approved travel orders, invitations, 
            charts, graphs, forms, biographical data, photographs, 
            book drafts, clippings and other printed matter, 
            résumés and miscellaneous material. Organized by 
            name of person or organization, topic, or type of 
            material.</p>
         </introduction>
         ...
      </part>
      ...   
   </content>
</book>

9.2.2 Q2 Query on Word with Characters with and Without Diacritics

Verify the existence of a résumé in the papers of John Wesley Usabilityguy.

This query finds a word whether its diacritics are present or not.

  • Operands: "resume"

  • Functionality: word query, functionality allowing substitution of characters with and without diacritics, character wildcard (suffix) (1)

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: ./content

  • Return: .

  • Comments: The desired results include either the words "résumé" or "résumés" with diacritics or the words "resume" or "resumes" without diacritics. The user wants to find résumé, but has entered resume possibly because the system does not allow the entry of diacritics, the user does not know how to enter diacritics, or the user did not want to take the time to enter them.

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $cont := $book//content[. ftcontains "resume." 
   with wildcards diacritics insensitive]
where count($cont) >0   
return $book

Solution in XPath:

doc("http://bstore1.example.com/full-text.xml")
/books/book[count(.//content ftcontains "resume." 
with wildcards diacritics insensitive)>0]

Expected Result:

<book number="2">
   <metadata>
      ...
   </metadata> 
   <content>
      ...
      <part number="1">
         <chapter>
            <title>Planning then Conducting Usability 
            Tests</title> 
            <p>Take the following steps to plan usability 
            testing. <step number="1">Clarify and 
            articulate the goal of the usability testing.
            </step> <step number="2">Identify tasks which 
            are critical for users to be able to complete 
            successfully.</step> <step number="3">Compile 
            a script of questions or instructions which 
            will prompt the user to attempt those 
            tasks.</step> <step number="4">Identify your 
            users and begin recruiting them.</step> <step 
            number="5">Conduct a pretest on a few users.
            </step> <step number="6">Edit the script based 
            on insights gleaned from the pretest.</step> 
            <step number="7">Resume testing.</step></p>
         </chapter>
      </part>  
      ... 
   </content>
</book>      
   
<book number="3">
   <metadata>
      ...
   </metadata> 
   <content>
      <introduction>
         <p>The papers of John Wesley Usabilityguy span the 
         years 1946-2001, with the bulk of the items 
         concentrated in the period from 1985 to 2001. The 
         papers feature his career as a developer of software 
         applications and usability specialist. The collection 
         consists of correspondence, memoranda, journals, 
         speeches, article drafts, book drafts, notes, charts, 
         graphs, family papers, clippings, printed matter, 
         photographs, résumés and other materials.</p>
      </introduction>
      <part number="1"><container type="box">1-12</container>
         <title>Subject File, <date normalize="1930/1974">
         1930-1974</date></title>
         <introduction>
            <p>Correspondence, telegrams, memoranda, journals, 
            logs, testimony, approved travel orders, invitations, 
            charts, graphs, forms, biographical data, photographs, 
            book drafts, clippings and other printed matter, 
            résumés and miscellaneous material. Organized by 
            name of person or organization, topic, or type of 
            material.</p>
         </introduction>
         ...
      </part>
      ...   
   </content>
</book>

9.2.3 Q3 Query on Word with Upper Case Characters

Find out whether John Wesley Usabilityguy included research on "AIDS" among the charities he supported.

This query finds a word in upper case characters.

  • Operands: "AIDS"

  • Functionality: case-sensitivity (limited to upper case), word query

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: .

  • Return: .

  • Comments: This query does not return the word "aids" with lower case characters which exists in the sample data.

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book[. ftcontains "AIDS" uppercase]   
where count($book) >0  
return $book

Solution in XPath:

doc("http://bstore1.example.com/full-text.xml")
/books/book[count(. ftcontains "AIDS" 
uppercase)>0]

Expected Result:

<book number="3">
   <metadata>
      ...
   </metadata> 
   <content>
      ...   
      <part number="2"><container type="box">3-5</container>
         <title>Writings File, 
         <date normalize="1985/1999">1985-1999</date>
         </title>
         ...
         <component>
            <componentTitle>Charitable Contributions
            </componentTitle> 
            <subComponent>
               <componentTitle>Diseases: AIDS, Hepatitis, 
               Tuberculosis <componentDate normalize=
               "1990/1999">1990-1999</componentDate>
               </componentTitle>
            </subComponent> 
            ...
         </component>
      </part>
   </content>
</book>

9.2.4 Q4 Query on Word with Upper Case and Lower Case Characters

Find out whether John Wesley Usabilityguy included research on "AIDS" among the charities he supported.

This query finds a word with upper or lower case characters.

  • Operands: "AIDS"

  • Functionality: word query, case-insensitivity

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: .

  • Return: .

  • Comments: This query returns the word "aids" with characters in upper or lower case.

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book[. ftcontains "AIDS" case insensitive]   
where count($book) > 0  
return $book

Solution in XPath:

doc("http://bstore1.example.com/full-text.xml")
/books/book[count(. ftcontains "AIDS" case 
insensitive)>0]

Expected Result:

<book number="2">
   <metadata>
      ...
      <subjects xml:lang="en">
         <subject>Usability testing</subject>
         <subject>Web site development</subject>
         <subject>Guides and finding aids</subject>
      </subjects>      
      ...
   </metadata> 
   <content>
      ...   
   </content>   
</book>     
   
<book number="3">
   <metadata>
      ...
   </metadata> 
   <content>
      ...   
      <part number="2"><container type="box">3-5</container>
         <title>Writings File, 
         <date normalize="1985/1999">1985-1999</date>
         </title>
         ...
         <component>
            <componentTitle>Charitable Contributions
            </componentTitle> 
            <subComponent>
               <componentTitle>Diseases: AIDS, Hepatitis, 
               Tuberculosis <componentDate normalize=
               "1990/1999">1990-1999</componentDate>
               </componentTitle>
            </subComponent> 
            ...
         </component>
      </part>
   </content>
</book>

10 Use Case "LOGICAL": Queries with Logical Expressions (Or, And, and Not Queries)

10.1 Description

These use cases include queries containing logical expressions: or, and, the unary not, and not, and mild not.

10.2 Queries and Results

10.2.1 Q1 Or Query

Find all books with the words "web" or "software" in the text.

This query finds any or all of the words.

  • Operands: "web" "software"

  • Functionality: word query, or query

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: ./content

  • Return: .

  • Comment: The or query returns any or all of words queried.

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $cont := $book//content[. ftcontains "web" 
   ftor "software"]
where fn:count($cont)>0
return $book

Solution in XPath:

doc("http://bstore1.example.com/full-text.xml")
/books/book[count(.//content ftcontains 
"web" ftor "software")>0]

Expected Result:

<book number="1">
   <metadata>
      ...
   </metadata> 
   <content>
      <introduction>
         ...
         <p>The usability of a Web site is how well the 
         site supports the user in achieving specified 
         goals. A Web site should facilitate learning, 
         and enable efficient and effective task 
         completion, while propagating few errors. 
         Satisfaction with the site is also important. 
         The user must not only be well-served, but must 
         feel well-served.</p> 
         ...
         <p>This book has been approved by the Web Site 
         Users Association.</p>
      </introduction>
      <part number="1">
         <title>Expert Reviews</title>
         <introduction>
            <p>Expert reviewers identify problems 
            and recommend changes to web sites based 
            on research in human computer interaction 
            and their experience in the field.</p> 
            ...
            <p>Expert review methods should be 
            initiated early in the development process, 
            as soon as paper <b>p</b>rototypes 
            (hand-drawn pictures of Web pages) or
            <b>w</b>ireframes (electronic mockups) are 
            available. They should be conducted using 
            the hardware and software similar to that  
            employed by users.</p>
         </introduction>
         <chapter>
            <title>Heuristic Evaluation</title>
            <p>Expert reviewers critique an interface to 
            determine conformance with recognized 
            usability principles. <footnote>One of the 
            best known lists of heuristics is <citation 
            url="http://www.useit.com/papers/heuristic
            /heuristic_list.html">Ten Usability 
            Heuristics by Jacob Nielson</citation>. Another 
            is <citation url="http://usability.gov
            /guidelines/index.html"> Research-Based Web  
            Design and Usability Guidelines</citation>
            </footnote></p> 
         </chapter>
         <chapter>
            <title>Cognitive Walk-Through</title>
            <p>Expert reviewers evaluate Web site 
            understandability and ease of learning while 
            performing specified tasks. They walk through 
            the site answering questions such as "Would a 
            user know by looking at the screen how to 
            complete the first step of the task?" and "If 
            the user completed the first step, would the 
            user know what to do next?," with the goal of 
            identifying any obstacles to completing the 
            task and assessing whether the user would 
            cognitively be aware that he was successful in 
            completing a step in the process.</p>
         </chapter>
      </part>
      ...
   </content>
</book>
        
<book number="2">
   <metadata>
      ...
   </metadata> 
   <content>     
      <introduction>
         <p>This is a basic handbook for planning and 
         conducting usability tests on Web sites. Usability 
         testing should be used in conjunction with other 
         expert review methods.</p>
         <p>This book has not been approved by the Web Site
         Users Association.</p>
      </introduction>
      <part number="1">
         ...
      </part>
      <part number="2">
         <chapter>
            <title>Conducting Usability Tests</title> 
            ...
            <p>Give the user the script, then assure them 
            that you are testing the Web site, not them. 
            Users are asked to verbalize their thoughts as 
            they complete the tasks. The event is recorded 
            or someone takes notes. It is often preferable 
            to have two testers, <footnote>Usability 
            testing can be done at great expense or on a 
            shoe string, using <testingProcedure>in-house 
            expertise</testingProcedure> or 
            <testingProcedure>contracting with human 
            computer interaction professionals
            </testingProcedure>.</footnote> one to ask the 
            questions, another to take notes. Testers should 
            offer no guidance or comments to the user. Mouse 
            movements, typing, expressions, and the user's 
            words should be recorded.</p>
         </chapter>
         <chapter>
            <title>Evaluating and Implementing Results</title> 
            <p>Compile the results and review collectively. 
            Make changes to the site to alleviate the problems 
            found in Web site components which were propagating 
            the largest number of or the most devastating errors. 
            Begin new iterations of testing and changes, until 
            users are successful in the accomplishing the 
            tasks.</p>
         </chapter>
      </part>    
   </content>
</book>        
    
<book number="3">
   <metadata>
      ...
   </metadata> 
   <content> 
      <introduction>
         <p>The papers of John Wesley Usabilityguy span the 
         years 1946-2001, with the bulk of the items 
         concentrated in the period from 1985 to 2001. The 
         papers feature his career as a developer of software 
         applications and usability specialist. The collection 
         consists of correspondence, memoranda, journals, 
         speeches, article drafts, book drafts, notes, charts, 
         graphs, family papers, clippings, printed matter, 
         photographs, résumés and other materials.</p>
      </introduction>
      <part number="1"><container type="box">1-12</container>
         <title>Subject File, <date normalize="1930/1974">
         1930-1974</date></title>
         ...
         <component><container type="box">1</container>
           <componentTitle>Computers</componentTitle>
           <subComponent>
              <componentTitle>Software, 
              <componentDate normalize="1946/1947">1946-1947
              </componentDate>
              </componentTitle>
           </subComponent>   
           ...
         </component>
         <component>
           <componentTitle>Web User Appreciation Award, 
           <componentDate normalize="1956">1956</componentDate>
           </componentTitle>
         </component>
         ...
      </part>  
   </content>
</book>

10.2.2 Q2 And Query

Find all books with the words "web" "software" in the text.

This query finds all of the words.

  • Operands: "web" "software"

  • Functionality: word queries, and query

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: ./content

  • Return: .

  • Comments: The and query finds all the words.

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $cont := $book//content[. ftcontains "web" 
   ftand "software"]
where count($cont)>0
return $book

Solution in XPath:

doc("http://bstore1.example.com/full-text.xml")
/books/book[count(.//content ftcontains 
"web" ftand "software")>0]

Expected Result:

<book number="1">
   <metadata>
      ...
   </metadata> 
   <content>
      <introduction>
         <author>Elina Rose</author>
         <p>The usability of a Web site is how well the 
         site supports the user in achieving specified 
         goals. A Web site should facilitate learning, 
         and enable efficient and effective task 
         completion, while propagating few errors. 
         Satisfaction with the site is also important. 
         The user must not only be well-served, but must 
         feel well-served.</p> 
         ...
         <p>This book has been approved by the Web Site 
         Users Association.</p>
      </introduction>
      <part number="1">
         <title>Expert Reviews</title>
         <introduction>
             <p>Expert reviewers identify problems 
            and recommend changes to web sites based 
            on research in human computer interaction 
            and their experience in the field.</p> 
            ...
            <p>Expert review methods should be 
            initiated early in the development process, 
            as soon as paper <b>p</b>rototypes 
            (hand-drawn pictures of Web pages) or
            <b>w</b>ireframes (electronic mockups) are 
            available. They should be conducted using 
            the hardware and software similar to that  
            employed by users.</p>
         </introduction>
         <chapter>
            <title>Heuristic Evaluation</title>
            <p>Expert reviewers critique an interface to 
            determine conformance with recognized 
            usability principles. <footnote>One of the 
            best known lists of heuristics is <citation 
            url="http://www.useit.com/papers/heuristic
            /heuristic_list.html">Ten Usability 
            Heuristics by Jacob Nielson</citation>. Another 
            is <citation url="http://usability.gov
            /guidelines/index.html"> Research-Based Web  
            Design and Usability Guidelines</citation>
            </footnote></p> 
         </chapter>
         <chapter>
            <title>Cognitive Walk-Through</title>
            <p>Expert reviewers evaluate Web site 
            understandability and ease of learning while 
            performing specified tasks. They walk through 
            the site answering questions such as "Would a 
            user know by looking at the screen how to 
            complete the first step of the task?" and "If 
            the user completed the first step, would the 
            user know what to do next?," with the goal of 
            identifying any obstacles to completing the 
            task and assessing whether the user would 
            cognitively be aware that he was successful in 
            completing a step in the process.</p>
         </chapter>
      </part>
      ...
   </content>
</book>   
    
<book number="3">
   <metadata>
      ...
   </metadata> 
   <content> 
      <introduction>
         <p>The papers of John Wesley Usabilityguy span the 
         years 1946-2001, with the bulk of the items 
         concentrated in the period from 1985 to 2001. The 
         papers feature his career as a developer of software 
         applications and usability specialist. The collection 
         consists of correspondence, memoranda, journals, 
         speeches, article drafts, book drafts, notes, charts, 
         graphs, family papers, clippings, printed matter, 
         photographs, résumés and other materials.</p>
      </introduction>
      <part number="1"><container type="box">1-12</container>
         <title>Subject File, <date normalize="1930/1974">
         1930-1974</date></title>
         ...
         <component><container type="box">1</container>
           <componentTitle>Computers</componentTitle>
           <subComponent>
              <componentTitle>Software, 
              <componentDate normalize="1946/1947">1946-1947
              </componentDate>
              </componentTitle>
           </subComponent>   
           ...
         </component>
         <component>
           <componentTitle>Web User Appreciation Award, 
           <componentDate normalize="1956">1956</componentDate>
           </componentTitle>
         </component>
         ...
      </part>  
   </content>
</book>

10.2.3 Q3 And Query Ordered

Find all book text containing the words "goal" "obstacles" "task" in this order.

This query finds multiple words in the order queried.

  • Operands: "goal" "obstacles" "task"

  • Functionality: ordered word query

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: ./content

  • Return: .

  • Comments: This query finds multiple words in a specified order. It is more permissive than a phrase query. It is comparable to an ordered distance query where the number of intervening words is zero or more.

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $cont := $book//content[. ftcontains 
   "goal" ftand "obstacles" ftand "task" ordered]
where count($cont)>0
return $book

Solution in XPath:

doc("http://bstore1.example.com/full-text.xml")
/books/book[count(.//content ftcontains 
"goal" ftand "obstacles" ftand "task" ordered)>0]

Expected Result:

<book number="1">
   <metadata>
      ...
   </metadata>                                    
   <content>
   ...
      <part number="1">
         <chapter>
            <p>Expert reviewers evaluate Web site 
            understandability and ease of learning while 
            performing specified tasks. They walk through 
            the site answering questions such as "Would a 
            user know by looking at the screen how to 
            complete the first step of the task?" and "If 
            the user completed the first step, would the 
            user know what to do next?," with the goal of 
            identifying any obstacles to completing the 
            task and assessing whether the user would 
            cognitively be aware that he was successful in 
            completing a step in the process.</p>
         </chapter>
      </part>
      ...
   </content>
</book>

10.2.4 Q4 Unary Not Query

Find all books which do not belong in a collection on "usability testing".

This query finds books which do not contain a phrase in an element and its descendants.

  • Operands: "usability testing"

  • Functionality: phrase query, character wildcard (suffix) (0 or more), unary not query

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: .

  • Return: .

  • Comments: Unlike the and not query below, the unary not query requires only one operand. This query has value for information architects and data managers who will use it for checks such as this one: to find nonconforming data in a document or a collection.

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $not := $book[. ftcontains ftnot "us.* testing"
   with wildcards]
where count($not) > 0
return $book

Solution in XPath:

doc("http://bstore1.example.com/full-text.xml")
/books/book[count(. ftcontains  ftnot "us.* testing" 
with wildcards)>0]

Expected Result: No results returned.

10.2.5 Q5 And Not Query

Find all books with the word "usability" and not the word "plan" in the metadata.

This query finds a word only when another is not found in an element or its descendants.

  • Operands: "usability" "plan"

  • Functionality: word query, and not query

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: ./metadata

  • Return: .

  • Comments: The and not query is also called a but, but not, and without query. Unlike the unary not query above,this query requires two operands. Book 2 which contains the words "usability" and "plan" in the metadata is not returned.

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $up := $book[./metadata ftcontains "usability" 
   ftand ftnot "plan"]
where count($up) > 0
return $book

Solution in XPath:

doc("http://bstore1.example.com/full-text.xml")
/books/book[count(./metadata ftcontains "usability" 
ftand ftnot "plan")>0]

Expected Result:

<book number="1">
   <metadata>                             
      <title shortTitle="Improving Web Site Usability">Improving 
      the Usability of a Web Site Through Expert Reviews 
      and Usability Testing</title>
      ...
   </metadata>
   <content>
   ...   
   </content>   
</book>

<book number="3">
   <metadata>     
      ...                       
      <subjects xml:lang="en">
         ...  
         <subject>Usability Testing</subject>
         ... 
      </subjects>  
      ...
   </metadata>
   <content>
   ...   
   </content>   
</book>


10.2.6 Q6 And Not Query Where Second Operand Is a Subset of the First Operand

Find all books with listings for "résumés", "drafts", or "correspondence", and not "book drafts" in the text.

This query finds books with multiple words and not a phrase containing one of those words.

  • Operands: "résumés" "drafts" "correspondence" "book drafts"

  • Functionality: word queries, or query, phrase query, and not query, functionality requiring presence of diacritics

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: ./content

  • Return: .

  • Comments: This query will not return a result the user wants because that result also includes what the user does not want, "book drafts".

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $cont := $book/content[. ftcontains 
   (("résumés" with diacritics) ftor "drafts" 
   ftor "correspondence") ftand ftnot "book drafts"]
where count($cont)>0
return $book

Solution in XPath:

doc("http://bstore1.example.com/full-text.xml")
/books/book[count(./content ftcontains (("résumés" 
with diacritics) ftor "drafts" ftor "correspondence") 
ftand ftnot "book drafts")>0]

Expected Result: No results returned.

10.2.7 Q7 Mild Not Query Where Second Operand Is a Subset of the First Operand

Find all books with listings for "résumés", "drafts", or "correspondence", and not "book drafts", in the metadata or text.

This query finds books with multiple words and not a phrase which contains one of the words, while not eliminating a result if it contains the phrase as well as one of the words searched.

  • Operands: "résumés" "drafts" "correspondence" "book drafts"

  • Functionality: word queries, or query, phrase query, mild not query, functionality requiring presence of diacritics

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: ./content

  • Return: .

  • Comments: This query will return a result the user wants even though it contains the phrase the user deprecated via the mild not, "book drafts". The user will not lose results which contain what he wants when that book also contains what he does not want. Books containing instances of "book drafts" (a subset of "drafts") are not excluded, merely not considered.

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $cont := $book//content[. ftcontains 
   (("résumés" with diacritics) ftor "drafts" 
   ftor "correspondence") not in "book drafts"]
where count($cont)>0
return $book

Solution in XPath:

doc("http://bstore1.example.com/full-text.xml")
/books/book[count(.//content ftcontains (("résumés" 
with diacritics) ftor "drafts" ftor "correspondence") 
not in "book drafts")>0]

Expected Result:

<book number="3">
   <metadata>
      ...
   </metadata> 
   <content>
      <introduction> 
         <p>The papers of John Wesley Usabilityguy span the 
         years 1946-2001, with the bulk of the items 
         concentrated in the period from 1985 to 2001. The 
         papers feature his career as a developer of software 
         applications and usability specialist. The collection 
         consists of correspondence, memoranda, journals, 
         speeches, article drafts, book drafts, notes, charts, 
         graphs, family papers, clippings, printed matter, 
         photographs, résumés and other materials.</p>
         </introduction>
      ...      
   </content>
</book>

11 Use Case "CARDINALITY": Queries in Same, Any, Every Instance of an Element, and Occurrence Count Query

11.1 Description

These use cases illustrate instance queries and occurrence count queries. They query words within the same, any, and every instance of an element. Another query finds a phrase only if it occurs over a specified number of times in a book.

11.2 Queries and Results

11.2.1 Q1 Query in Same Instance of an Element

Find all books with the phrase "web site" and the word "usability" in the same subject.

This query finds a word and a phrase in the same instance of an element.

  • Operands: "web site" "usability"

  • Functionality: phrase query, word query, and query

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: ./metadata/subjects/subject

  • Return: .

  • Comments: This query finds a word and a phrase in an instance of an element, not allowing one of the operands to be found in an instance of the element and the other operand in a different instance of the element. This query does not find Book 2 which has "usability" and "web site" in different instances of the subject element.

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $subj := $book/metadata/subjects/subject[. ftcontains 
   "web site" ftand "usability"]
where count($subj)>0
return $book

Solution in XPath:

doc("http://bstore1.example.com/full-text.xml")
/books/book[count(./metadata/subjects/subject ftcontains 
"web site" ftand "usability")>0]

Expected Result:

<book number="1">
   <metadata>
      ...  
      <subjects xml:lang="en">
         <subject>Usability testing</subject>
         <subject>Web site development</subject>        
         <subject>Heuristic evaluation</subject>
         <subject>Cognitive walk-through</subject>
         <subject>Web site usability</subject>
      </subjects>
      ...
   </metadata>
   <content>
      ...
   </content>
</book>

11.2.2 Q2 Query in Any Instance of an Element (Existential Quantification)

Find all books with the phrase "web site" and the word "usability" in any subject.

This query finds a word and a phrase in any instance of an element across the siblings of the same element. The word and the phrase may be in different elements.

  • Operands: "web site" "usability"

  • Functionality: phrase query, word query, and query, existential quantification

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: ./metadata/subjects/subject

  • Return: .

  • Comments: This query returns words and phrases in any instance of an element, allowing one of the operands to be found in one sibling and the other operand in a different sibling of the same element name.

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book                        
let $subj := $book/metadata/subjects/subject            
where (some $s1 in $subj satisfies $subj ftcontains "web site")    
   and (some $s2 in $subj satisfies $subj ftcontains "usability")
return $book

Solution in XPath:

doc("http://bstore1.example.com/full-text.xml")
/books/book(some $s1 in ./metadata/subjects/subject satisfies 
./metadata/subjects/subject ftcontains "web site") 
and (some $s2  in ./metadata/subjects/subject satisfies 
./metadata/subjects/subject ftcontains "usability")

Expected Result:

<book number="1">
   <metadata>
      ...  
      <subjects xml:lang="en">
         <subject>Usability testing</subject>
         <subject>Web site development</subject>          
         <subject>Heuristic evaluation</subject>
         <subject>Cognitive walk-through</subject>
         <subject>Web site usability</subject>
      </subjects>
      ...
   </metadata>
   <content>
      ...
   </content>
</book>
   
<book number="2">
   <metadata>
      ...  
      <subjects xml:lang="en">
         <subject>Usability testing</subject>
         <subject>Web site development</subject>
         <subject>Guides and finding aids</subject>
      </subjects>
      ...
   </metadata>
   <content>
      ...
   </content>
</book>

11.2.3 Q3 Query in Every Instance of an Element (Universal Quantification)

Find all books with the words "ersatz" and "publications" in every publisher name.

This query finds two words in every instance of an element.

  • Operands: "ersatz" "publications"

  • Functionality: word query, and query, universal quantification

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: ./metadata/publicationInfo/publisher

  • Return: .

  • Comments: This query does not return a book if at least one of its publishers does not contain the words "ersatz" and "publications". Book 1 is returned because it has an instance of the publisher element which satisfies the full-text conditions (contains both "Ersatz" and "Publications"). Book 2 is not returned because even though it has a publisher that satisfies the full-text conditions, it also has a publisher that does not satisfy it. Book 3 is not returned because it has an instance of the publisher element which does not satisfy the query (contains "Ersatz" but not "Publications").

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
where every $pub in $book//publisher satisfies 
   ($pub ftcontains "ersatz" ftand "publications")
return $book

Solution in XPath:

doc("http://bstore1.example.com/full-text.xml")
/books/book(every $pub in .//publisher 
satisfies ($pub ftcontains "ersatz" ftand "publications"))

Expected Result:

<book number="1">
   <metadata>
      ...
      <publicationInfo>   
         <publisher>Ersatz Publications</publisher>
      </publicationInfo>
      ...
   </metadata>
   <content>
      ...
   </content>
</book>

11.2.4 Q4 Occurrence Count Query

Find all books which repeat the phrase "expert review methods" in the text at least two times.

This query finds a phrase which is repeated a specified number of times.

  • Operands: "expert review methods"

  • Functionality: phrase query, at least functionality

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: ./content

  • Return: .

  • Comments: This query excludes books with only minor (single occurrence) references to "expert review methods".

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $cont := $book//content[. ftcontains 
   "expert review methods" occurs at least 2 times]
where count($cont)>0
return $book

Solution in XPath:

doc("http://bstore1.example.com/full-text.xml")
/books/book[count(.//content ftcontains "expert 
review methods" occurs at least 2 times)>0]

Expected Result:

<book number="1">
   <metadata>
      ...
   </metadata>                                    
   <content>
      ...
      <part number="1">
         <title>Expert Reviews</title>
         <introduction>
            ...
            <p>Two expert review methods are discussed 
            here. They are heuristic evaluation and 
            cognitive walk-through.</p> 
            <p>Expert review methods should be 
            initiated early in the development process, 
            as soon as paper <b>p</b>rototypes 
            (hand-drawn pictures of Web pages) or 
            <b>w</b>ireframes (electronic mockups) are 
            available. They should be conducted using 
            the hardware and software similar to that 
            employed by users.</p>
         </introduction>
         ...
      </part>      
   </content>
</book>

12 Use Case "PROXIMITY": Queries on Proximity Relationships Including Distance, Window, Sentence, and Paragraph

12.1 Description

These use cases illustrate unordered and ordered distance queries which find sequences of words allowing up to a specified number of intervening words. They also include a query to find words within a window, within a sentence, and within a paragraph.

12.2 Queries and Results

12.2.1 Q1 Unordered Distance Query

Find all books with information on "software developers".

This query finds multiple words in any order allowing up to a specified number of intervening words.

  • Operands: "software" "developer"

  • Functionality: word queries, stemming, unordered distance (0 to 3 intervening words)

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: ./content

  • Return: .

  • Comments: This query returns "developer of software", which occurs in the sample data.

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $cont := $book//content[. ftcontains 
   "software" ftand "developer" with stemming 
   distance at most 3 words]
where count($cont)>0
return $book

Solution in XPath:

doc("http://bstore1.example.com/full-text.xml")
/books/book[count(.//content ftcontains "software" 
ftand "developer" with stemming distance at most 3 words)>0]

Expected Result:

<book number="3">
   <metadata>
      ...
   </metadata> 
   <content>
      <introduction> 
         <p>The papers of John Wesley Usabilityguy span the 
         years 1946-2001, with the bulk of the items 
         concentrated in the period from 1985 to 2001. The 
         papers feature his career as a developer of software 
         applications and usability specialist. The collection 
         consists of correspondence, memoranda, journals, 
         speeches, article drafts, book drafts, notes, charts, 
         graphs, family papers, clippings, printed matter, 
         photographs, résumés and other materials.</p>
      </introduction>
      ...      
   </content>
</book>

12.2.2 Q2 Ordered Distance Query

Find all books with information on "efficient task completion".

This query finds multiple words in the order queried allowing up to a specified number of intervening words.

  • Operands: "efficient" "task" "completion"

  • Functionality: word queries, ordered distance (0 to 10 intervening words)

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: ./content

  • Return: .

  • Comments: This query is more permissive than an phrase query on "efficient task completion" which would return no results.

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $cont := $book//content[. ftcontains 
   "efficient" ftand "task" ftand "completion" 
   ordered distance at most 10 words]
where count($cont)>0
return $book

Solution in XPath:

doc("http://bstore1.example.com/full-text.xml")
/books/book[count(.//content ftcontains "efficient" 
ftand "task" ftand "completion" ordered
distance at most 10 words )>0]

Expected Result:

<book number="1">
   <metadata>
      ...
   </metadata> 
   <content>
   <content>
      <introduction>
         ... 
         <p>The usability of a Web site is how well the 
         site supports the user in achieving specified 
         goals. A Web site should facilitate learning, 
         and enable efficient and effective task
         completion, while propagating few errors.
         Satisfaction with the site is also important. 
         The user must not only be well-served, but must 
         feel well-served.</p> 
         ...
      </introduction>
      ...   
   </content>
</book>

12.2.3 Q3 Ordered Window Query

Find all books about "users feeling well-served".

This query finds books with multiple words within an ordered window of up to a specified number of words.

  • Operands: "users" "feeling" "well served" "well-served"

  • Functionality: word queries, ordered window (0 to 15 words)

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: ./content

  • Return: .

  • Comments: This query opens a window on the first found word (which must be the first word queried) and counts a specified number of words from that first word within which it may find the remaining word or words, finding them in the order queried.

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $cont := $book//content[. ftcontains 
   "users" ftand "feeling" ftand ("well served" ftor "well-served")
   with stemming ordered window 15 words]
where count($cont)>0
return $book

Solution in XPath:

doc("http://bstore1.example.com/full-text.xml")
/books/book[count(.//content ftcontains "users" 
ftand "feeling" ftand ("well served" ftor "well-served") with stemming 
ordered window 15 words)>0]

Expected Result:

<book number="1">
   <metadata>
      ...
   </metadata> 
   <content>
      <introduction>
         ... 
         <p>The usability of a Web site is how well the 
         site supports the user in achieving specified 
         goals. A Web site should facilitate learning, 
         and enable efficient and effective task
         completion, while propagating few errors.         
         Satisfaction with the site is also important. 
         The user must not only be well-served, but must
         feel well-served.</p>  
         ...
      </introduction>
      ...   
   </content>
</book>

12.2.4 Q4 Unordered Within a Sentence Query

Find all books which discuss "questions asked during cognitive walk-throughs".

This query finds books with multiple words in any order within a sentence.

  • Operands: "users" "would" "know" "step"

  • Functionality: word queries, stemming, unordered sentence query

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: ./content

  • Return: .

  • Comments: This query expects an implementation-defined tokenized sentence or a sentence element.

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $cont := $book//content[. ftcontains 
   "users" ftand "would" ftand "know" ftand "step" 
   with stemming same sentence]
where count($cont)>0
return $book

Solution in XPath:

doc("http://bstore1.example.com/full-text.xml")
/books/book[count(.//content ftcontains "users" ftand "would" 
ftand "know" ftand "step" with stemming same sentence)>0]

Expected Result:

<book number="1">
   <metadata>
      ...
   </metadata>                                    
   <content>
      ...
      <part number="1">
         <chapter>
            <p>Expert reviewers evaluate Web site 
            understandability and ease of learning while 
            performing specified tasks. They walk through 
            the site answering questions such as "Would a
            user know by looking at the screen how to
            complete the first step of the task?" and "If            
            the user completed the first step, would the 
            user know what to do next?," with the goal of 
            identifying any obstacles to completing the 
            task and assessing whether the user would 
            cognitively be aware that he was successful in 
            completing a step in the process.</p>
         </chapter>
      </part>
      ...
   </content>
</book>

12.2.5 Q5 Unordered Within a Paragraph Query

Find all paragraphs which define what "Web site usability" is.

This query finds books with multiple words and phrases in any order within a paragraph.

  • Operands: "usability" "web site" "efficiency" "satisfaction"

  • Functionality: word queries, phrase query, unordered paragraph query

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: ./content

  • Return: .

  • Comments: This query expects an implementation-defined tokenized paragraph or a paragraph element.

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $cont := $book//content[. ftcontains 
   "usability" ftand "web site" ftand "efficiency" 
   ftand "satisfaction" same paragraph]
where count($cont)>0
return $book

Solution in XPath:

doc("http://bstore1.example.com/full-text.xml")
/books/book[count(.//content ftcontains "usability" 
ftand "web site" ftand "efficiency" ftand "satisfaction" 
same paragraph)>0]

Expected Result:

<book number="1">
   <metadata>
      ...
   </metadata> 
   <content>
   <content>
      <introduction>
         ... 
         <p>The usability of a Web site is how well the 
         site supports the user in achieving specified 
         goals. A Web site should facilitate learning, 
         and enable efficient and effective task
         completion, while propagating few errors.         
         Satisfaction with the site is also important.. 
         The user must not only be well-served, but must
         feel well-served.</p>  
         ...
      </introduction>
      ...   
   </content>                                     
</book>

13 Use Case "AXES": Queries Using Relative XPath Axes

13.1 Description

These use cases illustrate queries traversing relative XPath axes.

13.2 Queries and Results

13.2.1 Q1 Query on Element and Its Children

Find all books with paragraphs containing the phrase "computer workstation" and footnotes within those paragraphs containing the word "comfortable".

This query finds a phrase in an element, then finds a word in a child element.

  • Operands: "computer workstation" "comfortable"

  • Functionality: phrase query, word query

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: .//p, .//p/footnote

  • Return: ./metadata/title, .//p

  • Comments: This query combines phrase and word search in different elements which have a parent-child relationship.

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $para := $book//p[. ftcontains "computer 
   workstation"]
let $fn := $para/footnote[. ftcontains "comfortable"]
where count($fn)>0
return $book/metadata/title, $para

Solution in XPath:

doc("http://bstore1.example.com/full-text.xml")
/books/book[count(.//p ftcontains "computer workstation" 
and .//p/footnote ftcontains "comfortable")>0]/(metadata/title 
| .//p)

Expected Result:

<title shortTitle="Usability Basics">Usability 
Basics: How to Plan for and Conduct Usability Tests 
on Web Site Thereby Improving the Usability of Your 
Web Site</title>      
<p>Users can be tested at any computer 
workstation<footnote>They may be more 
comfortable at their own workstation than in 
 a lab.</footnote> or in a lab.</p>

13.2.2 Q2 Query on Element Returning Its First Two Children

Find the first two steps in chapters on "conducting usability tests."

This query finds words in an element, then returns its first two children elements.

  • Operands: "usability", "test"

  • Functionality: word queries, stemming

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: ./content/part/chapter/p

  • Return: ./metadata/title ./content/part/chapter/p/step[1], ./content/part/chapter/p/step[2]

  • Comments: This query finds words in a p element and uses XPath to return the first two children of the element.

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $para := $book[.//chapter/p ftcontains "usability" 
   ftand "test" with stemming]
where count($para) > 0   
return $book/metadata/title, $para/step[1], $para/step[2]

Solution in XPath:

doc("http://bstore1.example.com/full-text.xml")
/books/book//chapter/p[count(. ftcontains "usability" 
ftand "test" with stemming)>0]/(metadata/book 
| .//chapter/p/step[1] | .//chapter/p/step[2])

Expected Result:

<title shortTitle="Usability Basics">Usability 
Basics: How to Plan for and Conduct Usability Tests 
on Web Site Thereby Improving the Usability of Your 
Web Site</title>   
<step number="1">Clarify and articulate 
the goal of the usability testing.</step> 
<step number="2">Identify tasks which 
are critical for users to be able to complete 
successfully.</step>

13.2.3 Q3 Query on Element and Its Ancestors

Are there any "flow diagrams" of "human computer interaction" scenarios in John Wesley Usabilityguy's papers?

This query finds a phrase in an element, then finds another phrase in an ancestor element.

  • Operands: "flow diagrams" "human computer interaction"

  • Functionality: phrase queries, character wildcard (suffix) (0 or one)

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book[@number="3"]

  • Query context: ./content/part/component/subcomponent/componentTitle, ./content/part/component/subcomponent/subsubcomponent/componentTitle

  • Return: ./metadata/title, ./content

  • Comments: This query looks for a phrase in an element and a different phrase in its ancestor elements.

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book[@number="3"]
let $comp := $book[./content/part/component/
   (subcomponent | subcomponent/subsubcomponent)/
   componentTitle ftcontains "flow diagram.?" 
   with wildcards]
let $parentComp := $book[ancestor::books//../$comp 
  ftcontains "human computer interaction"]
where count($comp) > 0   
return $book/metadata/title, $book/content

Solution in XPath:

doc("http://bstore1.example.com/full-text.xml")
/books/book[@number="3" and count((./content/part/
component(subcomponent | subcomponent/subsubcomponent) 
ftcontains "flow diagram.?" with wildcards 
and ancestor::books//(subcomponent | subcomponent/
subsubcomponent) ftcontains "human computer 
interaction"))>0]/(metadata/title | ./content)

Expected Result:

<title shortTitle="Usabilityguy Manuscript 
Guide">John Wesley Usabilityguy: A Register of His 
Papers</title>
<content>
   ...
   <part number="1"><container type="box">1-12</container>
      <title>Subject File, <date normalize="1930/1974">
      1930-1974</date></title>
        ...
        <subComponent>
           <componentTitle>Human Computer Interaction 
           research, <componentDate normalize="1945/1952">
           1945-1952</componentDate>
           </componentTitle>
           <subsubComponent>
              <componentTitle>Flow diagram, 
              <componentDate normalize="1950">1950
              </componentDate>
              </componentTitle>
           </subsubComponent>
           ...
         </subComponent>
      </component>
   </part>
</content>

13.2.4 Q4 Query on Element and Its Right Siblings

Find all book chapters with paragraphs on "usability testing" followed by paragraphs on "information architecture".

This query finds a phrase in an element, then finds another phrase in one of its right siblings.

  • Operands: "usability testing" "information architecture"

  • Functionality: phrase queries

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: ./content/part/chapter/p

  • Return: ./metadata/title, .//content

  • Comments: This query returns book chapters if they contain paragraphs following each other as specified in the query.

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $chapters := $book//chapter[./p ftcontains "usability 
   testing" and ./p/following-sibling::p ftcontains 
   "information architecture"]
where count($chapters)>0
return ($book/metadata/title, $chapters)

Solution in XPath: None

Expected Result:

<book number="1">
        <metadata>
      ...
   </metadata> 
   <content>
      ...      
      <part number="2">
         <chapter>
            <p>Once the problems identified by expert 
            reviews have been corrected, it is time to 
            conduct some tests of the site with your unique 
            audience or audiences by conducting usability
            testing.</p>
            <p>Users are asked to complete tasks which 
            measure the success of the information 
            architecture and navigational elements of the 
            site.</p>
         </chapter>
      </part> 
   </content>
</book>

14 Use Case "IGNORE": Queries Ignoring Descendant Element Content

14.1 Description

These phrase and proximity queries cross element boundaries ignoring the content of descendant elements. One query ignores the content of a complete sub-tree. Other queries ignore only the content of specified descendant elements. The last query performs a level-by-level ignore. It ignores the content of descendant elements when querying the content of the parent element. Its descendant elements are promoted and then their content is queried.

14.2 Queries and Results

14.2.1 Q1 Distance Query Ignoring Content of All Descendant Elements

Find advice on whether the observer should "correct" or provide "guidance" to the user during usability "testing".

This query ignores the content of all descendant elements.

  • Operands: "testing" "correct" "guidance"

  • Functionality: phrase query, word queries, or query, ordered distance query (0 to 60 intervening words), ignore content of descendant elements

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: .//p

  • Return: .

  • Comments: This query ignores the content of all the descendant elements of the p element, so it ignores the footnote and testingProcedure elements. If the descendant elements were not ignored, the words searched would be too distant from each other to have been returned.

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $p := $book//p [. ftcontains "testing" 
   ftand ("guidance" ftor "correct") distance at 
   most 60 words without content *] 
where count($p) > 0
return $book

Solution in XPath:

doc("http://bstore1.example.com/full-text.xml")
/books//p[count(. ftcontains "testing" 
ftand ("guidance" ftor "correct") distance at 
most 60 words without content *)>0]

Expected Result:

<book number="2">
   <metadata>
      ...
   </metadata> 
   <content>
      ...                                       
      <part number="2">
         <chapter>
            ...
            <p>Give the user the script, then assure them 
            that you are testing the Web site, not them. 
            Users are asked to verbalize their thoughts as 
            they complete the tasks. The event is recorded 
            or someone takes notes. It is often preferable 
            to have two testers, <footnote>Usability 
            testing can be done at great expense or on a 
            shoe string, using <testingProcedure>in-house 
            expertise</testingProcedure> or 
            <testingProcedure>contracting with human 
            computer interaction professionals
            </testingProcedure>.</footnote> one to ask the 
            questions, another to take notes. Testers should 
            offer no guidance or comments to the user. Mouse 
            movements, typing, expressions, and the user's 
            words should be recorded.</p>
         </chapter>
         ...
      </part>
   </content>
</book>

14.2.2 Q2 Phrase Query Ignoring Content of Descendant Element Specified by XPath Expression

Find all book chapters containing "users can be tested at any computer workstation or in a lab" ignoring footnotes.

This query finds book chapters containing the phrase "users can be tested at any computer workstation or in a lab" ignoring the content of a descendant element explicitly specified by an XPath expression.

  • Operands: "users can be tested at any computer workstation or in a lab"

  • Functionality: phrase query, ignore content of footnote element

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: ./content/part/chapter

  • Return: ./metadata/title, ./content/part/chapter

  • Comments: This query ignores the content of a descendant element, the footnote element.

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $chap := $book//chapter[. ftcontains 
   "users can be tested at any computer workstation 
   or in a lab" without content .//footnote] 
where count($chap) > 0
return $book/metadata/title, $chap

Solution in XPath:

doc("http://bstore1.example.com/full-text.xml")
/books/book[count(.//chapter ftcontains "users can be 
tested at any computer workstation or in a lab" 
without content .//footnote)>0]/(metadata/title | .//chapter)

Expected Result:

<title shortTitle="Usability Basics">Usability 
Basics: How to Plan for and Conduct Usability Tests 
on Web Site Thereby Improving the Usability of Your 
Web Site</title>
<chapter>
   ...
   <p>Users can be tested at any computer  
   workstation <footnote>They may be more 
   comfortable at their own workstation than in 
   a lab.</footnote>or in a lab.</p> 
   ...
</chapter>

14.2.3 Q3 Phrase Query Ignoring Content of Descendant Element Specified by Full-Text Query

Find all book chapters containing the phrase "at any computer workstation or in a lab" ignoring footnotes on workstations.

This query ignores the content of a descendant element specified by a full-text query.

  • Operands: "at any computer workstation or in a lab", "workstations"

  • Functionality: phrase query, character wildcard (suffix) (1), ignore content of a descendant element found by a full-text query

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: ./content/part/chapter

  • Return: ./metadata/title, ./content/part/chapter

  • Comments: This query ignores the content of a descendant element identified dynamically by a full-text query.

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $chap := $book//chapter[. ftcontains 
   "at any computer workstation or in a lab" 
   without content (.//footnote[. ftcontains 
   "workstation." with wildcards])]
where count($chap) > 0
return $book/metadata/title, $chap

Solution in XPath:

doc("http://bstore1.example.com/full-text.xml")
/books/book[count(.//chapter ftcontains "at any computer 
workstation or in a lab" without content 
.//footnote[. ftcontains "workstation." with wildcards])>0]
/metadata/title | .//chapter

Expected Result:

<title shortTitle="Usability Basics">Usability 
Basics: How to Plan for and Conduct Usability Tests 
on Web Site Thereby Improving the Usability of Your Web 
Site</title>
<chapter>
   ...
   <p>Users can be tested at any computer
   workstation<footnote>They may be more
   comfortable at their own workstation than in 
   a lab.</footnote>or in a lab.</p>   
   ...
</chapter>

14.2.4 Q4 Distance Query Ignoring Content of Descendant Elements Level by Level

Find all books with the word "workstation" near the word "lab".

This query performs a level-by-level ignore. It ignores the content of descendant elements when querying the content of the parent element. Its descendant elements are promoted and then their content is queried. It differs from the ignore queries above because it queries the content of parent elements skipping over the descendant elements, then instead of stopping there it queries the content of descendent elements in isolation.

  • Operands: "workstation" "lab"

  • Functionality: word queries, unordered distance (0 to 6 intervening words), level by level ignore (ignore the content of descendant element when searching the parent element and promote the descendant element and query it in isolation)

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: ./content/part/chapter/p, /content/part/chapter/p/footnote

  • Return: ./metadata/title, $where,

  • Comments: This query ignores the content of the descendant element footnote when querying its parent element p returning "workstation" and "lab" from "Users can be tested at any computer workstation or in a lab". Then the descendant element footnote is promoted and queried separately returning "workstation" and "lab" from "They may be more comfortable at their own workstation than in a lab". This query is written using the standard ignore syntax ORing together parent and descendant elements to be queried separately.

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $where := ($book//chapter/p | $book//chapter/p/footnote) 
   [. ftcontains "workstation" ftand "lab" 
   distance at most 6 words without content ./footnote]
where fn:count($where) > 0
return $b/metadata/title, $where

Solution in XPath:

doc("http://bstore1.example.com/full-text.xml")
/books/book/chapter[count((./p | ./p/footnote) 
ftcontains "workstation" ftand "lab" distance at most 6 words 
without content ./footnote)>0]/(metadata/title | ./p 
| ./p/footnote)

Expected Result:

<title shortTitle="Usability Basics">Usability 
   Basics: How to Plan for and Conduct Usability Tests 
   on Web Site Thereby Improving the Usability of Your 
   Web Site</title>
<p>Users can be tested at any computer 
   workstation <footnote>They may be more 
   comfortable at their own workstation than in 
   a lab.</footnote> or in a lab.</p>
<footnote>They may be more comfortable at their own 
   workstation than in a lab.</footnote>

15 Use Case "FULL-TEXT-COMPOSABILITY": Queries Illustrating Composability of Full-Text with Itself

15.1 Description

The use cases illustrate a multi-lingual query and queries which use multiple full-text functionalities in conjunction with other XQuery and XPath functionalities.

15.2 Queries and Results

15.2.1 Q1 Query on Words and Phrases in Two Languages

Find all books with the subject "网站可用性", with an introduction written by "Elina Rose", which mention the name of the usability expert "Millicent Marigold".

This query finds words and a phrase in more than one language.

  • Operands: "网站可用性" "Elina" "Rose" "Millicent" "Marigold"

  • Functionality: phrase query, word queries, and query, unordered distance (0 to 3 intervening words), capacity to enter, query, and return multiple languages

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: ./metadata/subjects/subject, ./content/introduction/author, ./content

  • Return: ./@number, ./metadata/title, ./metadata/subjects/subject, ./content/introduction/author, ./content

  • Comments: This query accepts multiple languages as input and returns multiple languages as output.

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
where $book//subject[. ftcontains "网站可用性" language "zh"]
   and $book/content/introduction/author[. ftcontains 
   "Elina" ftand "Rose" distance at most 3 words]
   and $book//content[. ftcontains "Millicent" ftand "Marigold" 
   distance at most 3 words]
return <book number="{$book/@number}"> 
          {$book/metadata/title, $book//subject, 
          $book/content/introduction, $book//content} 
       </book>

Solution in XPath: None

Expected Result:

<book number="1">
   <title shortTitle="Improving Web Site Usability">Improving 
   the Usability of a Web Site Through Expert Reviews 
   and Usability Testing</title>
   <subject>网站可用性</subject>
   <content>
      <introduction>
         <author>Elina Rose</author>
         ...   
         <p>The most successful projects employ multiple methods 
         in multiple iterations. As Millicent Marigold remarked 
         during a recent conference, "Don't stop. Iterate, iterate, 
         then iterate again."</p>
         ...
      </introduction>   
      ...      
   </content>
</book>

15.2.2 Q2 Phrase and Distance Query in an Instance of an Element with Stemming

Find all paragraphs in books which discuss the role of "task performance" in "expert review methods".

This query finds multiple words close to each other and a phrase in one instance of an element.

  • Operands: "task" "performance" "expert review"

  • Functionality: word queries, stemming, phrase query, unordered distance (0 to 3 intervening words between "task" and "performance")

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: ./content//p

  • Return: ./metadata/title, ./content//p

  • Comments: This query combines functionalities introduced in previous sections.

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $para := $book/content//p[. ftcontains 
   ("task" ftand "performance" with stemming distance 
   at most 3 words) ftand "expert review" with stemming]
where count($para) > 0
return $book/metadata/title, $book//content

Solution in XPath:

doc("http://bstore1.example.com/full-text.xml")
/books/book[count(.//content/p ftcontains ("task" 
ftand "performance" with stemming distance 
at most 3 words) ftand "expert review" with stemming)>0]

Expected Result:

<title shortTitle="Improving Web Site Usability">Improving 
   the Usability of a Web Site Through Expert Reviews and 
   Usability Testing</title>
<content>
   ...   
   <part number="1">
      <title>Expert Reviews</title>
      ...
      <chapter>
         <title>Cognitive Walk-Through</title>
         <p>Expert reviewers evaluate Web site 
         understandability and ease of learning while 
         performing specified tasks. They walk through 
         the site answering questions such as "Would a 
         user know by looking at the screen how to 
         complete the first step of the task?" and "If 
         the user completed the first step, would the 
         user know what to do next?," with the goal of 
         identifying any obstacles to completing the 
         task and assessing whether the user would 
         cognitively be aware that he was successful in 
         completing a step in the process.</p>
      </chapter>
   </part>
   ...   
</content>

15.2.3 Q3 Nested Distance Query with Wildcards, Stemming, and Thesaurus Support

Find all books on "usability testing" which "quote" "Millicent Marigold" on the value of multiple "iterations".

This query finds multiple words in three nested levels of distance queries. It uses wildcards, stemming, and thesaurus support.

  • Operands: "usability testing" "quote" "millicent" "marigold" "iterations"

  • Functionality: phrase query, character wildcard (suffix) (0-5), word queries, thesaurus support, stemming, ordered distance (0 to 3 intervening words between "millicent" and "marigold"), unordered distance (0 to 3 intervening words between ("millicent ... marigold" and (one of the following from stemming: "quote", "quoted", "quotes", "quotation", "quotations" or one of the following from thesaurus support: "said", "says", "stated", "states", "statement", "spoke", "speaks", "replied', "replies", "reply", "remarks", "remarked", "responded", "response", "reports ", "reported", "quotes", "quoted", "according", "commented", "discussed", "expressed", "told"), unordered distance (0 to 50 intervening words between ("millicent ... marigold" ... ("quote" or any of its wildcard- or thesaurus-derived substitutes) and ("usability testing" and "iterations")).

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: ./content

  • Return: .

  • Comments: This query combines functionalities introduced in previous sections.

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $quote := $book//content[. ftcontains (("millicent" 
   ftand "marigold" ordered distance at most 3 words)
   ftand "quote.{0-5}" with wildcards with thesaurus at  
   "http://bstore1.example.com/UsabilityThesaurus.xml"
   relationship "synonyms" distance at most 3 words) 
   ftand "usability testing" ftand "iterations" with stemming 
   distance at most 50 words]
where count($quote) > 0
return $book

Solution in XPath:

doc("http://bstore1.example.com/full-text.xml")
/books/book[count(.//content ftcontains (("millicent" 
ftand "marigold" ordered distance at most 3 words)
ftand "quote.{0-5}" with wildcards with thesaurus at 
"http://bstore1.example.com/UsabilityThesaurus.xml"
relationship "synonyms" distance at most 3 words) 
ftand "usability testing" ftand "iterations" with stemming 
distance at most 50 words)>0]

Expected Result:

<book number="1">
   <metadata>
      ...
   </metadata> 
   <content>
      <introduction>
         ...   
         <p>Expert reviews and usability testing are 
         methods of identifying problems in layout, 
         terminology, and navigation before they frustrate 
         users and drive them away from your site.</p>      
         <p>The most successful projects employ multiple 
         methods in multiple iterations. As Millicent
         Marigold remarked during a recent conference, 
         "Don't stop. Iterate, iterate, then iterate          
         again."</p>
      </introduction>
   </content>
</book>

15.2.4 Q4 Window Query with Wildcards and Stemming Ignoring Content of a Descendant Element

Find advice on whether an observer in a "usability test" should "correct" or provide "guidance" to the user in a book not authored by Montana Marigold.

This query uses synonyms supplied by the user, uses the unary not, nests a Boolean query and a phrase query within a window query, and ignores the tags and content of a descendant element.

  • Operands: "usability testing" "correct" "comment" "guidance" "help" "assistance" "montana" "marigold"

  • Functionality: phrase query, word queries, character wildcard (suffix) (0 or more), synonyms for "correct" and "guidance" provided by the user ("comment" or "assistance" or "help"), stemming, or query ("correct" or "comment" or "guidance" or "assistance" or "help"), and query ("montana" and "marigold"), unary not query (not "montana" and "marigold"), unordered window (0 to 70 words within a window of "usability testing" and ("correct" or "comment" or "guidance" or "assistance" or "help"). Ignores content of descendant elements.

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: ./metadata/author, ./content

  • Return: ./@number, ./metadata/title, ./content

  • Comments: This query combines functionalities introduced in previous sections.

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $au := $book/metadata/author[. ftcontains ftnot ("montana" 
  ftand "marigold")]   
let $co := $book//content[. ftcontains (("correct" 
   ftor ("comment" with stemming) ftor "guidance" ftor "assistance" 
   ftor "help") ftand "usability test.*" with wildcards) 
   window 70 words without content .//footnote]
where count($au) > 0 and  count($co) > 0 
return <book number="{$book/@number}"> 
          {$book/metadata/title,
          $book//content}
       </book>

Solution in XPath: None

Expected Result:

<book number="2">
   <title shortTitle="Usability Basics">Usability 
   Basics: How to Plan for and Conduct Usability Tests 
   on Web Site Thereby Improving the Usability of Your 
   Web Site</title>
   <content>
      ...                                       
      <part number="2">
         <chapter>
            <title>Conducting Usability Tests</title> 
            <p>Users can be tested at any computer 
            workstation <footnote>They may be more 
            comfortable at their own workstation than in 
            a lab.</footnote> or in a lab.</p>
            <p>Give the user the script, then assure them 
            that you are testing the Web site, not them. 
            Users are asked to verbalize their thoughts as 
            they complete the tasks. The event is recorded 
            or someone takes notes. It is often preferable 
            to have two testers, <footnote>Usability 
            testing can be done at great expense or on a 
            shoe string, using <testingProcedure>in-house 
            expertise</testingProcedure> or 
            <testingProcedure>contracting with human 
            computer interaction professionals
            </testingProcedure>.</footnote> one to ask the 
            questions, another to take notes. Testers should 
            offer no guidance or comments to the user. Mouse 
            movements, typing, expressions, and the user's 
            words should be recorded.</p>
         </chapter>
         ...
      </part>
   </content>
</book>

15.2.5 Q5 Query on Different Elements in Different Sub-Trees with Conditional Return

For each book with a title containing the word "usability", a book introduction containing the word "satisfaction", and a part introduction containing the phrase "identify problems", return the book title and the authors if it has authors. Return the book title and publisher, if it has no authors. Always return the content surrounding the found words.

This query finds words and a phrase in different elements in different sub-trees. It also contains a conditional return.

  • Operands: "usability" "satisfaction" "identify problems"

  • Functionality: word queries, phrase query, conditional query

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: ./metadata/title, ./content/introduction, ./content/part/introduction

  • Return: ./@number, ./metadata/title, ./metadata/author, ./metadata/publicationInfo/publisher, ./content/introduction, ./content/part/introduction

  • Comments: This query combines functionalities introduced in previous sections.

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $title := $book/metadata/title[. ftcontains 
   "usability"]
let $in := $book/content/introduction[. ftcontains 
   "satisfaction"]
let $pin := $book/content/part/introduction[. ftcontains 
   "identify problems"]
where count($title)>0 and count($in)>0 
   and count($pin)>0
return <book number="{$book/@number}"> 
          {$title} 
          if (count($book/metadata/author) > 0)
          then {$book/metadata/author, $in, $pin}
          else {$book/metadata/publicationInfo/publisher, $in, $pin}
       </book>

Solution in XPath: None

Expected Result:

<book number="1">
   <title shortTitle="Improving Web Site Usability">Improving 
   the Usability of a Web Site Through Expert Reviews 
   and Usability Testing</title>     
   <author>Millicent Marigold</author>  
   <author>Montana Marigold</author>     
   <introduction>
      ...
      <p>The usability of a Web site is how well the 
      site supports the user in achieving specified 
      goals. A Web site should facilitate learning, 
      and enable efficient and effective task 
      completion, while propagating few 
      errors. Satisfaction with the site is also important. 
      The user must not only be well-served, but must 
      feel well-served.</p>
      ...
  </introduction>
  <introduction>
      <p>Expert reviewers identify problems and recommend changes 
      to web sites based on research in human computer interaction 
      and their experience in the field.</p>
      ...
  </introduction> 
</book>

16 Use Case "XQUERY-XPATH-COMPOSABILITY": Queries Illustrating Composability of Full-Text with Other XQuery and XPath Functionalities

16.1 Description

These queries combine full-text queries with other XQuery and XPath functionalities.

16.2 Queries and Results

16.2.1 Q1 Full-Text Query Constructing New Element

For books with "usability" in the title create a flat list of all title-author pairs, with each pair enclosed in a newly constructed element.

This query finds a word in an element and returns the element and another wrapped in a new element.

  • Operands: "usability"

  • Functionality: word query, construction of new element

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: ./metadata/title

  • Return: result (constructed element), ./metadata/title, ./metadata/author

  • Comments: This query finds the word "usability" in the title of a book and building title-author pairs for those books returning them wrapped in a newly constructed result element.

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $var := $book[./metadata/title ftcontains "usability"]
where count ($var) > 0   
return <result> 
          {$book/metadata/title, $book/metadata/author} 
       </result>

Solution in XPath: None

Expected Result:

<result>
   <title shortTitle="Improving Web Site Usability">Improving 
   the Usability of a Web Site Through Expert Reviews 
   and Usability Testing</title>
   <author>Millicent Marigold</author>
   <author>Montana Marigold</author>
</result>
   
<result>
   <title shortTitle="Usability Basics">Usability 
   Basics: How to Plan for and Conduct Usability Tests 
   on Web Site Thereby Improving the Usability of Your 
   Web Site</title>
</result>

16.2.2 Q2 Full-Text Query Returning Count of Descendant Element Occurrences

Find all books with a chapter title on "usability tests". Return book title, chapter title, and the number of steps in chapters.

This query finds words then returns among other elements a constructed element reporting the number of occurrences of a descendant element.

  • Operands: "usability" "test"

  • Functionality: word queries, and query, stemming, count(), construction of new element

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: ./content/part/chapter/title, ./content/part/chapter/p/step

  • Return: ./@number, ./metadata/title, ./content/part/chapter/title, number-of-steps (constructed element)

  • Comments: This query finds the word "usability" and stemmed forms of the word "test" in the titles of book chapters. It returns chapter titles along with an occurrence count of descendant step elements. The query returns a number of steps equal to 0 if the chapter is on usability testing but does not specify any steps (e.g., there are not descendant step elements).

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $ct := $book/content/part/chapter/title[. ftcontains 
   "usability" ftand ("test" with stemming)]
where count($ct)>0
return <book number="{$book/@number}"> 
          {for $title in $ct
          return $title} 
             <number-of-steps> 
                {count($title/..//step)}
             </number-of-steps>
       </book>

Solution in XPath: None

Expected Result:

<book number="1">
   <title shortTitle="Improving Web Site Usability">Improving 
   the Usability of a Web Site Through Expert Reviews and 
   Usability Testing</title>
   <title>Usability Testing</title>
   <number-of-steps>0</number-of-steps>
 </book>

<book number="2">
   <title shortTitle="Usability Basics">Usability 
   Basics: How to Plan for and Conduct Usability Tests 
   on Web Site Thereby Improving the Usability of Your 
   Web Site</title>
   <title>Planning then Conducting Usability
   Tests</title>
   <number-of-steps>7</number-of-steps>
   <title>Conducting Usability Tests</title>
   <number-of-steps>0</number-of-steps>
</book>

16.2.3 Q3 Full-Text Query with Conditional Return

For each book with "usability" in the book title, return the book title and a second element. Return the book title and a third element if the second element does not exist.

This query finds a word and contains a conditional return.

  • Operands: "usability"

  • Functionality: word query, conditional expression

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: ./metadata/title

  • Return: ./@number, ./metadata/title, ./metadata/author, ./metadata/publicationInfo/publisher

  • Comments: This query finds the word "usability" in the title of a book, then returns title-author pairs for those books when there are author elements. If there are no author elements, it returns publisher elements.

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book[./metadata/title ftcontains 
   "usability"]
return <book number="{$book/@number}">
          {$book/metadata/title,
             if (count($book/metadata//author) > 0) 
             then $book/metadata//author 
             else $book/metadata//publisher}
       </book>

Solution in XPath: None

Expected Result:

<book number="1">
   <title shortTitle="Improving Web Site Usability">Improving 
   the Usability of a Web Site Through Expert Reviews 
   and Usability Testing</title>
   <author>Millicent Marigold</author>
   <author>Montana Marigold</author>
</book>

<book number="2">
   <title shortTitle="Usability Basics">Usability 
   Basics: How to Plan for and Conduct Usability Tests 
   on Web Site Thereby Improving the Usability of Your 
   Web Site</title>
   <publisher>Ersatz Publications</publisher>
   <publisher>Electronic BookWorks</publisher>
</book>

16.2.4 Q4 Full-Text Query with Numeric Value Comparison

For each book with "usability" in the book title, return its book title and the round number of its suggested price if the price exceeds $25.

This query finds a word and contains a conditional return based on a function on a numeric value.

  • Operands: "usability"

  • Functionality: word query, round(), numeric value comparison, conditional expression

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: ./metadata/title, ./metadata/price

  • Return: ./@number, ./metadata/title, ./metadata/price

  • Comments: This query finds the word "usability" in the title of a book, then returns the round number of its price if the price exceeds a specified value.

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book/books/book[./metadata/title ftcontains 
    "usability"]
return <book number="{$book/@number}">
           {$book/metadata/title,  
             if ($book/metadata/price > 25)
             then <price>{concat("$", round($book/metadata/price))}</price>
             else ()
           }   
       </book>

Solution in XPath: None

Expected Result:

<book number="1">
   <title shortTitle="Improving Web Site Usability">Improving 
   the Usability of a Web Site Through Expert Reviews 
   and Usability Testing</title>
   <price>$26</price>
</book>

<book number="2">
   <title shortTitle="Usability Basics">Usability 
   Basics: How to Plan for and Conduct Usability Tests 
   on Web Site Thereby Improving the Usability of Your 
   Web Site</title>
   <price>$174</price>
</book>

16.2.5 Q5 Full-Text Query with Character String Query

Find all introductions in books, published in "Washington, D.C.", which include listings for "résumés", "drafts", and "correspondence".

This query finds words and a character string.

  • Operands: "résumés" "drafts" "correspondence" character string "Washington, D.C."

  • Functionality: word query, functionality requiring presence of characters with diacritics, and query, character string query

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: ./content/introduction, ./metadata/publicationInfo/place

  • Return: ./@number, ./metadata/title, ./content//introduction

  • Comments: This query performs a full-text query when it needs to find word variants in full text and performs a character string query when word variants are not possible.

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book[.//publicationInfo/place/text() 
   = "Washington, D.C."]
let $intro := $book/content/introduction[. ftcontains 
   ("résumés" with diacritics) ftand "drafts" ftand "correspondence"]
where count($intro)>0
return <book number="{$book/@number}"> 
           {$book/metadata/title, $intro}
        </book>

Solution in XPath: None

Expected Result:

<book number="3">
   <title shortTitle="Usabilityguy Manuscript 
   Guide">John Wesley Usabilityguy: A Register of 
   His Papers</title> 
   <introduction>
      <p>The papers of John Wesley Usabilityguy span the 
      years 1946-1999, with the bulk of the items
      concentrated in the period from 1985 to 1999. The 
      papers feature his career as a developer of software 
      applications and usability specialist. The collection 
      consists of correspondence, memoranda, journals, 
      speeches, article drafts, book drafts, notes, charts, 
      graphs, family papers, clippings, printed matter, 
      photographs, résumés and other materials.</p>
   </introduction>
</book>

16.2.6 Q6 Full-Text Query with Conditional Return of Boolean Values

For each book on "usability" return the book title and a new has-publishers element with value true if the book has more than 1 publisher. Return the title and a new has-publishers element with value false if the book does not have more than one publisher.

This query finds a word, then returns Boolean values based on the number of occurrences of an element.

  • Operands: "usability"

  • Functionality: word query, construction of new Boolean values, construction of new element, count, >, conditional expression

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: ./metadata/title

  • Return: ./@number, ./metadata/title, has-publishers (constructed element)

  • Comments: This query finds "usability" in the title of a book, then returns the title and Boolean values showing whether the book has more than one publisher or not.

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book[./metadata/title ftcontains 
   "usability"]
return <book number="{$book/@number}">
          {$book/metadata/title} 
          <has-publishers> 
             {if (count($book//publisher) > 1) 
             then "true" else "false"}
          </has-publishers>
       </book>

Solution in XPath: None

Expected Result:

<book number="1">
   <title>Improving the Usability of a Web Site Through 
   Expert Reviews and Usability Testing</title> 
   <has-publishers>false</has-publishers>
</book>

<book number="2">
   <title shortTitle="Improving Web Site Usability">Usability 
   Basics: How to Plan for and Conduct Usability Tests 
   on Web Site Thereby Improving the Usability of Your 
   Web Site</title>
   <has-publishers>true</has-publishers>
</book>

16.2.7 Q7 Full-Text Query with Date Comparison and Element Occurrence Count

Find all books about conducting "usability tests" which have more than one author and are published after "2000".

This query finds a phrase, counts the number of occurrences of an element, runs a greater than comparison on dates, and combines the results.

  • Operands: "usability testing", "2000"

  • Functionality: phrase query, character wildcard (suffix) (0 or more), count, >

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: ./metadata/subjects/subject, ./metadata/author, ./metadata/publicationInfo/dateIssued|dateRevised

  • Return: ./@number, ./metadata/title, ./metadata/author, ./metadata/subjects/subject

  • Comments: This is a full-text query on the phrase "usability testing" using a wildcard on the word "test", restricted to the subject element. The query counts the number of author elements, and runs a greater than comparison on dates.

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
   [(($book/metadata/publicationInfo/dateIssued > "2000-12-31") 
   or ($book/metadata/publicationInfo/dateRevised > "2000-12-31")) 
   and count($book/metadata/author) > 1]
let $subj := $book//subject[. ftcontains "usability test.*" 
   with wildcards]
where count($subj)>0
return <book number="{$book/@number}"> 
          {$book/metadata/title, $book/metadata/author, $subj}
       </book>

Solution in XPath: None

Expected Result:

<book number="1">
   <title shortTitle="Improving Web Site Usability">Improving 
   the Usability of a Web Site Through Expert Reviews and 
   Usability Testing</title>
   <author>Millicent Marigold</author>
   <author>Morley Marigold</author>
   <subject>Usability testing</subject>
</book>

16.2.8 Q8 Query with XPath Expression Within Full-Text Expression

Find all books published after "2001" which share a subject with the book with the short title "Usability Basics".

This query finds words using an XPath expression to identify the words queried and looks for a publication date after the one specified.

  • Operands: "Usability Basics", "2001"

  • Functionality: phrase query, and query, date comparisons, XPath expression to identify the words queried.

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: ./metadata/title/@shortTitle, ./metadata/subjects/subject, ./metadata/publicationInfo/dateIssued|dateRevised

  • Return: ./metadata/title, ./metadata/author

  • Comments: This query returns a book if its last date of publication is after 2001 and one of its subjects is the same as a subject of the book with the short title "Usability Basics". This query uses an XPath expression to dynamically find the subjects of books.

Solution in XQuery:

let $books := doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $bookSubject := 
   $books/metadata[./title/@shortTitle 
   ftcontains "Usability Basics"]/subjects/subject
for $book in $books   
where $book/metadata/publicationInfo/dateIssued > 2001 or
     $book/metadata/publicationInfo/dateRevised > 2001 and
     $book/metadata/subjects/subject ftcontains 
     {$bookSubject} any
return
        <book number="{$book/@number}">
           {$book/metadata/title,
           $book/metadata/author}
        </book>

Solution in XPath: None

Expected Result:

<book number="1">
   <title shortTitle="Improving Web Site Usability">Improving 
   the Usability of a Web Site Through Expert Reviews and 
   Usability Testing</title>
   <author>Millicent Marigold</author>
   <author>Morley Marigold</author>
</book>

<book number="3">
   <title shortTitle="Usabilityguy Manuscript 
   Guide">John Wesley Usabilityguy: A Register of His 
   Papers</title>     
   <author>Millicent Marigold</author>
   <author>Morty Marigold</author> 
<book>

16.2.9 Q9 Query Using an XQuery Expression to Determine the Number of Words Allowed in a Window

Find all books which discuss "successfully completing tasks".

This query finds words within a window, allowing more words within the window depending on the number of chapters in the book.

  • Operands: "successfully" "completing" "tasks"

  • Functionality: word query, stemming, unordered window of at most (number of chapters in the book times 3) words

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: ./content

  • Return: ./metadata/title, ./content

  • Comments: This query uses an XQuery expression to determine the number of words in an unordered window. It allows more words in the window when there are more chapters in the book. The query does not return "tasks which are critical for users to be able to complete successfully" from Book 2, because there are three chapters in Book 2 which multiplied by three allows up to nine words within the window, not the 12 in the quoted phrase.

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
for $cont := $book/content[. ftcontains ("successfully" 
   ftand "completing" ftand "tasks") with stemming
   window at most (count(./contents/part/chapter) * 3) 
   words] 
where count($cont)>0
return $book/metadata/title, $cont

Solution in XPath

doc("http://bstore1.example.com/full-text.xml")
/books/book[count(./content ftcontains ("successfully" 
ftand "completing" ftand "tasks") with stemming
window at most (count(./contents/part/chapter) * 3)
words)>0]/(./metadata/title|./content)

Expected Result:

<title shortTitle="Usability Basics">Usability 
Basics: How to Plan for and Conduct Usability Tests 
on Web Site Thereby Improving the Usability of Your 
Web Site</title>
<content>
   ...
   <part number="1">
      <chapter>
         <title>Planning then Conducting Usability
         Tests</title> 
         <p>Take the following steps to plan usability 
         testing. <step number="1">Clarify and 
         articulate the goal of the usability testing.
         </step> <step number="2">Identify tasks which 
         are critical for users to be able to complete  
         successfully .</step> <step number="3">Compile 
         a script of questions or instructions which 
         will prompt the user to attempt those 
         tasks.</step> <step number="4">Identify your 
         users and begin recruiting them.</step> <step 
         number="5">Conduct a pretest on a few users.
         </step> <step number="6">Edit the script based 
         on insights gleaned from the pretest.</step> 
         <step number="7">Resume testing.</step></p>
      </chapter>
   </part>
   ...
</content>

17 Use Case "SCORE": All Queries May Be Written with Score, Queries in this Section Must Be Written with Score

17.1 Description

All the queries in these Use Cases may be written with or without score. The Use Cases in this section are merely a small subset that focuses on score.

These queries exploit score and can not be written as queries with pure Boolean full-text predicates. Among these queries are a query that computes and returns only scores, a query which returns only results over a specified threshold, a query which filters by score, a query which returns all the documents ordered, and a query which uses weighting to impact scoring and sorting.

Scoring methodologies will not be defined in this recommendation. Scoring is implementation-defined.

17.2 Queries and Results

17.2.1 Q1 Query Returning Scores

Find all books which mention "usability" in the title or the text. Return book titles and scores.

This query performs a word query and returns scores, highest scores first.

  • Operands: "usability"

  • Functionality: word query, implementation-defined scoring, returns score, construction of new element

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: ./metadata/title, ./content

  • Return: ./@number, ./metadata/title, score (constructed element)

  • Comments: This query is only possible as a scored query. Scores are included between 0 and 1. The scoring methodology in this use case is for illustrative purposes only. Scoring methodologies will be implementation-defined. This query returns the same results as a query with a pure Boolean full-text predicate. The difference is that the results are scored and the results are returned displaying the score and ranked by score.

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
  /books/book
let score $s := ($book/metadata/title ftcontains 
   "usability" or $book/content ftcontains "usability") 
where $s > 0  
order by $s descending 
return <book number="{$book/@number}"> 
          {$book/metadata/title},  <score>{$s}</score> 
       </book>

Solution in XPath: None

Expected Result:

<book number="2">
   <title shortTitle="Usability Basics">Usability 
   Basics: How to Plan for and Conduct Usability Tests 
   on Web Site Thereby Improving the Usability of Your 
   Web Site</title>
   <score>0.9</score>
</book>

<book number="1">
   <title shortTitle="Improving Web Site Usability">Improving 
   the Usability of a Web Site Through Expert Reviews 
   and Usability Testing</title>
   <score>0.8</score>
</book>
   
<book number="3">
   <title shortTitle="Usabilityguy Manuscript 
   Guide">John Wesley Usabilityguy: A Register of His 
   Papers</title>    
   <score>0.12</score>
</book>

17.2.2 Q2 Query Returning Results with Top Scores

Find the best two books on "usability".

This query performs a word query and returns only the results with the two top scores.

  • Operands: "usability"

  • Functionality: word query, implementation-defined scoring, returns books with the top two scores, conditional expression

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: .

  • Return: ./@number, ./metadata/title

  • Comments: This query returns results only for the two books with the highest scores. This query is only possible as a scored query. The scoring methodology in this use case is for illustrative purposes only. Scoring methodologies will be implementation-defined. This query returns the same results as a query with a pure Boolean full-text predicate. The difference is that the results are scored and through the introduction of a third variable only the two results with the highest scores are returned.

Solution in XQuery:

for $result at $i in
     for $book score $s in 
        doc("http://bstore1.example.com/full-text.xml")
        /books/book[. ftcontains "usability"]
      order by $s descending
      return $book
   where $i <= 2
   return <book number="{$result/@number}"> 
      $result/metadata/title</book>

Solution in XPath: None

Expected Result:

<book number="1">
   <title shortTitle="Improving Web Site Usability">Improving 
   the Usability of a Web Site Through Expert Reviews 
   and Usability Testing</title>
</book>
   
<book number="2">
   <title shortTitle="Usability Basics">Usability 
   Basics: How to Plan for and Conduct Usability Tests 
   on Web Site Thereby Improving the Usability of Your 
   Web Site</title> 
</book>

17.2.3 Q3 Query Filtering on Scores

Find all books that focus on "usability".

This query performs a word query and filters on scores.

  • Operands: "usability"

  • Functionality: word query, implementation-defined scoring, filters on scores (accepts only those with score over 0.1)

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: .

  • Return: ./@number, ./metadata/title

  • Comments: This query is only possible as a scored query. The scoring methodology in this use case is for illustrative purposes only. Scoring methodologies will be implementation-defined. This query returns the same results as a query with a pure Boolean full-text predicate. The difference is that the results are scored and then filtered on the scores.

Solution in XQuery:

for $book score $s in 
   doc("http://bstore1.example.com/full-text.xml")
   /books/book[. ftcontains "usability"]
where $s > 0.1
return $book/metadata/title

Solution in XPath:

doc("http://bstore1.example.com/full-text.xml")
/books/book[(for $i score $s in .[. ftcontains "usability"]
return $s) > 0.1]/metadata/title

Expected Result:

<title shortTitle="Improving Web Site Usability">Improving 
the Usability of a Web Site Through Expert Reviews 
and Usability Testing</title>

<title shortTitle="Usability Basics">Usability 
Basics: How to Plan for and Conduct Usability Tests 
on Web Site Thereby Improving the Usability of Your 
Web Site</title>

17.2.4 Q4 Query Combining Score and XML Structure with a Conditional Return

Find all books with parts about "usability testing".

This query finds books which contain parts about usability testing, returning entire books, but without part elements identified as irrelevant via score.

  • Operands: "usability testing"

  • Functionality: phrase query, character wildcard (suffix) (0 or more), implementation-defined scoring, filters on scores (under .05), conditional return

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: ./content/part

  • Return: ./@number, ./metadata/title, ./content/part/@number, ./content/part//title, ./content/part/p

  • Comments: This query is only meaningful as a scored query. The scoring methodology in this use case is for illustrative purposes only. Scoring methodologies will be implementation-defined. This query returns the same results as a query with a pure Boolean full-text predicate. The difference is that this query filters the part elements. They are included or excluded from the results depending on their score.

Solution in XQuery:

declare function local:filter ( $nodes 
   as node()*, $exclude as element()* ) as node()*
   {
      for $node in $nodes except $exclude
      return
         typeswitch ($node)
            case $e as element()
               return 
                 element {node-name($e)}
                   {
                       $e/@*,
                      filter( $e/node() except $exclude, 
                      $exclude )
                   }
            default 
               return $node
   };

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $irrelevantParts := 
   for $part in $book//part
   let score $score := $part ftcontains "usability test.*" 
      with wildcards
   where $score < 0.5
   return $part
where count($irrelevantParts) < count($book//part)
return filter($book, $irrelevantParts)

Solution in XPath: None

Expected Result:

<book number="1">
   <metadata>
      ...
   </metadata>
   <content>
      <introduction>
         <author>Elina Rose</author>
         <p>The usability of a Web site is how well the 
         site supports the user in achieving specified 
         goals. A Web site should facilitate learning, 
         and enable efficient and effective task 
         completion, while propagating few errors. 
         Satisfaction with the site is also important. 
         The user must not only be well-served, but must 
         feel well-served.</p> 
         <p>Expert reviews and usability testing are 
         methods of identifying problems in layout, 
         terminology, and navigation before they frustrate
         users and drive them away from your site.</p>
         <p>The most successful projects employ multiple 
         methods in multiple iterations. As Millicent 
         Marigold remarked during a recent conference, 
         "Don't stop. Iterate, iterate, then iterate 
         again."</p>
         <p>This book has been approved by the Web Site 
         Users Association.</p>
      </introduction>
      ...
      <part number="2">
         <chapter>
            <title>Usability Testing</title>
            <p>Once the problems identified by expert 
            reviews have been corrected, it is time to 
            conduct some tests of the site with your unique 
            audience or audiences by conducting usability 
            testing.</p>
            <p>Users are asked to complete tasks which 
            measure the success of the information 
            architecture and navigational elements of the 
            site.</p>
            <p>Then changes are made to improve service to 
            users.</p>
         </chapter>
      </part> 
   </content>
</book>

<book number="2">
   <metadata>
      ...
   </metadata>
   <content>
      <introduction>
         <p>This is a basic handbook for planning and 
         conducting usability tests on Web sites. Usability 
         testing should be used in conjunction with other 
         expert review methods.</p>
         <p>This book has not been approved by the Web Site 
         Users Association.</p>
      </introduction>
      <part number="1">
         <chapter>
            <title>Planning then Conducting Usability 
            Tests</title> 
            <p>Take the following steps to plan usability
            testing. <step number="1">Clarify and 
            articulate the goal of the usability testing.
            </step> <step number="2">Identify tasks which 
            are critical for users to be able to complete 
            successfully.</step> <step number="3">Compile 
            a script of questions or instructions which 
            will prompt the user to attempt those 
            tasks.</step> <step number="4">Identify your 
            users and begin recruiting them.</step> <step 
            number="5">Conduct a pretest on a few users.
            </step> <step number="6">Edit the script based 
            on insights gleaned from the pretest.</step> 
            <step number="7">Resume testing.</step></p>
         </chapter>
      </part>
      <part number="2">
         <chapter>
            <title>Conducting Usability Tests</title> 
            <p>Users can be tested at any computer 
            workstation <footnote>They may be more 
            comfortable at their own workstation than in 
            a lab.</footnote> or in a lab.</p>
            <p>Give the user the script, then assure them 
            that you are testing the Web site, not them. 
            Users are asked to verbalize their thoughts as 
            they complete the tasks. The event is recorded 
            or someone takes notes. It is often preferable 
            to have two testers, <footnote>Usability 
            testing can be done at great expense or on a 
            shoe string, using <testingProcedure>in-house 
            expertise</testingProcedure> or 
            <testingProcedure>contracting with human 
            computer interaction professionals
            </testingProcedure>.</footnote> one to ask the 
            questions, another to take notes. Testers should 
            offer no guidance or comments to the user. Mouse 
            movements, typing, expressions, and the user's 
            words should be recorded.</p>
         </chapter>
         <chapter>
            <title>Evaluating and Implementing Results</title> 
            <p>Compile the results and review collectively. 
            Make changes to the site to alleviate the problems 
            found in Web site components which were propagating 
            the largest number of or the most devastating errors. 
            Begin new iterations of testing and changes, until 
            users are successful in the accomplishing the 
            tasks.</p>
         </chapter>
      </part>
   </content>
</book>

17.2.5 Q5 Query Returning All Books Ordered by Score

Return all books, listing books with text on "software" first.

This query performs a word query, returns all the documents in the database, and orders them returning those with found word first, those without last.

  • Operands: "software"

  • Functionality: word query, implementation-defined scoring

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: .

  • Return: ./@number, ./metadata/title, .

  • Comments: This query is only meaningful as a scored query. The scoring methodology in this use case is for illustrative purposes only. Scoring methodologies will be implementation-defined. This query returns the more results than a parallel query with a pure Boolean full-text predicate. In a parallel query with a pure Boolean full-text predicate, the last result would have a Boolean value of false and would not be returned. In this scored query the last result receives a score and is returned.

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let score $s := $book//content ftcontains "software"
order by $s descending
return $book

Solution in XPath: None

Expected Result:

<book number="1">
   <metadata>
      ...
   </metadata>
   <content>      
      <part number="1">
         <title>Expert Reviews</title>
         <introduction>
            ...                                                                 
            <p>Expert review methods should be
            initiated early in the development process, 
            as soon as paper <b>p</b>rototypes
            (hand-drawn pictures of Web pages) or
            <b>w</b>ireframes (electronic mockups) are
            available. They should be conducted using
            the hardware and software similar to that 
            employed by users.</p>
         </introduction>
      </part> 
      ...
   </content>
</book>

<book number="3">
   <metadata>
      ...
   </metadata>
   <content>
      <introduction>   
         <p>The papers of John Wesley Usabilityguy span the 
         years 1946-2001, with the bulk of the items 
         concentrated in the period from 1985 to 2001. The 
         papers feature his career as a developer of software 
         applications and usability specialist. The collection 
         consists of correspondence, memoranda, journals, 
         speeches, article drafts, book drafts, notes, charts, 
         graphs, family papers, clippings, printed matter, 
         photographs, résumés and other materials.</p>
      </introduction>
      ...
   </content>
</book>

<book number="2">
   <metadata>
      ...
   </metadata>
   <content>      
      ...
   <content>      
</book>

17.2.6 Q6 Query with Weight Declaration

Finds books which discuss "conducting usability tests" returning those which mention "measuring success" first.

This query finds words using weighting on optional words to impact the scoring and sorting.

  • Operands: "conduct" "usability" "tests" "measuring" "success"

  • Functionality: word queries, stemming, unordered distance (0 to 10 intervening words between "conduct" and "usability" and between "usability" and "tests"), unordered distance (0 to 4 intervening words between "measuring" and "success"), weight declaration

  • Data context: doc("http://bstore1.example.com/full-text.xml")/books/book

  • Query context: ./content

  • Return: ./metadata/title, ./content

  • Comments: This query returns books on "conducting usability tests", using a weight declaration to return books with mentions of "measuring success" higher in the sort.

Solution in XQuery:

for $book in doc("http://bstore1.example.com/full-text.xml")
   /books/book
let $booktext := $book/content[. ftcontains 
   "conduct" ftand "usability" ftand "tests"
   with stemming distance at most 10 words]
let score $s := $booktext ftcontains 
   "measuring" ftand "success" with stemming distance
   at most 4 words weight 0.8
where count($booktext) > 0
order by $s
return $book/metadata/title, $booktext

Solution in XPath: None

Expected Result:

<title shortTitle="Improving Web Site Usability">Improving 
the Usability of a Web Site Through Expert Reviews 
and Usability Testing</title>
<content>
   ...
   <part number="2">
      <chapter>
         <title>Usability Testing</title>
         <p>Once the problems identified by expert 
         reviews have been corrected, it is time to 
         conduct some tests of the site with your unique 
         audience or audiences by conducting usability 
         testing.</p>
         <p>Users are asked to complete tasks which 
         measure the success of the information 
         architecture and navigational elements of the 
         site.</p>
         <p>Then changes are made to improve service to 
         users.</p>
      </chapter>
   </part> 
</content>

<title shortTitle="Usability Basics">Usability 
Basics: How to Plan for and Conduct Usability Tests 
on Web Site Thereby Improving the Usability of Your 
Web Site</title>
<content>
   <introduction>
      <p>This is a basic handbook for planning and 
      conducting usability tests on Web sites. Usability 
      testing should be used in conjunction with other 
      expert review methods.</p>
      <p>This book has not been approved by the Web Site 
      Users Association.</p>
      </introduction>
   <part number="1">
      <chapter>
         <title>Planning then Conducting Usability 
         Tests</title> 
         <p>Take the following steps to plan usability 
         testing. <step number="1">Clarify and 
         articulate the goal of the usability testing.
         </step> <step number="2">Identify tasks which 
         are critical for users to be able to complete 
         successfully.</step> <step number="3">Compile 
         a script of questions or instructions which 
         will prompt the user to attempt those 
         tasks.</step> <step number="4">Identify your 
         users and begin recruiting them.</step> <step 
         number="5">Conduct a pretest on a few users.
         </step> <step number="6">Edit the script based 
         on insights gleaned from the pretest.</step> 
         <step number="7">Resume testing.</step></p>
      </chapter>
   </part>
   <part number="2">
      <chapter>
         <title>Conducting Usability Tests</title> 
         <p>Users can be tested at any computer 
         workstation <footnote>They may be more 
         comfortable at their own workstation than in 
         a lab.</footnote> or in a lab.</p>
         <p>Give the user the script, then assure them 
         that you are testing the Web site, not them. 
         Users are asked to verbalize their thoughts as 
         they complete the tasks. The event is recorded 
         or someone takes notes. It is often preferable 
         to have two testers, <footnote>Usability 
         testing can be done at great expense or on a 
         shoe string, using <testingProcedure>in-house 
         expertise</testingProcedure> or 
         <testingProcedure>contracting with human 
         computer interaction professionals
         </testingProcedure>.</footnote> one to ask the 
         questions, another to take notes. Testers should 
         offer no guidance or comments to the user. Mouse 
         movements, typing, expressions, and the user's 
         words should be recorded.</p>
      </chapter>
      ...
   </part>
</content>

A Acknowledgements

The editors thank the members of the Full-Text Task Force of the XML Query and XSL Working Groups, which produced the material in this document. Special thanks to Stephen Buxton for contributing the first version of the schema.

The editors thank the following staff at the Library of Congress for providing and improving sample data and queries: Ardith Bausenbach, Caroline Arms, Marla Banks, Susan David, Ray Denenberg, Louis Drummond, Bohdan Kantor, Mary A. Lacy, Joe Pagano, Betsy Reifsnyder, Belinda D. Urquiza, and Anne Washington.

Thanks also to Bohdan Kantor, Foster Zhang, François Yergeau, and Michel Biezunski for assistance in translating the subjects in the sample data into Chinese and French.

The editors also wish to thank the members of the W3C Internationalization Working Group for their assistance.

B References

B.1 References (Primary)

The following references are some of the works considered by the Working Groups in deriving its use cases.

XQuery 1.0 and XPath 2.0 Functions and Operators
XQuery 1.0 and XPath 2.0 Functions and Operators, Ashok Malhotra, Jim Melton, and Norman Walsh, Editors. World Wide Web Consortium, 23 Jan 2007. This version is http://www.w3.org/TR/2007/REC-xpath-functions-20070123/. The latest version is available at http://www.w3.org/TR/xpath-functions/.
Infoset
XML Information Set (Second Edition), John Cowan and Richard Tobin, Editors. World Wide Web Consortium, 04 Feb 2004. This version is http://www.w3.org/TR/2004/REC-xml-infoset-20040204. The latest version is available at http://www.w3.org/TR/xml-infoset.
Maier98
Database Desiderata for an XML Query Language, David Maier, 1998. In Query Languages 98 (QL'98). This paper is at http://www.w3.org/TandS/QL/QL98/pp/maier.html.
XML
Extensible Markup Language (XML) 1.0 (Fourth Edition), Eve Maler, Jean Paoli, François Yergeau, et. al., Editors. World Wide Web Consortium, 16 Aug 2006. This version is http://www.w3.org/TR/2006/REC-xml-20060816. The latest version is available at http://www.w3.org/TR/xml.
XMLSchema0
XML Schema Part 0: Primer Second Edition, David C. Fallside and Priscilla Walmsley, Editors. World Wide Web Consortium, 28 Oct 2004. This version is http://www.w3.org/TR/2004/REC-xmlschema-0-20041028/. The latest version is available at http://www.w3.org/TR/xmlschema-0/.
XMLSchema1
XML Schema Part 1: Structures Second Edition, Henry S. Thompson, David Beech, Noah Mendelsohn, and Murray Maloney, Editors. World Wide Web Consortium, 28 Oct 2004. This version is http://www.w3.org/TR/2004/REC-xmlschema-1-20041028/. The latest version is available at http://www.w3.org/TR/xmlschema-1/.
XMLSchema2
XML Schema Part 2: Datatypes Second Edition, Paul V. Biron and Ashok Malhotra, Editors. World Wide Web Consortium, 28 Oct 2004. This version is http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/. The latest version is available at http://www.w3.org/TR/xmlschema-2/.
XQuery 1.0: An XML Query Language
XQuery 1.0: An XML Query Language, Don Chamberlin , Anders Berglund, Scott Boag, et. al., Editors. World Wide Web Consortium, 23 Jan 2007. This version is http://www.w3.org/TR/2007/REC-xquery-20070123/. The latest version is available at http://www.w3.org/TR/xquery/.
XML Query Use Cases
XML Query Use Cases, Jonathan Robie, Don Chamberlin, Peter Fankhauser, et. al., Editors. World Wide Web Consortium, 8 Jun 2006. This version is http://www.w3.org/TR/2006/WD-xquery-use-cases-20060608/. The latest version is available at http://www.w3.org/TR/xquery-use-cases/.
XQuery 1.0 and XPath 2.0 Full-Text 1.0
ERROR: NO xpath-full-text-10 KNOWN!
XQuery 1.0 and XPath 2.0 Full-Text 1.0 Requirements
ERROR: NO xpath-full-text-10-requirements KNOWN!
XML Path Language (XPath) 2.0
XML Path Language (XPath) 2.0, Don Chamberlin , Anders Berglund, Scott Boag, et. al., Editors. World Wide Web Consortium, 23 Jan 2007. This version is http://www.w3.org/TR/2007/REC-xpath20-20070123/. The latest version is available at http://www.w3.org/TR/xpath20/.
XSL Transformations (XSLT) Version 2.0
XSL Transformations (XSLT) Version 2.0, Michael Kay, Editor. World Wide Web Consortium, 23 Jan 2007. This version is http://www.w3.org/TR/2007/REC-xslt20-20070123/. The latest version is available at http://www.w3.org/TR/xslt20/.

B.2 References (Background)

BYR99
Modern Information Retrieval, R.Baeza-Yates, B. Ribeiro-Neto. Addison Wesley, 1999.
FGR01
XIRQL: An Extension of XQL for Information Retrieval, N. Fuhr, K. Grossjohann. Proceedings of SIGIR, 2001.
HTK00
Searching Text-Rich XML Documents with Relevance Ranking, Y. Hayashi, J. Tomita, G. Kikui. Proceedings of SIGIR Workshop on XML and Information Retrieval, 2000.
MJK98
A Flexible Model for Retrieval of SGML Documents, S. Myaeng, D.-H. Jang, M.-S. Kim, Z.-C. Zhoo. Proceedings of SIGIR, 1998.
SCH01
Similarity Search in XML Data Using Cost-Based Query Transformations, T. Schlieder. Proceedings of SIGMOD WebDB Workshop, 2001.
TWE00
Adding Relevance to XML, A. Theobald and G. Weikum. Proceedings of SIGMOD WebDB Workshop, 2000.

C Issues

Issue: staticErrorTesting, priority: , status: open

1. Testing queries for static errors

The queries in the Full-Text Use Cases have not yet been tested to ensure they do not cause static errors, such as cardinality errors.

Raised by Michael Rys, Full-Text Redwood Shores meeting, March 30.

Resolution:

None.

D Change Log

Pat Case 2003-06-18 Added a Change Log
Pat Case 2003-06-18 Statements of Functionality Illustrated by Query Modified Added a Data Context to the Statement of Functionality Illustrated by Query for each query. Made XPath expressions in Query Context and Return relative to the XPath expression in Data Context.
Sihem Amer-Yahia 2003-06-18 Schema Modified Replaced schema with a shorter one which defines more shared types.
Sihem Amer-Yahia 2003-06-18 New Use Cases Added Added the following Use Cases: 3.2.11 Q11 Query on Entire Document, 14.2.11 Q11 Phrase Query Ignoring Explicit List of Tags and Content of Descendant Elements.
Pat Case 2003-06-23 New Use Case Added Added the following Use Case: 16.2.7 Q7 Query on Full-Text Combined with Conditional on Date and Full-Text.
Pat Case 2004-02-24 Solutions in XQuery Added Added Solutions in XQuery authored by Full Text Task Force Members.
Pat Case 2004-02-24 Use Case Removed Removed the following Use Case: 2.2.3 Q3 Single Phrase Query on Long Text Excerpt.
Pat Case 2004-02-24 Switched Use of Proximity and Distance Proximity is now the broader term, distance (proximity counting intervening words) and window are the narrower terms.
Pat Case 2004-02-24 Added Definition of the Word "Tag" Added definition of the word "tag" to the introduction to the Ignore Section (subsequently moved to the Across Element Boundaries Section).
Pat Case 2004-03-15 Edited Solutions in XQuery Made changes such as removing operators and unnecessary parentheses, made stopwords stop words, etc.
Pat Case 2004-03-15 Query Statements and Expected Results Changed Made extensive changes to statements of query functionality and expected results to correlate with the new solutions.
Pat Case 2004-04-26 Use Cases Removed Removed the following use cases: 3.2.1 Q1 Query on Element, 4.2.1 Q1 Query on Word Ignoring Single Stop Word, 4.2.3 Q3 Query on Phrase Word, 4.2.4 Q4 Query on Phrase Ignoring Multiple Stop Words, 4.2.5 Q5 Query on Phrase Overriding Multiple Stop Words, 6.2.3 Q3 Single Infix Character Wildcard Query, 6.2.5 Q5 0 or More Suffix Character Wildcard Query, 6.2.9 Q9 Word Wildcard Query, 6.2.10 Q10 Specified Range Word Wildcard Query, 9.2.2 Q2 Or Query on More Than Two Words, 9.2.3 Q3 Or Query on Phrases, 9.2.5 Q5 And Query on More Than Two Words, 9.2.6 Q6 And Query on Phrases, 10.2.3 Q3 Unordered Window Query, 10.2.5 Q5 Unordered Within a Sentence Query, 10.2.7 Q7 Unordered Within a Paragraph Query, 12.2.1 Q1 Multiple Word Query, 12.2.2 Q2 Phrase Word Query, 13.2.3 Q3 Query on Element and Its Descendants, 13.2.4 Q4 Query on Element and Its Parent, 13.2.7 Q7 Query on Element and Its Siblings, 13.2.8 Q8 Query on Same Element in Different Sub-Trees, 14.2.2 Q2 Query Ignoring ! Tags Within Multiple Words, 14.2.4 Q4 Phrase Query Ignoring Explicit List of Tags of Descendant Elements, 14.2.8 Q8 Phrase Query Ignoring Tags and Content of Descendant Elements Identified by an XPath Query, 14.2.10 Q10 Distance Query Ignoring All Tags and Content of Descendant Elements, 14.2.11 Q11 Phrase Query Ignoring Explicit List of Tags and Content of Descendant Elements.
Pat Case 2004-04-26 Reorganized sections, moved and reworked numerous use cases. Removed the Querying Words and Phrases Section and the Advanced Word and Phrase Query Section. Added sections for Querying Across XML Element Boundaries, Querying on Attribute Values, and Querying Instances of Elements. Reorganized the sections so functionality is introduced before it is used. Revised titles of sections and titles of queries.
Pat Case 2004-04-26 Use Cases Added Added the following Use Cases:13.2.6 Q6 Query Combining Score and XML Structure with a Conditional Return, 16.2.8 Q8 Query with an XQuery Expression Within the Full-Text Expression.
Pat Case 2004-04-26 <authors> Elements Removed Removed the unnecessary <authors> elements from the sample data, schema, and use cases.
Pat Case 2004-04-26 Solutions in XPath Added Added Solutions in XPath authored by Full Text Task Force Members.
Pat Case 2004-04-26 Query Statements and Expected Results Changed Made extensive changes to statements of query functionality and expected results to correlate with the new solutions.
Pat Case 2004-05-19 Renamed and Reversed Order of Sections The INSTANCE Section was renamed CARDINALITY. The COMPOSABILITY Section was renamed XQUERY-XPATH-COMPOSABILITY and the COMPLEX Section was renamed FULL-TEXT-COMPOSABILITY, and their order in the document was reversed.
Pat Case 2004-09-17 Removed Version Statements Removed the "For consideration in v.1" and "For consideration after v.1 version" statements from the Statements of functionality illustrated by query.
Pat Case 2004-09-17 Changed queries Changed query statements, solutions, and results based on implementer feedback and Task Force decisions in the following use cases: Use case 14.2.1. Q1 Distance Query Ignoring Content of All Descendant Elements (changed the element whose descendants are ignored to one with content; without content keywords must be followed by an Exp so to ignore all of the descendants added *), Use Case 16.2.8 Q8 Query with XQuery Expression Within Full-Text Expression (changed all to any), Use Case 10.2.5 Q5 And Not Query (added Book 3 as a result), Use Case 15.2.5 Q5 Query on Different Elements in Different Sub-Trees with Conditional Return (added an "s" to problems in a let statement, corrected the $i(s) to $in(s), corrected the book number on the result to 1), Use Case 16.2.4 Q4 Full-Text Query with Numeric Value Comparison (added missing curly brace in element constructor), Use Case 16.2.5 Q5 Full-Text Query with Character String Query (changed metadata for Book 3 and the query to look for Washington, D.C. to make the result valid), Use Case 16.2.8 Q8 Query with XQuery Expression Within Full-Text Expression (Changed the query statement to search the book short title, improved the query and the comment statement), Use Case 13.2.4 Q4 Query on Element and Its Right Siblings (improved query).
Pat Case 2004-09-18 Added FTUnit to window function Added the FTUnit "word" to query solutions using the window function.
Pat Case 2004-09-22 Changed query in XQUERY-XPATH-COMPOSABILITY Section Changed query statements, solutions, and results based on implementer feedback and Task Force decisions in Use Case 16.2.8 Q8 Query with XQuery Expression Within Full-Text Expression. (made it search any document not only $book, collapsed where clauses).
Pat Case 2005-01-17 Changed score functionality Changed the score functions (ft:score) to score clauses in the SCORE Section.
Pat Case 2005-01-17 Removed use cases from CHARACTER Section Removed 9.2.5 Query on Word with Special Character and 9.2.6 Query on Word with Special Character or Phrase with Space from the CHARACTER Section.
Pat Case 2005-01-17 Updated syntax Updated the syntax for wildcards, stop words, starts-with, entire content, and thesauri.
Pat Case 2005-02-01 Added XPath example of score functionality Added XPath example of score clauses in the SCORE Section Q3 Filtering on Scores.
Pat Case 2005-02-02 Removed explicit unordered Removed the "unordered" keyword from unordered queries. The default is unordered; the presence of the "ordered" keyword overrides the default.
Pat Case 2005-02-10 Updated distance and window syntax Updated distance queries removing the no longer acceptable "with" keyword. Updated window queries removing the no longer acceptable "within" keyword.
Pat Case 2005-03-09 Updated FTTimes syntax Updated the FTTimes syntax from "at least 2 occurrences" to "occurs at least 2 times".
Pat Case 2005-03-09 Added syntax for embedded XQuery Added syntax (curly braces "{}") around XQuery expressions embedded in XQuery Full-Text expressions.
Pat Case 2005-03-09 Reformatted URLs in solutions Reformatted URLs in solutions to enable automatic parsing.
Pat Case 2005-03-09 Updated thesaurus and stop words syntax Updated thesaurus and stop words syntax to include the keyword "at" before URLs.
Pat Case 2005-08-08 Changed FTMildNegation syntax Changed "mild not" to "not in" in 10.27 Q7 Mild Not Query Where Second Operand Is a Subset of the First Operand.
Pat Case 2005-08-25 Changed score syntax Changed to new scoring syntaxes in Section 17. Use cases 1-4 illustrate scored queries returning the same results as a parallel pure Boolean full-text predicate query. 17.2.5 Q5 Query Returning All Books Ordered by Score illustrates a scored query returning more results than a parallel pure Boolean full-text predicate query.
Pat Case 2005-08-25 Corrected 15.2.4 Q4 Changed the title of 15.2.4 Q4 Distance and Boolean Queries Ignoring Content of a Descendant Element with Wildcards and Stemming to 15.2.4 Q4 Window Query with Wildcards and Stemming Ignoring Content of a Descendant Element. Rewrote the query.
Pat Case 2005-08-25 Changed window syntax Changed to new window syntax, removing FTRange. Changed the syntax in 12.2.3 Q3 Ordered Window Query and 15.2.4 Q4 Window Query with Wildcards and Stemming Ignoring Content of a Descendant Element.
Pat Case 2006-01-06 Corrected operands Corrected the operands in XQuery and XPath solutions to 3.2.6. Q6 Query on Entire Document.
Pat Case 2006-01-06 Added 3 new use cases Added 8.2.3. Q3 Query Excluding a Stop Word on a Stop Word List, 6.2.9 Q9 Query Using an XQuery Expression to Determine the Number of Words Allowed in a Window, and 17.2.6. Query with Weight Declaration.
Pat Case 2006-01-06 Revised level by level ignore query Revised 14.2.4. Q4 Distance Query Ignoring Content of Descendant Elements Level by Level.
Pat Case 2006-02-02 Changed use of curly braces Changed the use of curly braces in 16.2.8. Q8 Query with XPath Expression Within Full-Text Expression to reflect Task Force decision that curly braces surround XQuery expressions when they are within an FTContainsExpr where an FTSelection may occur (they are optional for literals).
Pat Case 2006-11-17 Corrected operator Corrected operator in Use Case 2.2.4 Q4 Query in Different Elements from an or to a union because it is operating on nodes.
Pat Case 2007-02-24 Changed syntax for and, or, not Changed syntax for the full-text and, or, not operators from &&, ||, ! to ftand, ftor, ftnot.
Pat Case 2007-02-24 Moved ordered keywords Moved ordered keywords before distance and window operators so ordered is processed before distance and window.