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

Early exit for exact match calculation based on distance.

Kishore Nallanb18e2a41b374
diff --git a/include/match_score.h b/include/match_score.h
index 803a55ba..7f9e6874 100644
--- a/include/match_score.h
+++ b/include/match_score.h
@@ -218,6 +218,12 @@ struct Match {
exact_match = 0;
if(check_exact_match) {
+
+ if(distance != token_offsets.size()-1) {
+ // we can exit early and don't have to care about other requirements
+ return;
+ }
+
int last_token_index = -1;
size_t total_offsets = 0;
@@ -232,8 +238,7 @@ struct Match {
}
}
- if(last_token_index == int(token_offsets.size())-1 &&
- total_offsets == token_offsets.size() && distance == token_offsets.size()-1) {
+ if(last_token_index == int(token_offsets.size())-1 && total_offsets == token_offsets.size()) {
exact_match = 1;
}
}