according to the docs sort_by can have upto 2 fiel...
# community-help
r
according to the docs sort_by can have upto 2 field for sorting but it doesn't seems to work. just to confirm both of the data type are int64. and both field work when only single sort is provided. what could be the reason ?
j
Could you share the exact curl command / code snippet and the output?
r
https://example.com/typesense/collections/job/documents/search?per_page=15&query_by=jobTitle &page=1&q=&sort_by=jobDeadlineasc,projectCreationTimedesc&filter_by=
this is the url, both sort data are unix timestamp
j
The query seems fine... May I know what error you get from Typesense when you run it?
r
I'm not getting any error, it's just the data is not sorted
it sort the data when used only 1 field
this is sample 50 records
of this query domain/search?per_page=50&page=1&q=&sort_by=jobDeadlineasc,projectCreationTimedesc&query_by=jobTitle&include_fields=jobDeadline,projectCreationTime,id
j
May I know which records seem off to you in ordering?
r
in this json you can se 1st and 2nd record
here jobDeadline is in right order ie. asc as sent in query
but projectCreationTime is not in desc
j
I eye-balled the first few and it seems like they're all ordered by
jobDeadline:asc
. I don't see any overlapping jobDeadline values for the
projectCreationTime:desc
to kick-in though
r
jobDeadline is sorted but projectCreationTimes doesn't seems working.
j
Essentially, when multiple sort fields are used, the data is sorted by the first field, then if the first field has the same value across records, then the 2nd field is used to sort within those. This is very similar to how sorting multiple columns in a spreadsheet would work for eg
r
you mean after 1st sort, if it founds same value in multiple record then 2rd fielf of sort will trigger
something like that
j
Correct
r
okay, is there any way we can sort multiple field like i described
meilisearch also doesn't support this. initially i though typesense do support this feature
but typesense is way better than meilisearch
😀 2
j
is there any way we can sort multiple field like i described
No, but I'm trying to visualize how this would work. For every record, there needs to be a single value to know which ordered position to put it in, right?
Could you give me an example of say three records with some sample data for these two fields, and how you'd sort them in the way you've described?
r
ok
j
meilisearch also doesn't support this. initially i though typesense do support this feature
I don't think so either. But if you're referring to the comparison chart, what Meilisearch & Algolia do not support that Typesense supports, is support for dynamic sorting, as part of the search parameters. With Meilisearch & Algolia, you have to define the sort order upfront. With Typesense, you can sort on any integer fields on the fly at search time.
r
right. I spent 4-5 day in meilisearch before discovering typesense
[ { "document": { "id": "5bdb10bca52ece560e8a8a17", "projectCreationTime": 10, "jobDeadline": 50 } }, { "document": { "id": "5bdb1278a52ece560e8a8a26", "projectCreationTime": 15, "jobDeadline": 40 } }, { "document": { "id": "5bdb1235a52ece560e8a8a1c", "projectCreationTime": 20, "jobDeadline": 22 } }]
for eg. here projectCreationTime is in asc and jobDeadline is in dsc
j
How about this example. Let's say the unsorted dataset is this:
Copy code
[{
    "document": {
        "id": "5bdb10bca52ece560e8a8a17",
        "jobDeadline": 10,
        "projectCreationTime": 1
    },
},
{
    "document": {
        "id": "5bdb1278a52ece560e8a8a26",
        "jobDeadline": 6,
        "projectCreationTime": 5
    },
},
{
    "document": {
        "id": "5bdb1235a52ece560e8a8a1c",
        "jobDeadline": 9,
        "projectCreationTime": 3
    },
}]
How would you sort by
jobDeadline:asc,projectCreationTime:desc
in the way you've described.
If you were to do it by hand...
r
maybe i think i'm overthinking. ideally what i'm thinking is not doable.
j
ideally what i'm thinking is not doable.
I think so too, not just in Typesense - but in general, with sorting as a concept. But I'm trying to see if I'm missing something obvious or the possibility of a new feature 🙂
r
let me think of myself and i'll come up with a good example.
👍 1