#community-help

Sorting Issue in Typesense Schema

TLDR Keith had issues sorting by the field 'year' after changing its type to a string. Jason clarified that Typesense currently only supports numeric sorting and offered a workaround.

Powered by Struct AI

1

13
23mo
Solved
Join the chat
Dec 17, 2021 (23 months ago)
Keith
Photo of md5-49c23d5dc46241ca1af5233658633765
Keith
05:01 PM
Jason I had a facet field that was an init, everything was fine, but I changed it to be a string but now I’m getting an error of Error: 404 - Could not find a field named year in the schema for sorting. The field itself is optional, which it was before, does there always have to have a value though to be set in
additionalSearchParameters: {
    queryBy: "title,barcode",
    sortBy: "_text_match:desc,year:desc",
}
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
05:14 PM
Keith Typesense currently only supports sorting by numeric fields, the error message needs to be improved there
05:14
Jason
05:14 PM
We plan to tackle sorting by strings in the next few weeks (mid to late Jan)

1

Keith
Photo of md5-49c23d5dc46241ca1af5233658633765
Keith
05:15 PM
Um so why does _textmatch:desc work?
05:15
Keith
05:15 PM
Or is that the relevancy score?
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
05:16 PM
That’s a numeric relevancy score
05:16
Jason
05:16 PM
Keith
Photo of md5-49c23d5dc46241ca1af5233658633765
Keith
05:19 PM
Awesome, I’ll give that a try!
05:26
Keith
05:26 PM
Actually, that doesn’t make a whole lot of sense to be tbh
05:28
Keith
05:28 PM
Ohhh they just added two fields?
05:32
Keith
05:32 PM
My problem that I’m trying to solve that for my year field specifically, I have some instances where it could be “2021/22”
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
05:34 PM
Yup
Keith
Photo of md5-49c23d5dc46241ca1af5233658633765
Keith
05:59 PM
That’s what I just did for now if anyone is asking