Skip to content

Open Source alternative to Algolia + Pinecone and an Easier-to-Use alternative to ElasticSearch ⚡ 🔍 ✨ Fast, typo tolerant, in-memory fuzzy Search Engine for building delightful search experiences

Add `_eval` sorting test case.

Harpreet Sangar7e765e30fb3e
diff --git a/test/collection_sorting_test.cpp b/test/collection_sorting_test.cpp
index f6143c53..40882e38 100644
--- a/test/collection_sorting_test.cpp
+++ b/test/collection_sorting_test.cpp
@@ -1988,7 +1988,7 @@ TEST_F(CollectionSortingTest, OptionalFilteringViaSortingWildcard) {
"name": "coll1",
"fields": [
{"name": "title", "type": "string" },
- {"name": "brand", "type": "string" },
+ {"name": "brand", "type": "string", "infix": true },
{"name": "points", "type": "int32" }
]
}
@@ -2121,6 +2121,24 @@ TEST_F(CollectionSortingTest, OptionalFilteringViaSortingWildcard) {
ASSERT_FALSE(search_op.ok());
ASSERT_EQ("The eval expression in sort_by is empty.", search_op.error());
+ req_params = {
+ {"collection", "coll1"},
+ {"q", "a"},
+ {"query_by", "brand"},
+ {"sort_by", "_eval(brand:puma):desc, _text_match:desc"},
+ {"infix", "always"}
+ };
+
+ search_op = collectionManager.do_search(req_params, embedded_params, json_res, now_ts);
+ ASSERT_TRUE(search_op.ok());
+ results = nlohmann::json::parse(json_res);
+
+ ASSERT_EQ(4, results["hits"].size()); // 3 Adidas 1 Puma documents
+ expected_ids = {"5", "4", "2", "1"};
+ for(size_t i = 0; i < expected_ids.size(); i++) {
+ ASSERT_EQ(expected_ids[i], results["hits"][i]["document"]["id"].get<std::string>());
+ }
+
// more bad syntax!
sort_fields = {
sort_by(")", "DESC"),