#community-help

Resolving 'stores_count' field sorting issue in Schema

TLDR em1nos encountered an issue sorting the 'stores_count' field, which was due to a field disparity in multiple collections. Upon resolving that, a subsequent issue with instant search internally managing sorting came up, which Jason addressed by releasing an updated version of the adapter.

Powered by Struct AI

3

2

41
28mo
Solved
Join the chat
Jul 11, 2021 (28 months ago)
em1nos
Photo of md5-f33ae8b829901656b655c985c894be3a
em1nos
10:05 AM
I'm getting: Could not find a field named stores_count in the schema for sorting Do I need to set facet: true for sorting to work on that field?
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
10:05 AM
No, sorting should be enabled for all numerical fields automatically. Can you please post your schema?
10:06
Kishore Nallan
10:06 AM
As long as it is defined in the schema.
em1nos
Photo of md5-f33ae8b829901656b655c985c894be3a
em1nos
10:07 AM
10:09
em1nos
10:09 AM
10:09
em1nos
10:09 AM
oh wait, it should be defined in an array maybe?
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
10:10 AM
How does it look on the document being indexed?
em1nos
Photo of md5-f33ae8b829901656b655c985c894be3a
em1nos
10:12 AM
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
10:13 AM
:thinking_face:
em1nos
Photo of md5-f33ae8b829901656b655c985c894be3a
em1nos
10:14 AM
OH wait! I'm sorry. I'm searching in multiple collections!
10:14
em1nos
10:14 AM
and the other collection doesn't have that field. DOH!
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
10:14 AM
🙂 Okay
em1nos
Photo of md5-f33ae8b829901656b655c985c894be3a
em1nos
10:14 AM
I need to use collectionSpecificSearchParameters

1

10:23
em1nos
10:23 AM
hmm, now the error is gone, but the sorting doesn't work, it's not sent with the request. I'm using the InstantSearch adapter (with Vue)
10:23
em1nos
10:23 AM
10:24
em1nos
10:24 AM
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
10:26 AM
Should sortBy be an array?
10:27
Kishore Nallan
10:27 AM
Can you try: sortBy: ['stores_count:desc']
10:29
Kishore Nallan
10:29 AM
If that doesn't work, Jason will be able to help when he is around later.
em1nos
Photo of md5-f33ae8b829901656b655c985c894be3a
em1nos
10:30 AM
yea, it didn't work. ok, thank you! you have a fantastic product! 🙂

2

Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
03:26 PM
em1nos Are you looking to allow the user to sort, or will this be a fixed sort order?
em1nos
Photo of md5-f33ae8b829901656b655c985c894be3a
em1nos
03:28 PM
well, i had the sort widget, but removed it thinking it was causing the issues .. but yes, I would like the end user to be able to sort .. I'm trying to set the default now
03:29
em1nos
03:29 PM
it seems the collectionSpecificSearchParameters doesn't work at all
03:30
em1nos
03:30 PM
03:31
em1nos
03:31 PM
sorry, the above is not true
03:32
em1nos
03:32 PM
1 sec...
03:33
em1nos
03:33 PM
it just seems the "sort_by" is always an empty string
03:33
em1nos
03:33 PM
I don't know if I'm missing something, somewhere where I'm setting the sorting that's interfering with this
03:34
em1nos
03:34 PM
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
03:34 PM
Sorting is managed by instant search internally, you want to use the sort by widget this way: https://github.com/typesense/typesense-instantsearch-adapter#sortby
03:36
Jason
03:36 PM
In Algolia, you’d create duplicate indices for each sort order, but in Typesense you can have multiple sort orders on the fly with one index. So you’d need to configure the sort by widget in a specific way to make it work with Typesense
em1nos
Photo of md5-f33ae8b829901656b655c985c894be3a
em1nos
03:36 PM
ok, so setting a default sortBy in collectionSpecificSearchParameters will not work?
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
03:37 PM
Correct. You can set a default sort order using the sort by widget
em1nos
Photo of md5-f33ae8b829901656b655c985c894be3a
em1nos
03:37 PM
I see. OK. Thank you. I will try that! :)
03:38
em1nos
03:38 PM
but, what if I don't use the sorting widget? (I don't in the site-wide multi collection search/autocomplete)
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
03:40 PM
I was just going to say, if you don’t want a user visible widget, then I think I need to add support for it for collectionSpecific search params. Looking at the code it currently only works for additional search parameters…
03:40
Jason
03:40 PM
I’ll do this later today
em1nos
Photo of md5-f33ae8b829901656b655c985c894be3a
em1nos
03:40 PM
sweet! 🙂
03:40
em1nos
03:40 PM
thank you so much

1

Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
06:14 PM
em1nos I've published a new version of the adapter that supports sortBy in collection specific parameters: https://www.npmjs.com/package/typesense-instantsearch-adapter/v/2.0.0-1
em1nos
Photo of md5-f33ae8b829901656b655c985c894be3a
em1nos
06:48 PM
works! thank you!

1