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

simplifying test case

krunal1313c5d06cd271d4
diff --git a/test/collection_grouping_test.cpp b/test/collection_grouping_test.cpp
index b53a58a6..85039f9f 100644
--- a/test/collection_grouping_test.cpp
+++ b/test/collection_grouping_test.cpp
@@ -663,107 +663,126 @@ TEST_F(CollectionGroupingTest, SortingMoreThanMaxTopsterSize) {
coll3 = collectionManager.create_collection("coll3", 4, fields, "rating").get();
}
- for(int i = 0; i < 300; ++i) {
- nlohmann::json doc;
- doc["title"] = "Omega Casual Poplin Shirt";
- doc["brand"] = "Omega";
- doc["size"] = 10 * i;
- doc["colors"] = "blue";
- doc["rating"] = 4.5;
-
- ASSERT_TRUE(coll3->add(doc.dump()).ok());
-
- nlohmann::json doc2;
- doc2["title"] = "Beta Casual Poplin Shirt";
- doc2["brand"] = "Beta";
- doc2["size"] = 15 * i;
- doc2["colors"] = "white";
- doc2["rating"] = 4.3;
-
- ASSERT_TRUE(coll3->add(doc2.dump()).ok());
-
- nlohmann::json doc3;
- doc3["title"] = "Zeta Casual Poplin Shirt";
- doc3["brand"] = "Zeta";
- doc3["size"] = 20 * i;
- doc3["colors"] = "red";
- doc3["rating"] = 4.6;
-
- ASSERT_TRUE(coll3->add(doc3.dump()).ok());
+ for(auto i = 0; i < 150; i++) {
+ auto group_id = i;
+ for(auto j = 0; j < 4; j++) {
+ nlohmann::json doc;
+ doc["title"] = "Omega Casual Poplin Shirt";
+ doc["brand"] = "Omega";
+ doc["size"] = group_id;
+ doc["colors"] = "blue";
+ doc["rating"] = 4.5;
+
+ ASSERT_TRUE(coll3->add(doc.dump()).ok());
+ }
+ }
+
+ for(auto i = 150; i < 250; i++) {
+ auto group_id = i;
+ for(auto j = 0; j < 3; j++) {
+ nlohmann::json doc;
+ doc["title"] = "Beta Casual Poplin Shirt";
+ doc["brand"] = "Beta";
+ doc["size"] = group_id;
+ doc["colors"] = "white";
+ doc["rating"] = 4.3;
+
+ ASSERT_TRUE(coll3->add(doc.dump()).ok());
+ }
+ }
+
+ for(auto i = 250; i < 300; i++) {
+ auto group_id = i;
+ for(auto j = 0; j < 2; j++) {
+ nlohmann::json doc;
+ doc["title"] = "Zeta Casual Poplin Shirt";
+ doc["brand"] = "Zeta";
+ doc["size"] = group_id;
+ doc["colors"] = "red";
+ doc["rating"] = 4.6;
+
+ ASSERT_TRUE(coll3->add(doc.dump()).ok());
+ }
}
//first search in desc order
std::vector<sort_by> sort_fields = {sort_by("_group_count", "DESC")};
- auto res = coll3->search("*", {}, "", {"brand"}, sort_fields, {0}, 50, 5, FREQUENCY,
+ auto res = coll3->search("*", {}, "", {"brand"}, sort_fields, {0}, 100, 2, FREQUENCY,
{false}, Index::DROP_TOKENS_THRESHOLD,
spp::sparse_hash_set<std::string>(),
spp::sparse_hash_set<std::string>(), 10, "", 30, 5,
"", 10,
{}, {}, {"size"}, 2).get();
- ASSERT_EQ(625, res["found"].get<size_t>());
- ASSERT_EQ(50, res["grouped_hits"].size());
+ ASSERT_EQ(300, res["found"].get<size_t>());
+ ASSERT_EQ(100, res["grouped_hits"].size());
+
+ ASSERT_EQ(4, res["grouped_hits"][4]["found"].get<int32_t>());
+
+ ASSERT_EQ(4, res["grouped_hits"][4]["found"].get<int32_t>());
+
+ ASSERT_EQ(3, res["grouped_hits"][50]["found"].get<int32_t>());
+
+ ASSERT_EQ(3, res["grouped_hits"][99]["found"].get<int32_t>());
- ASSERT_STREQ("150", res["grouped_hits"][0]["hits"][0]["document"]["id"].get<std::string>().c_str());
- ASSERT_EQ(2, res["grouped_hits"][0]["found"].get<int32_t>());
- ASSERT_STREQ("138", res["grouped_hits"][1]["hits"][0]["document"]["id"].get<std::string>().c_str());
- ASSERT_EQ(2, res["grouped_hits"][1]["found"].get<int32_t>());
+ res = coll3->search("*", {}, "", {"brand"}, sort_fields, {0}, 100, 3, FREQUENCY,
+ {false}, Index::DROP_TOKENS_THRESHOLD,
+ spp::sparse_hash_set<std::string>(),
+ spp::sparse_hash_set<std::string>(), 10, "", 30, 5,
+ "", 10,
+ {}, {}, {"size"}, 2).get();
- ASSERT_STREQ("867", res["grouped_hits"][48]["hits"][0]["document"]["id"].get<std::string>().c_str());
- ASSERT_EQ(1, res["grouped_hits"][48]["found"].get<int32_t>());
+ ASSERT_EQ(300, res["found"].get<size_t>());
+ ASSERT_EQ(100, res["grouped_hits"].size());
- ASSERT_STREQ("866", res["grouped_hits"][49]["hits"][0]["document"]["id"].get<std::string>().c_str());
- ASSERT_EQ(1, res["grouped_hits"][49]["found"].get<int32_t>());
+ ASSERT_EQ(3, res["grouped_hits"][4]["found"].get<int32_t>());
+
+ ASSERT_EQ(3, res["grouped_hits"][4]["found"].get<int32_t>());
+
+ ASSERT_EQ(2, res["grouped_hits"][50]["found"].get<int32_t>());
+
+ ASSERT_EQ(2, res["grouped_hits"][99]["found"].get<int32_t>());
//search in asc order
std::vector<sort_by> sort_fields2 = {sort_by("_group_count", "ASC")};
- auto res2 = coll3->search("*", {}, "", {"brand"}, sort_fields2, {0}, 50, 5, FREQUENCY,
+ auto res2 = coll3->search("*", {}, "", {"brand"}, sort_fields2, {0}, 100, 1, FREQUENCY,
{false}, Index::DROP_TOKENS_THRESHOLD,
spp::sparse_hash_set<std::string>(),
spp::sparse_hash_set<std::string>(), 10, "", 30, 5,
"", 10,
{}, {}, {"size"}, 2).get();
- ASSERT_EQ(625, res2["found"].get<size_t>());
- ASSERT_EQ(50, res2["grouped_hits"].size());
+ ASSERT_EQ(300, res2["found"].get<size_t>());
+ ASSERT_EQ(100, res2["grouped_hits"].size());
- ASSERT_STREQ("599", res2["grouped_hits"][0]["hits"][0]["document"]["id"].get<std::string>().c_str());
- ASSERT_EQ(1, res2["grouped_hits"][0]["found"].get<int32_t>());
+ ASSERT_EQ(2, res2["grouped_hits"][0]["found"].get<int32_t>());
- ASSERT_STREQ("598", res2["grouped_hits"][1]["hits"][0]["document"]["id"].get<std::string>().c_str());
- ASSERT_EQ(1, res2["grouped_hits"][1]["found"].get<int32_t>());
+ ASSERT_EQ(2, res2["grouped_hits"][1]["found"].get<int32_t>());
- ASSERT_STREQ("503", res2["grouped_hits"][48]["hits"][0]["document"]["id"].get<std::string>().c_str());
- ASSERT_EQ(1, res2["grouped_hits"][48]["found"].get<int32_t>());
+ ASSERT_EQ(3, res2["grouped_hits"][50]["found"].get<int32_t>());
- ASSERT_STREQ("502", res2["grouped_hits"][49]["hits"][0]["document"]["id"].get<std::string>().c_str());
- ASSERT_EQ(1, res2["grouped_hits"][49]["found"].get<int32_t>());
+ ASSERT_EQ(3, res2["grouped_hits"][99]["found"].get<int32_t>());
- // default search without any sort order
- auto res3 = coll3->search("*", {}, "", {"brand"}, {}, {0}, 50, 5, FREQUENCY,
+ res2 = coll3->search("*", {}, "", {"brand"}, sort_fields2, {0}, 100, 2, FREQUENCY,
{false}, Index::DROP_TOKENS_THRESHOLD,
spp::sparse_hash_set<std::string>(),
spp::sparse_hash_set<std::string>(), 10, "", 30, 5,
"", 10,
{}, {}, {"size"}, 2).get();
- ASSERT_EQ(625, res3["found"].get<size_t>());
- ASSERT_EQ(50, res3["grouped_hits"].size());
+ ASSERT_EQ(300, res2["found"].get<size_t>());
+ ASSERT_EQ(100, res2["grouped_hits"].size());
- ASSERT_STREQ("299", res3["grouped_hits"][0]["hits"][0]["document"]["id"].get<std::string>().c_str());
- ASSERT_EQ(3, res3["grouped_hits"][0]["found"].get<int32_t>());
+ ASSERT_EQ(3, res2["grouped_hits"][0]["found"].get<int32_t>());
- ASSERT_STREQ("296", res3["grouped_hits"][1]["hits"][0]["document"]["id"].get<std::string>().c_str());
- ASSERT_EQ(2, res3["grouped_hits"][1]["found"].get<int32_t>());
+ ASSERT_EQ(3, res2["grouped_hits"][1]["found"].get<int32_t>());
- ASSERT_STREQ("155", res3["grouped_hits"][48]["hits"][0]["document"]["id"].get<std::string>().c_str());
- ASSERT_EQ(3, res3["grouped_hits"][48]["found"].get<int32_t>());
+ ASSERT_EQ(4, res2["grouped_hits"][50]["found"].get<int32_t>());
- ASSERT_STREQ("152", res3["grouped_hits"][49]["hits"][0]["document"]["id"].get<std::string>().c_str());
- ASSERT_EQ(2, res3["grouped_hits"][49]["found"].get<int32_t>());
+ ASSERT_EQ(4, res2["grouped_hits"][99]["found"].get<int32_t>());
}
\ No newline at end of file