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 edge case in term typo calculation.

Kishore Nallana2a21b3f9f5d
diff --git a/src/art.cpp b/src/art.cpp
index 95b1f14b..ca5534f1 100644
--- a/src/art.cpp
+++ b/src/art.cpp
@@ -1261,7 +1261,8 @@ static inline int fuzzy_search_state(const bool prefix, int key_index, bool last
return 1;
}
} else {
- cost = cost_row[key_len];
+ // `key_len` can't exceed `term_len` since length of `cost_row` is `term_len + 1`
+ cost = cost_row[std::min(key_len, term_len)];
}
int bounded_cost = (max_cost == 0) ? max_cost : (max_cost + 1);