Merge pull request #1442 from krunal1313/float_value_truncation

test for float value truncation
This commit is contained in:
Kishore Nallan 2023-12-20 15:52:12 +05:30 committed by GitHub
commit f8805ecd7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2047,4 +2047,71 @@ TEST_F(CollectionFacetingTest, RangeFacetTestWithGroupBy) {
ASSERT_EQ(4.5, results["grouped_hits"][1]["group_key"][0]);
collectionManager.drop_collection("coll1");
}
TEST_F(CollectionFacetingTest, FloatValueTruncation) {
std::vector<field> fields = {field("movie", field_types::STRING, true),
field("rating", field_types::FLOAT, true),};
Collection *coll1 = collectionManager.create_collection(
"coll1", 1, fields, "", 0, "", {}, {}).get();
nlohmann::json doc;
doc["movie"] = "The Shawshank Redemption";
doc["rating"] = 93.7;
ASSERT_TRUE(coll1->add(doc.dump()).ok());
doc["movie"] = "The Godfather";
doc["rating"] = 92.0;
ASSERT_TRUE(coll1->add(doc.dump()).ok());
doc["movie"] = "The Dark Knight";
doc["rating"] = 90;
ASSERT_TRUE(coll1->add(doc.dump()).ok());
doc["movie"] = "Inception";
doc["rating"] = 88.7;
ASSERT_TRUE(coll1->add(doc.dump()).ok());
doc["movie"] = "Pulp Fiction";
doc["rating"] = 89.2;
ASSERT_TRUE(coll1->add(doc.dump()).ok());
doc["movie"] = "Good Will Hunting";
doc["rating"] = 83.3;
ASSERT_TRUE(coll1->add(doc.dump()).ok());
auto results = coll1->search("The", {"movie"}, "", {"rating"}, sort_fields, {0}, 10, 1,
FREQUENCY, {false}, 10, spp::sparse_hash_set<std::string>(),
spp::sparse_hash_set<std::string>()).get();
ASSERT_EQ(3, results["hits"].size());
ASSERT_EQ(3, results["facet_counts"][0]["counts"].size());
ASSERT_EQ("90", results["facet_counts"][0]["counts"][0]["value"].get<std::string>());
ASSERT_EQ("92", results["facet_counts"][0]["counts"][1]["value"].get<std::string>());
ASSERT_EQ("93.7", results["facet_counts"][0]["counts"][2]["value"].get<std::string>());
//with filter
results = coll1->search("*", {}, "rating: >85", {"rating"}, sort_fields, {0}, 10, 1,
FREQUENCY, {false}, 10, spp::sparse_hash_set<std::string>(),
spp::sparse_hash_set<std::string>()).get();
ASSERT_EQ(5, results["hits"].size());
ASSERT_EQ(5, results["facet_counts"][0]["counts"].size());
ASSERT_EQ("90", results["facet_counts"][0]["counts"][0]["value"].get<std::string>());
ASSERT_EQ("92", results["facet_counts"][0]["counts"][1]["value"].get<std::string>());
ASSERT_EQ("88.7", results["facet_counts"][0]["counts"][2]["value"].get<std::string>());
ASSERT_EQ("89.2", results["facet_counts"][0]["counts"][3]["value"].get<std::string>());
ASSERT_EQ("93.7", results["facet_counts"][0]["counts"][4]["value"].get<std::string>());
//with filter and group
results = coll1->search("*", {}, "rating: >90", {"rating"}, sort_fields, {0}, 10, 1,
FREQUENCY, {false}, 10, spp::sparse_hash_set<std::string>(),
spp::sparse_hash_set<std::string>(), 10, "",
30, 4, "", 10, {},
{}, {"rating"}).get();
ASSERT_EQ(2, results["grouped_hits"].size());
ASSERT_EQ(2, results["facet_counts"][0]["counts"].size());
ASSERT_EQ("92", results["facet_counts"][0]["counts"][0]["value"].get<std::string>());
ASSERT_EQ("93.7", results["facet_counts"][0]["counts"][1]["value"].get<std::string>());
}