From af28e9d239fd104db0cda34577c7af67410ab157 Mon Sep 17 00:00:00 2001 From: Kishore Nallan Date: Fri, 7 Oct 2022 10:55:05 +0530 Subject: [PATCH] Fix regression in `out_of` in exclude_fields. --- src/collection.cpp | 5 +++++ test/collection_specific_more_test.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/collection.cpp b/src/collection.cpp index 52e9d421..cf99523b 100644 --- a/src/collection.cpp +++ b/src/collection.cpp @@ -993,6 +993,11 @@ Option Collection::search(const std::string & raw_query, } for(auto& f_name: exclude_fields) { + if(f_name == "out_of") { + // `out_of` is strictly a meta-field, but we handle it since it's useful + continue; + } + auto field_op = extract_field_name(f_name, search_schema, exclude_fields_vec, false, enable_nested_fields); if(!field_op.ok()) { return Option(404, field_op.error()); diff --git a/test/collection_specific_more_test.cpp b/test/collection_specific_more_test.cpp index ba14f33a..8bf2d95a 100644 --- a/test/collection_specific_more_test.cpp +++ b/test/collection_specific_more_test.cpp @@ -1434,3 +1434,27 @@ TEST_F(CollectionSpecificMoreTest, VerifyDeletionOfFacetStringIndex) { ASSERT_EQ(0, kv.second->size); } } + +TEST_F(CollectionSpecificMoreTest, MustExcludeOutOf) { + 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 1"; + ASSERT_TRUE(coll1->add(doc.dump()).ok()); + + spp::sparse_hash_set include_fields; + auto res_op = coll1->search("*", {}, "", {}, {}, {2}, 10, 1, + FREQUENCY, {true}, 0, include_fields, {"out_of"}); + + ASSERT_TRUE(res_op.ok()); + auto res = res_op.get(); + ASSERT_EQ(1, res["hits"].size()); + ASSERT_EQ(0, res.count("out_of")); +} \ No newline at end of file