#community-help

Typesense Sorting Query and Bug Report

TLDR michtio is new to Typesense and is querying sorting implementation. Jason shares resources and suggests use of specific adapters. However, michtio shares a bug found when applying a filter on Typesense. Jason asks for a GitHub issue to be opened for the bug.

Powered by Struct AI
Jun 20, 2022 (16 months ago)
michtio
Photo of md5-68e2637c7df7044e63075bd8ec098420
michtio
01:33 PM
Hey all, working with the new Typesense 0.23.0 and typesense algolia migration for the first time in general.
Is there any specific documentation on how to handle sorting, since we don’t need to use index replicas for those?
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
01:38 PM
Here's how to sort in Typesense: https://typesense.org/docs/0.23.0/api/documents.html#sort-results

You can use a single index to sort on multiple fields
michtio
Photo of md5-68e2637c7df7044e63075bd8ec098420
michtio
01:39 PM
Yes that we have Jason, but mainly wondering on how to implement on the Front-end
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
01:39 PM
If you're using instantsearch, here's how to use it with the Typesense instantsearch adapter: https://github.com/typesense/typesense-instantsearch-adapter#sortby
michtio
Photo of md5-68e2637c7df7044e63075bd8ec098420
michtio
01:40 PM
Seems like that is with a widget, we’re not using any widgets 😅 only the instantsearch_client. Heh
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
01:41 PM
Could you share your current sorting client-side code with Algolia?
michtio
Photo of md5-68e2637c7df7044e63075bd8ec098420
michtio
01:41 PM
Sure I can DM
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
01:41 PM
Did you mean Algolia client btw or instantsearch client? Because instantsearch only has the concept of widgets, either built-in ones or custom ones you build
01:47
Jason
01:47 PM
Looks like you are using Algolia client. The Typesense-instantsearch-adapter is only meant to be used with instantsearch.

So in your case you would have to use typesense-js directly to make API calls to Typesense
michtio
Photo of md5-68e2637c7df7044e63075bd8ec098420
michtio
01:52 PM
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
02:38 PM
That's right
02:44
Jason
02:44 PM
michtio After you pointed this out, I looked at the source code for instantsearch, and it looks like instantsearch does use the algoliasearch-helper library under the hood. So I suspect it might be possible to get it to work with the typesense-instantsearch-adapter with some tweaks. Did you run into any particular issues with the code snippet you shared? We can try debugging from there
Jun 21, 2022 (16 months ago)
michtio
Photo of md5-68e2637c7df7044e63075bd8ec098420
michtio
07:16 AM
Hey Jason after playing around with the sort doesn’t work with the helper library ( at least not how it is intended to be used with Typesense ) when parsing/adding the object that contains the search, it does nothing.

On that note I also found a (possible) bug, using filter_by:>2 did return all the results higher than 2, but also higher than -2 ( so we had a -3 int value in the results )
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
01:18 PM
michtio The adapter does handle sorting transformations: https://github.com/typesense/typesense-instantsearch-adapter#sortby

re: bug, could you open a Github issue with a reproducible code snippet with a few sample docs, along with the Typesense version?