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

Treat token hits as a rank slot instead of a weight.

kishorenc2061d0462914
diff --git a/src/index.cpp b/src/index.cpp
index ff345a7f..aaf42ee6 100644
--- a/src/index.cpp
+++ b/src/index.cpp
@@ -1501,7 +1501,7 @@ void Index::search(Option<uint32_t> & outcome,
existing_field_kvs.emplace(kv->field_id, kv);
}
- int64_t aggregated_score = 0;
+ uint64_t aggregated_score = 0;
uint32_t token_bits = (uint32_t(1) << 31); // top most bit set to guarantee atleast 1 bit set
//LOG(INFO) << "Init pop count: " << __builtin_popcount(token_bits);
@@ -1575,12 +1575,11 @@ void Index::search(Option<uint32_t> & outcome,
}
}
- //LOG(INFO) << "seq id: " << seq_id << ", pop count: " << __builtin_popcount(token_bits);
+ aggregated_score |= (uint64_t(__builtin_popcount(token_bits)) << 48);
- //aggregated_score *= std::max(1, __builtin_popcount(field_id));
- aggregated_score *= __builtin_popcount(token_bits);
+ /*LOG(INFO) << "seq id: " << seq_id << ", pop count: " << __builtin_popcount(token_bits)
+ << ", aggregated_score: " << aggregated_score;*/
- //LOG(INFO) << "kvs[0].key: " << kvs[0]->key;
kvs[0]->scores[kvs[0]->match_score_index] = aggregated_score;
topster->add(kvs[0]);
}
diff --git a/test/collection_test.cpp b/test/collection_test.cpp
index c12d3298..eae963d1 100644
--- a/test/collection_test.cpp
+++ b/test/collection_test.cpp
@@ -2704,8 +2704,8 @@ TEST_F(CollectionTest, MultiFieldRelevance2) {
spp::sparse_hash_set<std::string>(), 10, "", 30, 4, "", 40, {}, {}, {}, 0,
"<mark>", "</mark>", {1, 4}).get();
- ASSERT_STREQ("0", results["hits"][0]["document"]["id"].get<std::string>().c_str());
- ASSERT_STREQ("1", results["hits"][1]["document"]["id"].get<std::string>().c_str());
+ ASSERT_STREQ("1", results["hits"][0]["document"]["id"].get<std::string>().c_str());
+ ASSERT_STREQ("0", results["hits"][1]["document"]["id"].get<std::string>().c_str());
collectionManager.drop_collection("coll1");
}