React-Instant-Search v7, unable to sort by _geoDistance
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
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?
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".