#community-help

Typesense Facet Sorting When Counts Are Equal

TLDR Pedro inquired about sorting facets when counts are the same. Kishore Nallan explained it uses internal ID and directed to an existing GitHub issue discussing alphabetical ordering.

Powered by Struct AI
10
4mo
Solved
Join the chat
May 17, 2023 (4 months ago)
Pedro
Photo of md5-bd44cb242a5d1f68403cb16f3d167c4c
Pedro
09:46 AM
Hello, the question I have is, when we have a facet, for example brand, and we have HP, Logitech Creators and TP-Link.
HP has 20, Logitech Creators has 17 and TP-Link has 17. When I make a search and display the facet Brand, the order of the list is HP, then Logitech Creators or TP-Link. Because Logitech Creators and TP-Link have the same count.

What I want to understand is how does typesense decide which brand should come first in the list, in case they have the same count. And if there is a way to change that order.
Thank you.
Image 1 for Hello, the question I have is, when we have a facet, for example brand, and we have HP, Logitech Creators and TP-Link.
HP has 20, Logitech Creators has 17 and TP-Link has 17. When I make a search and display the facet Brand, the order of the list is HP, then Logitech Creators or TP-Link. Because Logitech Creators and TP-Link have the same count.

What I want to understand is how does typesense decide which brand should come first in the list, in case they have the same count. And if there is a way to change that order.
Thank you.
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
10:35 AM
The order is fixed so it won't alternate between page loads but there's no way to change the other of facet values when their count is same.
10:35
Kishore Nallan
10:35 AM
The order uses an internal ID which will guarantee a stable sort order when counts are same but no way to tweak that further.
May 18, 2023 (4 months ago)
Pedro
Photo of md5-bd44cb242a5d1f68403cb16f3d167c4c
Pedro
09:39 AM
Kishore Nallan Thank You. Is there any plans for future versions, to make it so we can edit the order of the facet list?
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
09:44 AM
How do you want to order it?
Pedro
Photo of md5-bd44cb242a5d1f68403cb16f3d167c4c
Pedro
03:00 PM
I want to order alphabetically.
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
03:06 PM
Yes, we want to support this. Can you please create an issue on Github for tracking. I will keep you posted on that.
May 19, 2023 (4 months ago)
Pedro
Photo of md5-bd44cb242a5d1f68403cb16f3d167c4c
Pedro
09:06 AM
I noticed there is an open issue about ordering facets alphabetically. https://github.com/typesense/typesense/issues/521 Can we keep track on this issue?
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
09:07 AM
Yes let's use that. Thanks.
Pedro
Photo of md5-bd44cb242a5d1f68403cb16f3d167c4c
Pedro
09:31 AM
Ok. Thanks