Hi. I have a question regarding sorting. I have re...
# community-help
i
Hi. I have a question regarding sorting. I have referenced https://typesense.org/docs/guide/ranking-and-relevance.html#text-match-score but would like to clarify some behaviour I observe. A subset of my data appears as follows (NB - when seeding these are added to the index in the order listed below):
Copy code
icd10,description
E78.1,Pure hyperglyceridaemia
E78.2,Mixed hyperlipidaemia
E78.3,Hyperchylomicronaemia
and my index is as follows:
Copy code
{
    'name': 'diagnosis',
    'fields': [
        {'name': 'id', 'type': 'string'},  # maps to icd10
        {'name': 'code', 'type': 'string'},  # maps to icd10
        {'name': 'description', 'type': 'string'},  # maps to description
    ]
}
Running a query
E78
I get the results in reverse order (E78.3, followed by E78.2 and E78.1) If I seed the data in reverse order than I get the results in the correct order. I would just like to understand this behaviour better, and how order of insertion affects sorting (and if its fine to rely on this for my use case since the data wont change).
k
👋 When you query
E78
all matching documents have the same text match score, so to break the tie, we sort on their internal document ID, which is an increasing sequential ID.
i
Is this sort by internal sequential ID descending or ascending?
k
Descending, you can rely on this behavior.
i
Awesome - thanks!
k
Welcome.