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

Don't initialize leaf_to_indices map for single token queries.

Kishore Nallan645355067af3
diff --git a/src/collection.cpp b/src/collection.cpp
index d23f72d8..a555ec5c 100644
--- a/src/collection.cpp
+++ b/src/collection.cpp
@@ -451,10 +451,13 @@ void Collection::score_results(Topster<100> &topster, const int & token_rank,
const int max_token_rank = 250;
spp::sparse_hash_map<art_leaf*, uint32_t*> leaf_to_indices;
- for (art_leaf *token_leaf : query_suggestion) {
- uint32_t *indices = new uint32_t[result_size];
- token_leaf->values->ids.indexOf(result_ids, result_size, indices);
- leaf_to_indices.emplace(token_leaf, indices);
+ if(query_suggestion.size() != 1) {
+ // won't be needing positional ranking when there is only 1 token in the query
+ for (art_leaf *token_leaf : query_suggestion) {
+ uint32_t *indices = new uint32_t[result_size];
+ token_leaf->values->ids.indexOf(result_ids, result_size, indices);
+ leaf_to_indices.emplace(token_leaf, indices);
+ }
}
for(auto i=0; i<result_size; i++) {