diff --git a/src/index.cpp b/src/index.cpp index 75a38ffd..e20e422e 100644 --- a/src/index.cpp +++ b/src/index.cpp @@ -4151,7 +4151,8 @@ Option Index::fuzzy_search_fields(const std::vector& 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(true); } diff --git a/test/collection_grouping_test.cpp b/test/collection_grouping_test.cpp index d518f89b..693ebda8 100644 --- a/test/collection_grouping_test.cpp +++ b/test/collection_grouping_test.cpp @@ -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(), + spp::sparse_hash_set(), 10, "", 30, 5, + "", 2, + {}, {}, {"brand"}, 1).get(); + + ASSERT_EQ(4, res["found_docs"].get()); + ASSERT_EQ(2, res["found"].get()); + 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(), + spp::sparse_hash_set(), 10, "", 30, 5, + "", 1, + {}, {}, {"brand"}, 1).get(); + + ASSERT_EQ(3, res["found_docs"].get()); + ASSERT_EQ(1, res["found"].get()); + ASSERT_EQ(1, res["grouped_hits"].size()); + ASSERT_EQ("Beta", res["grouped_hits"][0]["group_key"][0]); } TEST_F(CollectionGroupingTest, GroupingCompoundKey) {