mirror of
https://github.com/typesense/typesense.git
synced 2025-05-18 12:42:50 +08:00
Reduce false positives when considering trailing typos.
This commit is contained in:
parent
2e3bbca1b8
commit
1b46165423
@ -1318,7 +1318,7 @@ static inline int fuzzy_search_state(const bool prefix, int key_index, bool last
|
||||
|
||||
// used to match q=strawberries on key=strawberry, but limit to larger keys to prevent eager matches
|
||||
if(key_len > 5 && term_len > key_len && (term_len - key_len) <= max_cost &&
|
||||
cost >= min_cost && cost <= max_cost) {
|
||||
cost >= min_cost-1 && cost <= max_cost-1) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -622,17 +622,33 @@ TEST(ArtTest, test_art_fuzzy_search_single_leaf_prefix) {
|
||||
EXPECT_EQ(1, posting_t::first_id(l->values));
|
||||
|
||||
std::vector<art_leaf*> leaves;
|
||||
art_fuzzy_search(&t, (const unsigned char *) "aplication", strlen(key)-1, 0, 1, 10, FREQUENCY, true, nullptr, 0, leaves);
|
||||
std::string term = "aplication";
|
||||
art_fuzzy_search(&t, (const unsigned char *)(term.c_str()), term.size(), 0, 1, 10, FREQUENCY, true, nullptr, 0, leaves);
|
||||
ASSERT_EQ(1, leaves.size());
|
||||
|
||||
leaves.clear();
|
||||
art_fuzzy_search(&t, (const unsigned char *) "aplication", strlen(key)-1, 0, 2, 10, FREQUENCY, true, nullptr, 0, leaves);
|
||||
art_fuzzy_search(&t, (const unsigned char *)(term.c_str()), term.size(), 0, 2, 10, FREQUENCY, true, nullptr, 0, leaves);
|
||||
ASSERT_EQ(1, leaves.size());
|
||||
|
||||
res = art_tree_destroy(&t);
|
||||
ASSERT_TRUE(res == 0);
|
||||
}
|
||||
|
||||
TEST(ArtTest, test_art_fuzzy_search_single_leaf_qlen_greater_than_key) {
|
||||
art_tree t;
|
||||
int res = art_tree_init(&t);
|
||||
ASSERT_TRUE(res == 0);
|
||||
|
||||
const char* key = "storka";
|
||||
art_document doc = get_document((uint32_t) 1);
|
||||
ASSERT_TRUE(NULL == art_insert(&t, (unsigned char*)key, strlen(key)+1, &doc));
|
||||
|
||||
std::string term = "starkbin";
|
||||
std::vector<art_leaf*> leaves;
|
||||
art_fuzzy_search(&t, (const unsigned char *)(term.c_str()), term.size(), 0, 2, 10, FREQUENCY, true, nullptr, 0, leaves);
|
||||
ASSERT_EQ(0, leaves.size());
|
||||
}
|
||||
|
||||
TEST(ArtTest, test_art_fuzzy_search_single_leaf_non_prefix) {
|
||||
art_tree t;
|
||||
int res = art_tree_init(&t);
|
||||
@ -811,7 +827,7 @@ TEST(ArtTest, test_art_fuzzy_search) {
|
||||
|
||||
leaves.clear();
|
||||
art_fuzzy_search(&t, (const unsigned char *) "antisocao", strlen("antisocao"), 0, 2, 10, FREQUENCY, true, nullptr, 0, leaves);
|
||||
ASSERT_EQ(9, leaves.size());
|
||||
ASSERT_EQ(6, leaves.size());
|
||||
|
||||
long long int timeMillis = std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
std::chrono::high_resolution_clock::now() - begin).count();
|
||||
|
Loading…
x
Reference in New Issue
Block a user