Treat zero facet sample percent as not sampled.

This commit is contained in:
Kishore Nallan 2024-02-14 12:29:48 +05:30
parent 420c55ee6d
commit cc980c2ecd
2 changed files with 18 additions and 1 deletions

View File

@ -1368,6 +1368,10 @@ void Index::do_facets(std::vector<facet> & facets, facet_query_t & facet_query,
auto sort_index_it = sort_index.find(a_facet.field_name);
auto facet_sort_index_it = sort_index.find(a_facet.sort_field);
if(facet_sample_percent == 0) {
facet_sample_percent = 1;
}
size_t mod_value = 100 / facet_sample_percent;
auto num_facet_values = facet_index_v4->get_facet_count(facet_field.name);
@ -3612,7 +3616,8 @@ Option<bool> Index::search(std::vector<query_tokens_t>& field_query_tokens, cons
delete [] exclude_token_ids;
delete [] excluded_result_ids;
bool estimate_facets = (facet_sample_percent < 100 && all_result_ids_len > facet_sample_threshold);
bool estimate_facets = (facet_sample_percent > 0 && facet_sample_percent < 100 &&
all_result_ids_len > facet_sample_threshold);
bool is_wildcard_no_filter_query = is_wildcard_non_phrase_query && no_filters_provided;
if(!facets.empty()) {

View File

@ -1999,6 +1999,18 @@ TEST_F(CollectionFacetingTest, SampleFacetCounts) {
ASSERT_FALSE(res["facet_counts"][0]["sampled"].get<bool>());
// facet sample percent zero is treated as not sampled
res = coll1->search("*", {}, "", {"color"}, {}, {0}, 3, 1, FREQUENCY, {true}, 5,
spp::sparse_hash_set<std::string>(),
spp::sparse_hash_set<std::string>(), 10, "", 30, 4, "", 20, {}, {}, {}, 0,
"<mark>", "</mark>", {}, 1000, true, false, true, "", false, 6000 * 1000, 4, 7, fallback,
4, {off}, 3, 3, 2, 2, false, "", true, 0, max_score, 0, 10).get();
ASSERT_EQ(1000, res["found"].get<size_t>());
ASSERT_EQ(1, res["facet_counts"].size());
ASSERT_EQ(2, res["facet_counts"][0]["counts"].size());
ASSERT_FALSE(res["facet_counts"][0]["sampled"].get<bool>());
// test for sample percent > 100
auto res_op = coll1->search("*", {}, "", {"color"}, {}, {0}, 3, 1, FREQUENCY, {true}, 5,