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 test.

Kishore Nallan75263d52a39c
diff --git a/src/art.cpp b/src/art.cpp
index d6726b5a..90e9644e 100644
--- a/src/art.cpp
+++ b/src/art.cpp
@@ -41,11 +41,22 @@ void art_int_fuzzy_recurse(art_node *n, int depth, const unsigned char* int_str,
NUM_COMPARATOR comparator, std::vector<const art_leaf *> &results);
bool compare_art_leaf_frequency(const art_leaf *a, const art_leaf *b) {
- return posting_t::num_ids(a->values) > posting_t::num_ids(b->values);
+ uint32_t a_val = posting_t::num_ids(a->values);
+ uint32_t b_val = posting_t::num_ids(b->values);
+
+ if(a_val != b_val) {
+ return a_val > b_val;
+ }
+
+ return *((uint32_t *)(uintptr_t)a) > *((uint32_t *)(uintptr_t)b);
}
bool compare_art_leaf_score(const art_leaf *a, const art_leaf *b) {
- return a->max_score > b->max_score;
+ if(a->max_score != b->max_score) {
+ return a->max_score > b->max_score;
+ }
+
+ return *((uint32_t *)(uintptr_t)a) > *((uint32_t *)(uintptr_t)b);
}
bool compare_art_node_frequency(const art_node *a, const art_node *b) {
diff --git a/test/art_test.cpp b/test/art_test.cpp
index 2784fbe7..45edf3a9 100644
--- a/test/art_test.cpp
+++ b/test/art_test.cpp
@@ -683,8 +683,8 @@ TEST(ArtTest, test_art_fuzzy_search) {
art_fuzzy_search(&t, (const unsigned char *) "pltinum", strlen("pltinum"), 0, 1, 10, FREQUENCY, true, nullptr, 0, leaves);
ASSERT_EQ(2, leaves.size());
- ASSERT_STREQ("platinum", (const char *)leaves.at(0)->key);
- ASSERT_STREQ("platinumsmith", (const char *)leaves.at(1)->key);
+ ASSERT_STREQ("platinumsmith", (const char *)leaves.at(0)->key);
+ ASSERT_STREQ("platinum", (const char *)leaves.at(1)->key);
leaves.clear();
@@ -734,7 +734,8 @@ TEST(ArtTest, test_art_fuzzy_search) {
art_fuzzy_search(&t, (const unsigned char *) "hown", strlen("hown") + 1, 0, 1, 10, FREQUENCY, false, nullptr, 0, leaves);
ASSERT_EQ(10, leaves.size());
- std::vector<const char*> words = {"lown", "how", "shown", "howl", "howe", "mown", "town", "sown", "own", "howk"};
+ std::vector<const char*> words = {"shown", "lown", "mown", "howl", "howe", "town", "hoon", "horn", "sown", "howk"};
+
for(size_t leaf_index = 0; leaf_index < leaves.size(); leaf_index++) {
ASSERT_STREQ(words.at(leaf_index), (const char *)leaves.at(leaf_index)->key);
}
diff --git a/test/collection_test.cpp b/test/collection_test.cpp
index 8ce03d7c..e5a62584 100644
--- a/test/collection_test.cpp
+++ b/test/collection_test.cpp
@@ -1035,7 +1035,7 @@ TEST_F(CollectionTest, KeywordQueryReturnsResultsBasedOnPerPageParam) {
FREQUENCY, {true}, 1000, empty, empty, 10).get();
ASSERT_EQ(3, results["hits"].size());
- ASSERT_EQ(6, results["found"].get<int>());
+ ASSERT_EQ(7, results["found"].get<int>());
// cannot fetch more than in-built limit of 250
auto res_op = coll_mul_fields->search("w", query_fields, "", facets, sort_fields, {0}, 251, 1,
@@ -1057,13 +1057,13 @@ TEST_F(CollectionTest, KeywordQueryReturnsResultsBasedOnPerPageParam) {
FREQUENCY, {true}, 1000, empty, empty, 10).get();
ASSERT_EQ(3, results["hits"].size());
- ASSERT_EQ(6, results["found"].get<int>());
+ ASSERT_EQ(7, results["found"].get<int>());
results = coll_mul_fields->search("w", query_fields, "", facets, sort_fields, {0}, 3, 2,
FREQUENCY, {true}, 1000, empty, empty, 10).get();
ASSERT_EQ(3, results["hits"].size());
- ASSERT_EQ(6, results["found"].get<int>());
+ ASSERT_EQ(7, results["found"].get<int>());
collectionManager.drop_collection("coll_mul_fields");
}