/
Working with Queries

Working with Queries

Overview

Clients use ddf.catalog.operation.Query objects to describe which metacards are needed from Sources. Query objects have two major components:

  • Filter 
  • Query Options

A Source uses the Filter criteria constraints to find the requested set of metacards within its domain of metacards. The Query Options are used to further restrict the Filter's set of requested metacards. See the Creating Filters section for more on Filters.

Query Options

OptionDescription
StartIndex1-based index that states which metacard the Source should return first out of the requested metacards.
PageSizeRepresents the maximum amount of metacards the Source should return.
SortByDetermines how the results are sorted and on which property.
RequestsTotalResultsCountDetermines whether the total number of results should be returned.
TimeoutMillisThe amount of time in milliseconds before the query is to be abandoned.

Creation

The easiest way to create a Query is to use ddf.catalog.operation.QueryImpl object. It is first necessary to create an OGC Filter object, and then set the Query Options after QueryImpl has been constructed.

 

QueryImpl Example 1
 /*
  Builds a query that requests a total results count and
  that the first record to be returned is the second record found from
  the requested set of metacards.
 */ 
 
 String property = ...;
 
 String value = ...;  
 
 org.geotools.filter.FilterFactoryImpl filterFactory = new FilterFactoryImpl() ;
 
 QueryImpl query = new QueryImpl( filterFactory.equals(filterFactory.property(property), filterFactory.literal(value))) ;
 
 query.setStartIndex(2) ;
 
 query.setRequestsTotalResultsCount(true); 

Evaluation

Every Source must be able to evaluate a Query object. Nevertheless, each Source could evaluate the Query differently depending on what that Source supports as to properties and query capabilities. For instance, a common property all Sources understand is id, but a Source could possibly store frequency values under the property name "frequency." Some Sources may not support frequency property inquiries and will throw an error stating it cannot interpret the property. In addition, some Sources might be able to handle spatial operations, while others might not. A developer should consult a Source's documentation for the limitations, capabilities, and properties that a Source can support.

Additional Reading