Merge pull request #1339 from krunal1313/value_facet_int64_stats_fix

fix for int64 facet stats
This commit is contained in:
Kishore Nallan 2023-10-26 20:38:15 +05:30 committed by GitHub
commit 561ba5240f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 2 deletions

View File

@ -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 {

View File

@ -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");
}