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
fix for int64 facet stats
krunalc5e218c5b11e
diff --git a/src/index.cpp b/src/index.cppindex f15b289a..c171ede0 100644--- a/src/index.cpp+++ b/src/index.cpp@@ -1374,8 +1374,13 @@ void Index::do_facets(std::vector<facet> & facets, facet_query_t & facet_query,if(numerical_index_it != numerical_index.end()) {auto min_max_pair = numerical_index_it->second->get_min_max(result_ids,results_size);- a_facet.stats.fvmin = int64_t_to_float(min_max_pair.first);- a_facet.stats.fvmax = int64_t_to_float(min_max_pair.second);+ if(facet_field.is_float()) {+ a_facet.stats.fvmin = int64_t_to_float(min_max_pair.first);+ a_facet.stats.fvmax = int64_t_to_float(min_max_pair.second);+ } else {+ a_facet.stats.fvmin = min_max_pair.first;+ a_facet.stats.fvmax = min_max_pair.second;+ }}}} else {diff --git a/test/collection_optimized_faceting_test.cpp b/test/collection_optimized_faceting_test.cppindex 95a80eec..5e5acc2b 100644--- a/test/collection_optimized_faceting_test.cpp+++ b/test/collection_optimized_faceting_test.cpp@@ -486,6 +486,26 @@ TEST_F(CollectionOptimizedFacetingTest, FacetCounts) {ASSERT_FALSE(res_op.ok());ASSERT_STREQ("Facet query refers to a facet field `name_facet` that is not part of `facet_by` parameter.", res_op.error().c_str());+ //facet query on int64 field with stats+ results = coll_array_fields->search("*", query_fields, "", {"timestamps"}, sort_fields, {0}, 10, 1, FREQUENCY,+ {false}, Index::DROP_TOKENS_THRESHOLD,+ spp::sparse_hash_set<std::string>(),+ spp::sparse_hash_set<std::string>(), 10, "timestamps: 142189002").get();+ ASSERT_EQ(5, results["hits"].size());+ ASSERT_EQ(1, results["facet_counts"].size());+ ASSERT_EQ(1, results["facet_counts"][0]["counts"].size());+ ASSERT_STREQ("timestamps", results["facet_counts"][0]["field_name"].get<std::string>().c_str());+ ASSERT_EQ(2, (int) results["facet_counts"][0]["counts"][0]["count"]);+ ASSERT_STREQ("1421890022", results["facet_counts"][0]["counts"][0]["value"].get<std::string>().c_str());+ ASSERT_STREQ("<mark>142189002</mark>2", results["facet_counts"][0]["counts"][0]["highlighted"].get<std::string>().c_str());++ ASSERT_EQ(5, results["facet_counts"][0]["stats"].size());+ ASSERT_FLOAT_EQ(1106321222, results["facet_counts"][0]["stats"]["avg"].get<double>());+ ASSERT_FLOAT_EQ(348974822, results["facet_counts"][0]["stats"]["min"].get<double>());+ ASSERT_FLOAT_EQ(1453426022, results["facet_counts"][0]["stats"]["max"].get<double>());+ ASSERT_FLOAT_EQ(13275854664, results["facet_counts"][0]["stats"]["sum"].get<double>());+ ASSERT_FLOAT_EQ(1, results["facet_counts"][0]["stats"]["total_values"].get<size_t>());+collectionManager.drop_collection("coll_array_fields");}