mirror of
https://github.com/typesense/typesense.git
synced 2025-05-22 06:40:30 +08:00
Merge pull request #1339 from krunal1313/value_facet_int64_stats_fix
fix for int64 facet stats
This commit is contained in:
commit
561ba5240f
@ -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 {
|
||||
|
@ -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");
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user