Sorting query results

To sort the results of your Broker query, add an object that implements the SortParameter interface to your query object, using the addSorting (JSP) or AddSorting (ASP.NET) method.

The SortParameter constructor takes two parameters: an object that implements SortColumn, specifying the column to sort on, and a SortDirection object specifying how to sort (one of the static values ASCENDING or DESCENDING).

The SortColumn can be any of the predefined static metadata fields defined in the SortParameter class, such as ItemTitle in the sample above.

ASP.NET example: sorting your query results by title

The following ASP.NET fragment shows how to sort your query results by title, ascending:

SortParameter sortParameter = new SortParameter(SortParameter.ItemTitle, SortParameter.Ascending);
MyQuery.AddSorting(sortParameter);

JSP example: sorting on a custom metadata field

You can also sort on a custom metadata field that you yourself added by creating a new object of the class CustomMetaKeyColumn, which implements SortColumn. The constructor for CustomMetaKeyColumn has two parameters: a string containing the name of the custom metadata field to sort on, and an object of type MetadataType (a static value) that specifies the type of data contained in this field.

The following JSP sample shows how to sort your query results, descending, on a custom metadata field called "editorial date", which is a date:

customMetaKeyColumn = new CustomMetaKeyColumn("editorial date", MetadataType.DATE)
query.addSorting(new SortParameter(customMetaKeyColumn, SortParameter.DESCENDING);