Algolia Instant search default order by state (`live`, 'published', 'draft')

430 Views Asked by At

I'm trying to fetch Algolia results in particular order, hits have state column, and state values can be live/published/draft

Data in algolia

{ name: Post1, state: draft},
{ name: Post2, state: published},
{ name: Post3, state: live}

Expected Result

Default order should be, first live then published and then show draft

{ name: Post3, state: live},
{ name: Post2, state: published},
{ name: Post1, state: draft}
1

There are 1 best solutions below

0
On

Algolia doesn't support sorting by an enumerated type like this. Instead, in search, it is more common to use the state as a facet and allow users to filter results based on the enumerated value.

You could simulate the enumerated sort by performing a multi-index query with three separate queries to the same index with each of the state values as a filter, then display the results for each state.