meilisearch-rust: Sorting order is not correct

When querying the database with this SDK, the sorting order is different than using the Rest API:

Index

{
	"uid": "users",
	"primaryKey": "user_id"
}

Settings

{
	"displayedAttributes":["user_id"],
	"rankingRules": [
		"d_karma:desc",
		"typo",
		"proximity",
		"attribute",
		"sort",
		"exactness",
		"words"
	],
	"searchableAttributes": [
		"username",
		"bio"
	],
	"typoTolerance": {
		"minWordSizeForTypos": {
			"oneTypo": 3,
			"twoTypos": 6
		}
	},
	"pagination": {
		"maxTotalHits": 50
	}
}

Documents through Rest Api Url: http://127.0.0.1:7700/indexes/users/search POST request Body:

{
	"q": "piet"
}

Result:

{
	"hits": [
		{
			"user_id": "a0bacccc-b2a7-4c91-83f9-8dbf2ea42e8d"
		},
		{
			"user_id": "ec5a4e56-bf1a-44e3-aeee-91b28c25eb30"
		},
		{
			"user_id": "858a3a83-af26-48f4-b735-4987f4e2bc19"
		}
	],
	"estimatedTotalHits": 3,
	"query": "piet",
	"limit": 20,
	"offset": 0,
	"processingTimeMs": 0
}

Documents through Rust SDK Code:

Query::new(&self.index)
    .with_query("piet")
    .execute()
    .await;

Result:

[
    SearchResult {
        result: SearchResultUser {
            user_id: a0baccccb2a74c9183f98dbf2ea42e8d,
        },
        formatted_result: None,
        matches_position: None,
    },
    SearchResult {
        result: SearchResultUser {
            user_id: 858a3a83af2648f4b7354987f4e2bc19,
        },
        formatted_result: None,
        matches_position: None,
    },
    SearchResult {
        result: SearchResultUser {
            user_id: ec5a4e56bf1a44e3aeee91b28c25eb30,
        },
        formatted_result: None,
        matches_position: None,
    },
]

Problem Last two user_id’s are swapped

Raw documents

{
	"results": [
		{
			"username": "6RzDxughVD",
			"bio": "",
			"user_id": "b9fcf6fc-fee1-4e63-8461-72310e175035",
			"d_karma": 0
		},
		{
			"username": "pietjepietnm",
			"bio": "",
			"user_id": "858a3a83-af26-48f4-b735-4987f4e2bc19",
			"d_karma": 5
		},
		{
			"username": "pietpietpiet",
			"bio": "",
			"user_id": "a0bacccc-b2a7-4c91-83f9-8dbf2ea42e8d",
			"d_karma": 12
		},
		{
			"username": "pietpiethenk",
			"bio": "",
			"user_id": "ec5a4e56-bf1a-44e3-aeee-91b28c25eb30",
			"d_karma": 10
		}
	],
	"offset": 0,
	"limit": 20,
	"total": 4
}

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 25 (25 by maintainers)

Most upvoted comments

I am glad to hear that it appears to be resolved! And don’t worry about wasting our time. It is always better to report bugs and you clearly put effort into it, which I really appreciate 🙂

So I tried debugging it one more time in a new project, then it worked. I cleared my cargo dir and docker cache of the main project to force downloading the newest versions of both projects, than it also worked over there 😦. It looks like I wasted a lot of people’s time including my own, sorry 😔

Hey @Jasperav,

I want a fresh eye to look at this issue, like @ManyTheFish or @loiclec, as you worked on the sort ranking rule. For context, this user is experiencing strange behavior with the d_karma:desc ranking rule but only when using the Rust SDK, not when doing the same call using cURL. Do you have an idea? Could it be related to the ranking rule? I am not able to reproduce that on my side

In the meantime, we are releasing the v0.30.1 this week, I advise you to switch to this version when it is ready 😃

Oops, sorry, I totally forgot to answer.

Personally, from what I understand the issue comes down to the preserve_order feature of serde_json. That ensures your JSON Value will stay ordered according to how you received it over the network.

And I don’t think it’s in the scope of this crate to enable this feature. You should check how the feature unification works in rust but basically, to do a quick tldr: We can’t enable it only for meilisearch-rust. Thus, if we enable it’ll be enabled for all your workspace and the other crate using serde_json. Since the features slow down the deserialization a little bit and are typically not needed, I don’t think it’s a good idea to ship it by default.

EDIT: Ooops yeah sorry I totally misunderstood the issue ignore me 🙈

Hey @Jasperav Sorry I left on hollidays! I’ll have to investigate and try to reproduce locally. I’ll keep you updated here 😃