From 456f6c449ac9ab28471ca7f93dd15b787357bf5d Mon Sep 17 00:00:00 2001 From: Harpreet Sangar Date: Mon, 18 Dec 2023 10:27:07 +0530 Subject: [PATCH] Add test case for filter scoring. --- test/collection_sorting_test.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/collection_sorting_test.cpp b/test/collection_sorting_test.cpp index deb6ad4f..f6143c53 100644 --- a/test/collection_sorting_test.cpp +++ b/test/collection_sorting_test.cpp @@ -2082,6 +2082,20 @@ TEST_F(CollectionSortingTest, OptionalFilteringViaSortingWildcard) { ASSERT_EQ(expected_ids[i], results["hits"][i]["document"]["id"].get()); } + // Score associated with the first match is assigned to the document. + sort_fields = { + sort_by({"brand:nike", "brand:adidas", "points: 1"}, {3, 2, 5}, "DESC"), + sort_by("points", "DESC"), + }; + + results = coll1->search("*", {"title"}, "", {}, sort_fields, {2}, 10, 1, FREQUENCY, {true}, 10).get(); + ASSERT_EQ(6, results["hits"].size()); + + expected_ids = {"3", "0", "4", "2", "1", "5"}; + for(size_t i = 0; i < expected_ids.size(); i++) { + ASSERT_EQ(expected_ids[i], results["hits"][i]["document"]["id"].get()); + } + // bad syntax for eval query sort_fields = { sort_by({"brandnike || points:0"}, {1}, "DESC"),