OpenWGA 7.10 - OpenWGA Concepts and Features

Design and development » WebTML » Basic concepts » Document collections

Queries

Queries are another way of collecting documents for output. Using queries documents can be selected based on a large variation of criterias. For example: A query could select the 10 most recently updated documents. Or they could fetch all documents who contain the word "OpenWGA".

WebTML Queries specify a query expression to determine the criterias that documents must meet to be collected. Based on this expression OpenWGA finds all documents in the content store that match these criterias and collects them. The syntax that is used for a query expression is determined by the query type. The query type determines the "query language" that is used. The query types that are available depend on the database type in use. See the Query languages reference on which query types are available for the database type you are using and on how to use them.

In WebTML executing a Query and putting out its result is a bit more complicated than writing a navigator. Three tags are involved for doing this:

<tml:collection>

 

  <tml:query type="querytype"> query expression </tml:query>


  <tml:foreach>

      ... Output per document ...

  </tml:foreach>


</tml:collection>

  • The tag <tml:query> takes the query expression and determines the query type with attribute "type"
  • The tag <tml:foreach> receives the collected documents and determines the ouput per document.
  • The tag <tml:collection> groups the whole query operation and connects the involved tags

Note that only the <tml:foreach> tag produces visible results.

A frequently used query type is "lucene", which uses the built-in fulltext index of OpenWGA. It can take individual phrases as query expression which then are searched in the text items of all documents. Here an example that searches for all documents containing the text "OpenWGA" and puts out their titles as HTML list:

<ul>

  <tml:collection>


    <tml:query type="lucene">OpenWGA</tml:query>


    <tml:foreach>

      <li><tml:meta name="title"/>

    </tml:foreach>


  </tml:collection>

</ul>

Another frequently used query type, available for all content stores on relational database platforms, is "hql". It is an object-oriented version of SQL, allowing very specific criteria definitions. Mostly you only specify the "WHERE" part of the query in which you reference object properties and specify the value that they should have in order to be selected. The following query selects all contents using the content type "standard":

<ul>

  <tml:collection>


    <tml:query type="hql">content.structentry.contenttype.name='standard'</tml:query>


    <tml:foreach>

      <li><tml:meta name="title"/>

    </tml:foreach>


 </tml:collection>

</ul>

Query collections are not limited to just taking one query. You can specify as many query tags as you want. Their results will get concatenated in they order they were defined. The following example executes two queries which search for two differing values in an text item named" doctype":

<tml:collection>


  <tml:query type="hql">content.items['doctype'].text='project'</tml:query>

  <tml:query type="hql">content.items['doctype'].text='workgroup'</tml:query>


    <tml:foreach>

      ....

   </tml:foreach>


</tml:collection>

Some query types like "hql" accept query parameters. These are placeholders inside the query that can be filled with individual values per query execution. To fill these parameters the tag <tml:param> is used, either inside the <tml:query> tag itself (will be ignored for the query expression) or - preferrably  - somewhere before it inside the same <tml:collection> tag. The following example again queries a "doctype" item, but determines the value to search for from an URL parameter. This is injected to the query  as query parameter "type":

<tml:collection>


  <tml:param name="type"><tml:urlparam name="type"/><tml:param>

  <tml:query type="hql">content.items['doctype'].text=:type</tml:query>


  <tml:foreach>

   ....

  </tml:foreach>


</tml:collection>

There are two ways to sort query results: The first way is to use the sorting capabilities of <tml:foreach> already mentioned in Document collections with the known downsides. The second and more effective way is to use the sorting capabilities of the query language. HQL for example provides a "SORT BY" expression just like SQL. This can be processed on the database server very effectively and when paging is used then OpenWGA does not need to fetch all query results but only the ones displayed. This saves time and resources. The following HQL example sorts the output by the content title in ascending order.

<tml:query type="hql">content.items['doctype'].text=:type ORDER BY content.title ASC</tml:query>