Skip to content

Open Source alternative to Algolia + Pinecone and an Easier-to-Use alternative to ElasticSearch ⚡ 🔍 ✨ Fast, typo tolerant, in-memory fuzzy Search Engine for building delightful search experiences

Fix another edge case involving early end of term.

Kishore Nallan619a3972d8d4
diff --git a/src/art.c b/src/art.c
index ce6686f3..c57500b4 100644
--- a/src/art.c
+++ b/src/art.c
@@ -1087,19 +1087,24 @@ static int art_iter_fuzzy_prefix_recurse(art_node *n, const unsigned char *term,
printf("!child_char: %c, depth: %d", child_char, depth);
art_node* child = ((art_node4*)n)->children[i];
- int current_row[term_len+1];
- current_row[0] = previous_row[0] + 1;
+ int new_current_row[term_len+1];
+ new_current_row[0] = previous_row[0] + 1;
- row_min = levenshtein_score(child_char, term, term_len, previous_row, current_row);
+ row_min = levenshtein_score(child_char, term, term_len, previous_row, new_current_row);
int new_depth = (child_char != 0) ? depth+1 : depth;
- if(depth == term_len) {
- if(current_row[term_len] <= max_cost) {
+ printf("child cost: %d, depth: %d, term_len: %d \n", new_current_row[term_len], depth, term_len);
+
+ if(new_depth == term_len) {
+ // if reach end of term, and cost is below threshold, print children of this node as matches
+ if(new_current_row[term_len] <= max_cost) {
return recursive_iter(n, cb, NULL);
}
return 0;
}
- if(row_min <= max_cost) art_iter_fuzzy_prefix_recurse(child, term, term_len, max_cost, new_depth, current_row, cb, data);
+ if(row_min <= max_cost) {
+ art_iter_fuzzy_prefix_recurse(child, term, term_len, max_cost, new_depth, new_current_row, cb, data);
+ }
}
break;
diff --git a/src/main.cpp b/src/main.cpp
index a1782980..a7945631 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -30,7 +30,7 @@ int main() {
num++;
}
- const unsigned char *prefix = (const unsigned char *) "shawshanku";
+ const unsigned char *prefix = (const unsigned char *) "catm";
art_iter_fuzzy_prefix(&t, prefix, strlen((const char *) prefix), 2, test_prefix_cb, NULL);
// art_iter_prefix(&t, prefix, strlen((const char *) prefix), test_prefix_cb, NULL);