Docs
Guides
Sorting

Sorting

Sorting options for the search results.

API: Example

search_settings: {
  // ...
  sorting: {
    default: {
      field: '_score',
      order: 'desc'
    },
    _price_desc: {
      field: 'price',
      order: 'desc'
    },
    _price_asc: {
      field: 'price',
      order: 'asc'
    }
  }
}

Frontend: Example

Using the sorting options in frontend can be achieved with the sortBy component widget.

In the example below, the indexName is mrp-products_sk and the sorting options are _price_desc, _price_asc. The relevance option will use the default sorting option in the API.

<SortBy defaultRefinement='mrp-products_sk' items={[
  { value: 'mrp-products_sk', label: 'Relevance' },
  { value: 'mrp-products_sk_price_asc', label: 'Cheapest' },
  { value: 'mrp-products_sk_price_desc', label: 'Most Expensive' },
]} />