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

Identify curated results in response.

kishorenc2102f2323f81
diff --git a/src/collection.cpp b/src/collection.cpp
index 402892e5..bdfd1801 100644
--- a/src/collection.cpp
+++ b/src/collection.cpp
@@ -837,6 +837,7 @@ Option<nlohmann::json> Collection::search(const std::string & query, const std::
uint64_t override_position = override_result_kvs[override_kv_index][0]->distinct_key;
if(result_position == override_position) {
+ override_result_kvs[override_kv_index][0]->match_score = 0; // to identify curated result
result_group_kvs.push_back(override_result_kvs[override_kv_index]);
override_kv_index++;
} else {
@@ -846,6 +847,7 @@ Option<nlohmann::json> Collection::search(const std::string & query, const std::
}
while(override_kv_index < override_result_kvs.size()) {
+ override_result_kvs[override_kv_index][0]->match_score = 0; // to identify curated result
result_group_kvs.push_back({override_result_kvs[override_kv_index]});
override_kv_index++;
}
@@ -947,10 +949,16 @@ Option<nlohmann::json> Collection::search(const std::string & query, const std::
wrapper_doc["highlights"].push_back(h_json);
}
+ //wrapper_doc["seq_id"] = (uint32_t) field_order_kv->key;
+
prune_document(document, include_fields, exclude_fields);
wrapper_doc["document"] = document;
wrapper_doc["text_match"] = field_order_kv->match_score;
- //wrapper_doc["seq_id"] = (uint32_t) field_order_kv->key;
+
+ if(field_order_kv->match_score == 0) {
+ wrapper_doc["curated"] = true;
+ }
+
hits_array.push_back(wrapper_doc);
}
diff --git a/test/collection_override_test.cpp b/test/collection_override_test.cpp
index e79e2b42..e08f32d2 100644
--- a/test/collection_override_test.cpp
+++ b/test/collection_override_test.cpp
@@ -122,6 +122,11 @@ TEST_F(CollectionOverrideTest, ExcludeIncludeExactQueryMatch) {
ASSERT_STREQ("3", results["hits"][1]["document"]["id"].get<std::string>().c_str());
ASSERT_STREQ("13", results["hits"][2]["document"]["id"].get<std::string>().c_str());
+ // curated results should be marked as such
+ ASSERT_EQ(true, results["hits"][0]["curated"].get<bool>());
+ ASSERT_EQ(true, results["hits"][1]["curated"].get<bool>());
+ ASSERT_EQ(0, results["hits"][2].count("curated"));
+
coll_mul_fields->remove_override("exclude-rule");
coll_mul_fields->remove_override("include-rule");
@@ -367,6 +372,12 @@ TEST_F(CollectionOverrideTest, PinnedHitsGrouping) {
ASSERT_STREQ("13", results["hits"][2]["document"]["id"].get<std::string>().c_str());
ASSERT_STREQ("11", results["hits"][3]["document"]["id"].get<std::string>().c_str());
+ // pinned hits should be marked as curated
+ ASSERT_EQ(true, results["hits"][0]["curated"].get<bool>());
+ ASSERT_EQ(true, results["hits"][1]["curated"].get<bool>());
+ ASSERT_EQ(true, results["hits"][2]["curated"].get<bool>());
+ ASSERT_EQ(0, results["hits"][3].count("curated"));
+
// with grouping
results = coll_mul_fields->search("the", {"title"}, "", {"starring"}, {}, 0, 50, 1, FREQUENCY,