# Sorting

The **Sort** rule defines the order in which products are displayed once the base set (after filtering) has been defined. It determines which products are prioritized first within the recommendation list.

#### How it works

Each sorting rule is composed of:

| Element      | Description                                                                                                             |
| ------------ | ----------------------------------------------------------------------------------------------------------------------- |
| **Property** | The product attribute used to rank products (e.g., `price`, `stock`, `rating`, `booster_search_low`, `category`, etc.). |
| **Order**    | The direction of the sort: **Ascending** (lowest to highest) or **Descending** (highest to lowest).                     |

Multiple sorting criteria can be combined to refine the order of results. The system applies them sequentially, from top to bottom.

Example:

1. Sort by `booster_search_low` (Descending)
2. Then by `item_pageview_key` (Descending)

The platform will first sort by the main criterion, then use the second one only to rank products with identical values in the first criterion.

#### Adding multiple sorts

You can add as many sorting levels as necessary using the <kbd>**Add a sort**</kbd> button.\
Each new sorting condition is applied in sequence after the previous one.

For example:

* **Primary sort:** `booster_search_low` (Descending)
* **Secondary sort:** `price` (Ascending)
* **Tertiary sort:** `rating` (Descending)

This allows fine-tuned ranking logic, balancing relevance, performance, and commercial priorities.

#### Properties available for sorting

The available properties depend on the product dataset connected to the catalog. Common examples include:

| Property                 | Description                                                        | Typical Use                            |
| ------------------------ | ------------------------------------------------------------------ | -------------------------------------- |
| **price**                | Product price                                                      | Show cheapest or most expensive first  |
| **stock**                | Available stock quantity                                           | Prioritize in-stock items              |
| **rating**               | Average customer rating                                            | Highlight top-rated products           |
| **booster\_search\_low** | Internal ranking variable used for semantic or search-based boosts | Optimize by algorithmic relevance      |
| **item\_pageview\_key**  | Product view frequency                                             | Promote most-viewed products           |
| **category**             | Product category                                                   | Group or sort within a specific type   |
| **active**               | Availability flag (true/false)                                     | Prioritize active or sellable products |

#### Combining filters and sorts

Sorting rules can be combined with **filters** to further refine product selection.\
For instance:

* **Filter:** `stock > 0`
* **Sort:** `price Ascending`, then `rating Descending`

This approach ensures only valid products are considered and ranked according to defined priorities.

#### Example use cases

* Sort by popularity and display top-performing items: `item_pageview_key Descending`
* Rank by price to create a “Low to High” experience: `price Ascending`
* Prioritize stock availability for operational efficiency: `stock Descending`
* Combine algorithmic scoring with merchandising logic: `booster_search_low Descending`, then `price Ascending`


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.abtasty.com/recommendations-and-merchandising/concepts/strategies/rules/custom-rules/sorting.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
