Query Grammar in the Test Client

In this section:

The following topics provide the basics of query grammar used in the Test Client.


Top of page

x
Searching Elements in the Test Client

The following image shows the iWay Archive Search query page.

iWay Archive Search query page

Specify the query in the Key:Value search box to search the archive. The Key portion of the query consists of the hierarchical element structure that you wish to query. The Key must be surrounded by double quotation marks. The Value portion consists of the value that the element must match. If the value is a string, it must be surrounded by double quotation marks. If the value is numeric, do not use quotation marks.



Example: Element Search

Consider the following XML document:

<?xml version="1.0" encoding="UTF-8"?>
   <a>
      <b>test</b>
      <c>12345</c>
   </a>

Typing "a.b":"test" retrieves all documents whose <b> element is equal to the string "test". The following image shows the results in the Test Client.

iWay Archive element search results


Top of page

x
Searching Attributes in the Test Client

In the iWay XML Archive, XML documents are first converted to JSON (Java Script Object Notation) before they are loaded into the archive. This notation is used for storage and retrieval efficiency. Changes that convert attributes to child elements are made to the XML structure to support this notation.



Example: Attribute Search

Consider the following XML document:

<?xml version="1.0" encoding="UTF-8"?>
   <a name="bob">
      <b>test</b>
      <c>12345</c>
   </a>

Typing "a.name":"bob" retrieves all documents containing the name attribute of the <a> element that equals the string bob. The following image shows the results in the Test Client.

iWay Archive attribute search results


Top of page

x
Searching on Multiple Keys (and) in the Test Client

To search for a document based on multiple keys, type comma-delimited, key-value pairs in the Key:Value search box. This is similar to an and in a SQL where clause.



Example: Multiple Key Search

Consider the following XML document:

<?xml version="1.0" encoding="UTF-8"?>
   <a name="bob">
      <b>test</b>
      <c>12345</c>
   </a>

Typing the search term "a.name":"bob","a.b":"test" returns all documents containing the name attribute of the <a> element that equals the string bob, and whose <a><b> element value is equal to the string test. The following image shows the results in the Test Client.

iWay Archive multiple key search results


Top of page

x
Advanced Queries in the Test Client

Some queries require extra operators, such as an or query. Some of these advanced queries are documented at:

http://www.mongodb.org/display/DOCS/Advanced+Queries



Example: Advanced Query

Consider the following XML documents:

<?xml version="1.0" encoding="UTF-8"?>
   <a name="bob">
      <b>test</b>
      <c>12345</c>
   </a>
<?xml version="1.0" encoding="UTF-8"?>
   <a name="bob">
      <b>testA</b>
      <c>12345</c>
   </a>

Typing the search term $or:[{"a.b":"test"},{"a.b":"testA"}] results in the return of both documents, as shown in the following image. You can see that the $or key operator has the value of a JSON array with two JSON-formatted, Key:Value pair objects.

iWay Archive advanced query search results


Top of page

x
Using Regular Expressions in the Test Client

You can use Pearl Compatible Regular Expressions (PCRE) for the value of a search expression. The expressions are not enclosed in quotation marks, and are bound between / (slash) characters. For more information on PCRE, see http://www.cs.tut.fi/~jkorpela/perl/regexp.html.



Example: Regular Expression

Consider the following XML documents:

<?xml version="1.0" encoding="UTF-8"?>
   <a name="bob">
      <b>test</b>
      <c>12345</c>
   </a>
<?xml version="1.0" encoding="UTF-8"?>
   <a name="bob">
      <b>testA</b>
      <c>12345</c>
   </a>

Typing "a.b.":/test.*/ returns all documents whose <a><b> element values contain the string test, even if there is text following test. The period (.) and asterisk (*) operators match anything after the string test, 0 or more times.


Top of page

x
Understanding the Results

The following image shows the results of an empty query, which returns all documents in the archive.

iWay Archive empty query screen

The ID column of the result set contains the key for the record returned. This key can be used in a query to retrieve one particular document. For more information, see Special Queries. The XML column contains a link that returns the full XML document for the record from the archive.


Top of page

x
Applying an XQuery

You can apply an XQuery to a set of documents matching the mongoDB Key:Value query by selecting the Apply XQuery check box and typing a query in the XQuery to apply: field.

You can also apply an XQuery to an individual document in a result set by selecting the Apply XQuery check box, and then clicking the xml link in the result set.

Information on XQuery is available at:

http://www.w3schools.com/xquery/default.asp



Example: XQuery

Consider the following XML documents:

<?xml version="1.0" encoding="UTF-8"?>
   <a name="bob">
      <b>test</b>
      <c>12345</c>
   </a>
<?xml version="1.0" encoding="UTF-8"?>
   <a name="bob">
      <b>testA</b>
      <c>12345</c>
   </a>

With a Key:Value query of "a.name":"bob" and an XQuery of for $x in /a return $x/b, two XML documents are returned. The returned documents have the following format:

<?xml version="1.0" encoding="UTF-8"?>
<XQueryResult>
   <item>Return xml</item>
</XQueryResult>

The results are wrapped in an <XQueryResult><item> element, in case the query has multiple items, and the root has been removed.

An example of the query performed in the Test Client is shown in the following image.


Top of page

x
Special Queries

The archive query language uses a special notation for querying ID or date fields. Date fields are a special case and must be defined to the archive prior to loading.



x
Querying an ID

The following image shows a search result of two records.

Search results for two records

Given the preceding search results, to retrieve just the third record in the list, type "_id":new ObjectId("4d01274ce4e6cb0bf5d2e0cc") in the Key:Value field. The following image shows the results.

Search results for three records


iWay Software