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

Stable sort does not require key comparison.

Kishore Nallanda263b69ea21
diff --git a/include/topster.h b/include/topster.h
index 6c37f88f..c6d61eda 100644
--- a/include/topster.h
+++ b/include/topster.h
@@ -100,12 +100,12 @@ struct Topster {
}
static bool is_greater_kv(const struct KV &i, const struct KV &j) {
- return std::tie(i.match_score, i.primary_attr, i.secondary_attr, i.key) >
- std::tie(j.match_score, j.primary_attr, j.secondary_attr, j.key);
+ return std::tie(i.match_score, i.primary_attr, i.secondary_attr) >
+ std::tie(j.match_score, j.primary_attr, j.secondary_attr);
}
void sort() {
- std::sort(std::begin(data), std::begin(data) + size, is_greater_kv);
+ std::stable_sort(std::begin(data), std::begin(data) + size, is_greater_kv);
}
void clear(){