respect num of groups when typo_tokens_threshold is applied (#1574)

* respect num of groups when typo_tokens_threshold is applied

* update changes after merge
This commit is contained in:
Krunal Gandhi 2024-02-26 10:26:08 +00:00 committed by GitHub
parent 6e24c06e35
commit 7762f2d080
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 28 additions and 1 deletions

View File

@ -4151,7 +4151,8 @@ Option<bool> Index::fuzzy_search_fields(const std::vector<search_field_t>& the_f
resume_typo_loop:
if(!exhaustive_search && all_result_ids_len >= typo_tokens_threshold) {
auto results_count = group_limit != 0 ? groups_processed.size() : all_result_ids_len;
if(!exhaustive_search && results_count >= typo_tokens_threshold) {
// if typo threshold is breached, we are done
return Option<bool>(true);
}

View File

@ -159,6 +159,32 @@ TEST_F(CollectionGroupingTest, GroupingBasics) {
"", 10,
{}, {}, {"foo*"}, 2).error();
ASSERT_EQ("Pattern `foo*` is not allowed.", error);
// typo_tokens_threshold should respect num_groups
res = coll_group->search("beta", {"brand"}, "", {"brand"}, {}, {2}, 50, 1, FREQUENCY,
{false}, Index::DROP_TOKENS_THRESHOLD,
spp::sparse_hash_set<std::string>(),
spp::sparse_hash_set<std::string>(), 10, "", 30, 5,
"", 2,
{}, {}, {"brand"}, 1).get();
ASSERT_EQ(4, res["found_docs"].get<size_t>());
ASSERT_EQ(2, res["found"].get<size_t>());
ASSERT_EQ(2, res["grouped_hits"].size());
ASSERT_EQ("Beta", res["grouped_hits"][0]["group_key"][0]);
ASSERT_EQ("Zeta", res["grouped_hits"][1]["group_key"][0]);
res = coll_group->search("beta", {"brand"}, "", {"brand"}, {}, {2}, 50, 1, FREQUENCY,
{false}, Index::DROP_TOKENS_THRESHOLD,
spp::sparse_hash_set<std::string>(),
spp::sparse_hash_set<std::string>(), 10, "", 30, 5,
"", 1,
{}, {}, {"brand"}, 1).get();
ASSERT_EQ(3, res["found_docs"].get<size_t>());
ASSERT_EQ(1, res["found"].get<size_t>());
ASSERT_EQ(1, res["grouped_hits"].size());
ASSERT_EQ("Beta", res["grouped_hits"][0]["group_key"][0]);
}
TEST_F(CollectionGroupingTest, GroupingCompoundKey) {