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
C++ algoliadatastoreelasticsearchenterprise-searchfacetingfull-text-searchfuzzy-searchgeosearchin-memoryinstantsearchmerchandisingpineconesearchsearch-enginesemantic-searchsimilarity-searchsite-searchsynonymstypo-tolerancevector-search
Fix `id` field not available for include/exclude fields.
Kishore Nallande0efc1fae86
diff --git a/src/collection.cpp b/src/collection.cppindex 85bf6ce3..e640d4f1 100644--- a/src/collection.cpp+++ b/src/collection.cpp@@ -751,6 +751,11 @@ Option<bool> Collection::extract_field_name(const std::string& field_name,std::vector<std::string>& processed_search_fields,const bool extract_only_string_fields,const bool enable_nested_fields) {+ if(field_name == "id") {+ processed_search_fields.push_back(field_name);+ return Option<bool>(true);+ }+auto prefix_it = search_schema.equal_prefix_range(field_name);bool field_found = false;diff --git a/test/collection_nested_fields_test.cpp b/test/collection_nested_fields_test.cppindex edc31d02..0603f1c4 100644--- a/test/collection_nested_fields_test.cpp+++ b/test/collection_nested_fields_test.cpp@@ -689,6 +689,16 @@ TEST_F(CollectionNestedFieldsTest, HighlightNestedFieldFully) {ASSERT_EQ(highlight_doc.dump(), results["hits"][0]["highlight"]["snippet"].dump());ASSERT_EQ(highlight_full_doc.dump(), results["hits"][0]["highlight"]["full"].dump());++ // try to highlight `id` field+ results = coll1->search("shoes", {"locations.address.products"}, "", {}, sort_fields, {0}, 10, 1,+ token_ordering::FREQUENCY, {true}, 10, spp::sparse_hash_set<std::string>(),+ spp::sparse_hash_set<std::string>(), 10, "", 30, 4, "id",+ 20, {}, {}, {}, 0, "<mark>", "</mark>", {}, 1000, true, false, true,+ "id").get();++ ASSERT_TRUE(results["hits"][0]["highlight"]["snippet"].empty());+ ASSERT_TRUE(results["hits"][0]["highlight"]["full"].empty());}TEST_F(CollectionNestedFieldsTest, HighlightShouldHaveMeta) {diff --git a/test/collection_specific_more_test.cpp b/test/collection_specific_more_test.cppindex 35319ec8..353b3760 100644--- a/test/collection_specific_more_test.cpp+++ b/test/collection_specific_more_test.cpp@@ -1138,6 +1138,30 @@ TEST_F(CollectionSpecificMoreTest, UnorderedWeightingOfFields) {ASSERT_EQ(0, res_op.get()["hits"].size());}+TEST_F(CollectionSpecificMoreTest, IncludeFieldsOnlyId) {+ nlohmann::json schema = R"({+ "name": "coll1",+ "fields": [+ {"name": "title", "type": "string"}+ ]+ })"_json;++ Collection* coll1 = collectionManager.create_collection(schema).get();++ nlohmann::json doc;+ doc["title"] = "Sample Title";+ ASSERT_TRUE(coll1->add(doc.dump()).ok());++ auto res_op = coll1->search("*", {}, "", {}, {}, {2}, 10, 1,+ FREQUENCY, {true}, 0, {"id"});++ ASSERT_TRUE(res_op.ok());+ auto res = res_op.get();++ ASSERT_EQ(1, res["hits"][0]["document"].size());+ ASSERT_EQ("0", res["hits"][0]["document"]["id"].get<std::string>());+}+TEST_F(CollectionSpecificMoreTest, HighlightObjectShouldBeEmptyWhenNoHighlightFieldFound) {nlohmann::json schema = R"({"name": "coll1",