meilisearch-js-plugins icon indicating copy to clipboard operation
meilisearch-js-plugins copied to clipboard

React-Instant-Search v7, unable to sort by _geoDistance

Open dbargaud opened this issue 6 months ago • 2 comments

Hi,

has anyone succeed to use the _geoDistance sorting with the InstantMeiliSearch and ReactInstantSearch v7 ?

This is not a server issue since I can do it with Postman without any problem. (tried on MeiliSearch v1.15.2 and v1.13)

Can someone give a working example ?

Thank you all for your help and the great work!

David

dbargaud avatar Jun 16 '25 15:06 dbargaud

Hi @dbargaud can you send here more information about your setup (your index config) and a minimal reproduction use case of the issue you're facing?

brunoocasali avatar Jun 19 '25 21:06 brunoocasali

If you are using the useSortBy hook or the component you will face many limitations. The way I made sorting much more workable is to set the indexUiState myself.

Example:

const { setIndexUiState, scopedResults } = useInstantSearch();

const applySort = (sort: string | null) => {
  setIndexUiState((prev) => ({
    ...prev,
    sortBy: !sort ? `` : `${scopedResults[0].indexId}:${sort}`
  }));
};

This lets you send any type of sorting rule through instantsearch, you do however have to register the useSortBy hook somewhere so that sorting is "enabled".

Fronix avatar Sep 12 '25 07:09 Fronix