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
C++ algoliadatastoreelasticsearchenterprise-searchfacetingfull-text-searchfuzzy-searchgeosearchin-memoryinstantsearchmerchandisingpineconesearchsearch-enginesemantic-searchsimilarity-searchsite-searchsynonymstypo-tolerancevector-search
test for float value truncation
krunalc601b006a822
diff --git a/test/collection_faceting_test.cpp b/test/collection_faceting_test.cppindex 3126b047..f0f92ac1 100644--- a/test/collection_faceting_test.cpp+++ b/test/collection_faceting_test.cpp@@ -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"] = 9.37;+ ASSERT_TRUE(coll1->add(doc.dump()).ok());++ doc["movie"] = "The Godfather";+ doc["rating"] = 9.20;+ ASSERT_TRUE(coll1->add(doc.dump()).ok());++ doc["movie"] = "The Dark Knight";+ doc["rating"] = 9.0;+ ASSERT_TRUE(coll1->add(doc.dump()).ok());++ doc["movie"] = "Inception";+ doc["rating"] = 8.87;+ ASSERT_TRUE(coll1->add(doc.dump()).ok());++ doc["movie"] = "Pulp Fiction";+ doc["rating"] = 8.92;+ ASSERT_TRUE(coll1->add(doc.dump()).ok());++ doc["movie"] = "Good Will Hunting";+ doc["rating"] = 8.33;+ 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("9", results["facet_counts"][0]["counts"][0]["value"].get<std::string>());+ ASSERT_EQ("9.2", results["facet_counts"][0]["counts"][1]["value"].get<std::string>());+ ASSERT_EQ("9.37", results["facet_counts"][0]["counts"][2]["value"].get<std::string>());++ //with filter+ results = coll1->search("*", {}, "rating: >8.5", {"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("9", results["facet_counts"][0]["counts"][0]["value"].get<std::string>());+ ASSERT_EQ("9.2", results["facet_counts"][0]["counts"][1]["value"].get<std::string>());+ ASSERT_EQ("8.92", results["facet_counts"][0]["counts"][2]["value"].get<std::string>());+ ASSERT_EQ("8.87", results["facet_counts"][0]["counts"][3]["value"].get<std::string>());+ ASSERT_EQ("9.37", results["facet_counts"][0]["counts"][4]["value"].get<std::string>());++ //with filter and group+ results = coll1->search("*", {}, "rating: >9", {"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("9.2", results["facet_counts"][0]["counts"][0]["value"].get<std::string>());+ ASSERT_EQ("9.37", results["facet_counts"][0]["counts"][1]["value"].get<std::string>());}\ No newline at end of file