Guides / Managing results / Refine results / Sorting results

Using replicas with different sorting strategies allows you to provide a way for users to change the sorting on the front end. For example, imagine you have an e-commerce website, and by default, you want to sort search results from cheapest to most expensive. You might want to provide a dropdown or toggle switch to let users sort from most expensive to cheapest.

Because you have one replica index per sorting strategy, you need to change what index Algolia must search into when the user changes the sorting.

While you could handle it yourself, we recommend you use one of our InstantSearch libraries and leverage the built-in sortBy widget.

Setting up Replicas

Before you implement the search, you need to have replicas for each sorting strategy you want to provide.

Using the sortBy widget

Dropdowns are a familiar widget, common in e-commerce scenarios and power user workflows. InstantSearch provides sorting dropdowns via the sortBy widget.

1
2
3
4
5
6
7
8
9
search.addWidgets([
  instantsearch.widgets.sortBy({
    container: '#sort-by-container',
    items: [
      { value: 'products', label: 'Most relevant' },
      { value: 'products_price_desc', label: 'Highest price' }
    ]
  })
]);

Did you find this page helpful?