Sorting Search Results
The sorting object (sortBy
) is used to arrange search results based on relevance or specified fields, such as date, name, price, and other custom attributes. A common use case is to enable site visitors to reorder their search results using a "sort" dropdown, typically selecting options like "price low to high".
The sortBy
object includes:
- field: Specifies the catalog column or logic to sort by:
- Catalog column, exactly as named in the product feed (NUMBER, DATE, or STRING).
- Use
popularity
to sort the items by their engagement popularity.
- order: Defines the sorting order:
asc
(ascending) ordesc
(descending).
Example: Sort by arrival date
This example shows how you can override the default sorting by relevance, and instead use the sortby
object to sort according to the dates products were added to the inventory (as tracked in a custom feed column called "arrival_date").
"sortBy": {
"field": "type:date:arrival_date",
"order": "asc"
}
Notes:
- To sort properly, the custom column must be from a supported type. Otherwise it's treated as a string.
- Sorting is available only for Visual Search and Semantic Search.
- Sorting overrides any other relevancy logic.
Updated 12 days ago