---
schema_version: "1"
id: 6b708e0cb6b188e7e3563d158b7085489e5680e35b0ca6e6fb0f4da5ce25709b
title: How Sorting Rules Work
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/cc/264-0-0/b2c_how_sorting_rules_work.md
canonical_url: https://help.salesforce.com/s/articleView?id=cc.b2c_how_sorting_rules_work.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: 60a4ec31d7011edbb37fa877c532b4c7541dcf1aac0afdac84e17d2b640e652b
description: B2C Commerce Sorting rules enable you to control the presentation of search results to the customer. Use sorting rules to bring products to the attention of customers by having them appear at the top of search results. Use any attribute to sort search results or a weighted blend of multiple attributes. To blend multiple attributes, create dynamic attributes.
products:
  - Commerce
  - B2C Commerce
release: "264"
---
# How Sorting Rules Work

B2C Commerce Sorting rules enable you to control the presentation of search results to the customer. Use sorting rules to bring products to the attention of customers by having them appear at the top of search results. Use any attribute to sort search results or a weighted blend of multiple attributes. To blend multiple attributes, create dynamic attributes.

## Order That Rules Apply and Breaking Ties

A sorting rule evaluates all products by the value in the top attribute in the sorting rule list. It breaks any ties in the values of the first attribute using the second attribute, then breaks any ties in the values of the first and second attributes using the values of the third attribute. This continues for all attributes used in sorting.

After all the sorting rules have been evaluated, products that are _tied_ (or matched exactly) on all attributes, or have null values for the sort attributes, are sorted via the default sorting rules. These rules return products based on the search index document order, that is, the order in which the products are stored in the search index. Customers can’t control the index document order, and it can change from one release to another.

![Note](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-cc-b2c_merchandiser_administrator-264-0-0-production-enus/ea76f372-6cfa-42a6-8e7c-05c6df7abed8/images/icon_note.png)

Note

The values used in these examples are simplified.

Example:

This example demonstrates how products are sorted if you set up a sorting rule that first sorts products by Search Placement, allowing a merchant to explicitly define items that they want to appear first. Products are then sorted by lowest return rate. Finally, products are sorted by highest sales velocity. Both of the latter attributes are active data attributes whose values are based on values aggregated in the storefront.

The following tables show how each rule applies to sort products A-F based on their attribute values and the direction:

![BM Sort Attributes](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-cc-b2c_merchandiser_administrator-264-0-0-production-enus/ea76f372-6cfa-42a6-8e7c-05c6df7abed8/cc/b2c_merchandiser_administrator/images/b2c_search_slide_14.gif)

To combine two attributes, rather than sort consecutively with them, this also changes the sorting. The following example shows a myRank dynamic attribute that combines searchRank and categoryPosition with a 50/50 weighting.

![BM Sort Attributes](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-cc-b2c_merchandiser_administrator-264-0-0-production-enus/ea76f372-6cfa-42a6-8e7c-05c6df7abed8/cc/b2c_merchandiser_administrator/images/b2c_search_slide_15.gif)

## Direction

Specify the order in which you want results sorted.

![Note](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-cc-b2c_merchandiser_administrator-264-0-0-production-enus/ea76f372-6cfa-42a6-8e7c-05c6df7abed8/images/icon_note.png)

Note For all data types, items with no value in the field are placed last.

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small ">
        <colgroup>
          <col>
          <col>
          <col>
        </colgroup>
        <thead class="slds-text-title_caps ">
          <tr class="">
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d73696e88">Data Type</th>
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d73696e91">Ascending Sort</th>
            <th scope="col" class="slds-cell-wrap" style="vertical-align:top;" id="d73696e94">Descending Sort</th>
          </tr>
        </thead>
        <tbody>
          <tr class="">
            <td data-label="Data Type" class="slds-cell-wrap" style="vertical-align:top;" headers="d73696e88 ">String</td>

            <td data-label="Ascending Sort" class="slds-cell-wrap" style="vertical-align:top;" headers="d73696e91 ">A-Z</td>

            <td data-label="Descending Sort" class="slds-cell-wrap" style="vertical-align:top;" headers="d73696e94 ">Z-A</td>

          </tr>
          <tr class="">
            <td data-label="Data Type" class="slds-cell-wrap" style="vertical-align:top;" headers="d73696e88 ">Enum of string</td>

            <td data-label="Ascending Sort" class="slds-cell-wrap" style="vertical-align:top;" headers="d73696e91 ">
              <p>Sorts on the value of the attribute, not the display value (1–100, A-Z).
                The sorting for multiple values is undefined.</p>
              <p> In the following example the number is the value and the term in
                parentheses is the display value.</p>
              <p>0010 (Winter)</p>
              <p style="margin-bottom:0;">0040 (Ankle)</p>
            </td>

            <td data-label="Descending Sort" class="slds-cell-wrap" style="vertical-align:top;" headers="d73696e94 ">
              <p>Sorts on the value of the attribute, not the display value. (100-1, Z-A).
                The sorting for multiple values is undefined.</p>
              <p>In the following example the number is the value and the term in
                parentheses is the display value.</p>
              <p>0040 (Ankle)</p>
              <p style="margin-bottom:0;">0010 (Winter)</p>
            </td>

          </tr>
          <tr class="">
            <td data-label="Data Type" class="slds-cell-wrap" style="vertical-align:top;" headers="d73696e88 ">Date + Time</td>

            <td data-label="Ascending Sort" class="slds-cell-wrap" style="vertical-align:top;" headers="d73696e91 ">01/01/2001:12:01a - 12/30/2020: 11:59 p</td>

            <td data-label="Descending Sort" class="slds-cell-wrap" style="vertical-align:top;" headers="d73696e94 ">12/30/2020: 11:59 p - 01/01/2001:12:01a</td>

          </tr>
          <tr class="">
            <td data-label="Data Type" class="slds-cell-wrap" style="vertical-align:top;" headers="d73696e88 ">Boolean</td>

            <td data-label="Ascending Sort" class="slds-cell-wrap" style="vertical-align:top;" headers="d73696e91 ">
              <p>1. products with value 'false' </p>
              <p style="margin-bottom:0;">2. products with value 'true'</p>
            </td>

            <td data-label="Descending Sort" class="slds-cell-wrap" style="vertical-align:top;" headers="d73696e94 ">
              <p>1. products with value 'true' </p>
              <p style="margin-bottom:0;">2. products with value 'false'</p>
            </td>

          </tr>
          <tr class="">
            <td data-label="Data Type" class="slds-cell-wrap" style="vertical-align:top;" headers="d73696e88 ">Integer</td>

            <td data-label="Ascending Sort" class="slds-cell-wrap" style="vertical-align:top;" headers="d73696e91 ">1–100</td>

            <td data-label="Descending Sort" class="slds-cell-wrap" style="vertical-align:top;" headers="d73696e94 ">100-1</td>

          </tr>
          <tr class="">
            <td data-label="Data Type" class="slds-cell-wrap" style="vertical-align:top;" headers="d73696e88 ">Number</td>

            <td data-label="Ascending Sort" class="slds-cell-wrap" style="vertical-align:top;" headers="d73696e91 ">0.01 - 99.99</td>

            <td data-label="Descending Sort" class="slds-cell-wrap" style="vertical-align:top;" headers="d73696e94 ">99.99 -.01</td>

          </tr>
          <tr class="">
            <td data-label="Data Type" class="slds-cell-wrap" style="vertical-align:top;" headers="d73696e88 ">Date</td>

            <td data-label="Ascending Sort" class="slds-cell-wrap" style="vertical-align:top;" headers="d73696e91 ">01/01/2001- 12/30/2020</td>

            <td data-label="Descending Sort" class="slds-cell-wrap" style="vertical-align:top;" headers="d73696e94 ">12/30/2020 - 01/01/2001</td>

          </tr>
          <tr class="">
            <td data-label="Data Type" class="slds-cell-wrap" style="vertical-align:top;" headers="d73696e88 ">Enum of Integer</td>

            <td data-label="Ascending Sort" class="slds-cell-wrap" style="vertical-align:top;" headers="d73696e91 ">1–100</td>

            <td data-label="Descending Sort" class="slds-cell-wrap" style="vertical-align:top;" headers="d73696e94 ">100-1</td>

          </tr>
        </tbody>
      </table>

## Inheritance

If a sorting rule isn't assigned to a category, the category inherits the sorting rule from its parent category. This inheritance goes all the way up to the root of the category structure - the catalog.

- If you assign a sorting rule to the catalog and don't assign a sorting rule to any of its categories, the assigned sorting rule is inherited by all of the categories.
- If you assign a sorting rule to a category within a catalog, it overrides the sorting rule inherited from one of its ancestor categories (parent category or above). Then all of its descendants inherit this assigned sorting rule (subcategories and below). In this way, you can affect large numbers of categories with just a few sorting rule assignments.

For simplicity and best performance, only assign a sorting rule when you want to change the sorting rule that a category and its subcategories inherit. For example, assume that a catalog has top-level categories A, B, C, and D. If you want A and C to have rule 1, B to have rule 2, and D to have rule 3, then it's best to assign rule 1 to the catalog, rule 2 to B, and rule 3 to D. You would have the same results if you assigned rule 1 to A and C, but this is unnecessary.

If a subcategory of B named B1 needs rule 1, then assign rule 1 to that subcategory. This is because even though rule 1 is assigned to the catalog, B1 doesn't inherit rule 1 because rule 2 is assigned to its parent B. The assignment of rule 2 to B changes the rule inherited from the catalog. The assignment of rule 1 to B1 changes the rule inherited from B. This tree shows the sorting rules and their inheritance:

Catalog (rule 1 assigned)

- category A (rule 1 inherited from catalog)
- category B (rule 2 assigned, overrides rule 1 from catalog)
    - category B1 (rule 1 assigned, overrides rule 2 from category B)
- category C (rule 1 inherited from catalog)
- category D (rule 3 assigned, overrides rule 1 from catalog)

## Variation Product Sorting Rules

When sorting base products, the highest or lowest value (depending on sort direction) of all the variation product is used when the base product has no value of its own. The value of the default variation product isn't preferred over others. For sorting rules with active data, the aggregated active data value of the complex product (base product, product set, bundle, and the like) is used for all variation products (which are the represented products).

## Sorting Product Sets

If a product set contains variation products, it's sorted based on the attributes defined in the variation products, unless the product set or the base product defines its own values for these attributes, such as for aggregated active data metrics.

## Multi-Site Sorting Rules

Multi-Site Sorting Rules apply a sorting rule globally across all sites. Instead of having to apply the same sorting rule to each site individually, a multi-site rule can be used. It’s important to note that global sorting rules can only use global dynamic attributes. Setting Sorting Rules or Dynamic Sorting Attributes to Global results in an instance-wide availability of the object (that is, the sorting rule configuration). The actual sorting scores are still site-specific based on-site data.

Change the rule context from individual site to global (and vice versa) in Business Manager or use the Import / Export functionality.

![Note](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-cc-b2c_merchandiser_administrator-264-0-0-production-enus/ea76f372-6cfa-42a6-8e7c-05c6df7abed8/images/icon_note.png)

Note To allow changing the context from “site” to “global”, users must have the `Manage_Global_Sorting_Rules` setting (located by clicking App Launcher ![App Launcher](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-cc-b2c_merchandiser_administrator-264-0-0-production-enus/ea76f372-6cfa-42a6-8e7c-05c6df7abed8/cc/b2c_merchandiser_administrator/images/appLauncher.png), and then selecting **Business Manager** | **Administration** | **Organization** | **Roles & Permissions** | **user** | **Functional Permissions** | **Organization**) set to true.

## Category Sorting Rules

The sorting rule assigned to a storefront catalog's _root_ category is used for category sorting. Sorting rule inheritance makes sure that the root sorting rule is inherited by all subcategories of the catalog, if it's not overwritten on a subcategory level with another sorting rule.

The sorting rule applied to category-based search results is set for the root category of the navigational catalog. You can also select the category position standard attribute for a sorting rule to place specific products in a particular order for a specific category.