Oracle ATG Web Commerce Search returns a list of result groups in its query response. Normally, the result groups are sorted in relevance order, but you may want to allow users to sort the final results by some secondary criteria, such as date. This secondary sort does not affect what results are in the result groups, just the order of the returned groups.

Note: Secondary sorting work on result groups, not on individual search results, so it is affected by responseNumberSettings parameters such as perProp. See that section for detailed parameter information.

Secondary sorting is performed before paging, and is controlled by the following attributes:

<query docSort="mode" docSortOrder="order" docSortProp="prop"
dcSortPropDefault="def" docSortPropVal="val" docSortPred="predicate"
docSortCase="bool"

The mode value specifies how the index items will be sorted, and can be one of the following:

  • relevance—The default value, return items in relevance order, assuming the item set is a category

  • alpha—Sort index items by filename (such as index.htm)

  • address—Sort index items by the beginning of the full URL (for example, http://www.oracle.com)

  • url—Sort index items by full URL

  • date —Sort index items by last modified date

  • strprop —Sort index item by a metadata string property, requires docSortProp attribute

  • numprop —Sort index items by a metadata number property, requires docSortProp attribute

  • title —Sort index items by title

  • type —Sort index items by the type, such as HTML or PDF

  • docset—Sort index items by physical document set

  • index—Leave index items unsorted, in index order

  • predicate – Sort groups by combination of the modes specified in the docSortPred attribute (see below).

The order value determines whether the sort is ascending or descending, either alphabetically or numerically, depending on the sort mode. The order value can be either ascending or descending.

The prop value specifies the property name to use for the strprop or numprop modes. The property name must be a valid property of the given type; for example, for strprop, either string or enum, and for numprop, either integer, float, boolean or date. Index items that don’t have this property will be excluded from the sort. To prevent that, the def value can specify the default property value to use for these exceptional cases. The def value should agree with the type of the property.

When grouping by property, it is common to have multiple values for a property within an item as well as across a group. The val value controls which value of the result group’s properties to use. The val can be one of the following values:

  • first—The first value of the first item in the group is used.

  • last—The last value of the last item in the group is used.

  • high—The highest (greatest) value of the property from any of the items in the group.

  • low—The lowest (smallest) value of the property from any of the items in the group.

The default is first. As an example, if the items should be sorted by the lowest price and there are multiple price values per item or the items are grouped by some property, the low value for docSortPropVal should be used.

The predicate value specifies a sequence of sorting modes and orders to apply when mode="predicate", forming a complex sort criterion. The value has the following form:

docSort="predicate" docSortPred="mode:order:prop:def:bool|…"

The five colon-delimited fields correspond to the five docSort attribute values. Note that for modes other than strprop and numprop, the prop and def fields are irrelevant and can be omitted. The order value should specify the logical precedence of the mode, that is, how the results would be placed in order by that individual mode. The bool represents the docSortCase value.

The overall sort order is controlled using the docSortOrder attribute. For example:

docSortPred="numprop:descending:popularity:0|numprop:ascending:cost"
docSortOrder="ascending"

In this example, search results are first sorted descending by popularity, then ascending by cost (for results where popularity is the same).

The docSortCase attribute determines whether any string secondary sorting is case-sensitive (true) or not (false). This attribute affects the docSort mode values of strprop, alpha, url, address, and title. The sort predicate specifies its case-sensitivity within its fielded format.