From 0e52f93b5aaaa715246d9e17e72c84aa4858ca24 Mon Sep 17 00:00:00 2001 From: Kishore Nallan Date: Tue, 10 May 2022 20:35:01 +0530 Subject: [PATCH] Additional test for upsert with string field. --- test/collection_filtering_test.cpp | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/test/collection_filtering_test.cpp b/test/collection_filtering_test.cpp index ed2486de..6c9c4cf3 100644 --- a/test/collection_filtering_test.cpp +++ b/test/collection_filtering_test.cpp @@ -2294,7 +2294,9 @@ TEST_F(CollectionFilteringTest, ExcludeMultipleTokens) { } TEST_F(CollectionFilteringTest, FilteringAfterUpsertOnArrayWithTokenSeparators) { - std::vector fields = {field("name", field_types::STRING, false), field("tags", field_types::STRING_ARRAY, false)}; + std::vector fields = {field("name", field_types::STRING, false), + field("tags", field_types::STRING_ARRAY, false), + field("tag", field_types::STRING, false)}; Collection* coll1 = collectionManager.create_collection("coll1", 1, fields, "", 0, "", {}, {"-"}).get(); @@ -2302,11 +2304,13 @@ TEST_F(CollectionFilteringTest, FilteringAfterUpsertOnArrayWithTokenSeparators) doc1["id"] = "0"; doc1["name"] = "david"; doc1["tags"] = {"alpha-beta-gamma", "foo-bar-baz"}; + doc1["tag"] = "foo-bar-baz"; nlohmann::json doc2; doc2["id"] = "1"; doc2["name"] = "david"; doc2["tags"] = {"alpha-gamma-beta", "bar-foo-baz"}; + doc2["tag"] = "alpha-beta"; ASSERT_TRUE(coll1->add(doc1.dump()).ok()); ASSERT_TRUE(coll1->add(doc2.dump()).ok()); @@ -2326,11 +2330,20 @@ TEST_F(CollectionFilteringTest, FilteringAfterUpsertOnArrayWithTokenSeparators) ASSERT_EQ(1, results["hits"].size()); ASSERT_EQ("1", results["hits"][0]["document"]["id"].get()); + // repeat for singular string field: upsert with "foo-bar-baz" removed + doc1["tag"] = "alpha-beta-gamma"; + coll1->add(doc1.dump(), UPSERT); + + results = coll1->search("david", {"name"},"tag:=[foo-bar-baz]", {}, {}, {0}, 10, 1, FREQUENCY, {false}).get(); + ASSERT_EQ(0, results["hits"].size()); + collectionManager.drop_collection("coll1"); } TEST_F(CollectionFilteringTest, FilteringAfterUpsertOnArrayWithSymbolsToIndex) { - std::vector fields = {field("name", field_types::STRING, false), field("tags", field_types::STRING_ARRAY, false)}; + std::vector fields = {field("name", field_types::STRING, false), + field("tags", field_types::STRING_ARRAY, false), + field("tag", field_types::STRING, false)}; Collection* coll1 = collectionManager.create_collection("coll1", 1, fields, "", 0, "", {"-"}, {}).get(); @@ -2338,11 +2351,13 @@ TEST_F(CollectionFilteringTest, FilteringAfterUpsertOnArrayWithSymbolsToIndex) { doc1["id"] = "0"; doc1["name"] = "david"; doc1["tags"] = {"alpha-beta-gamma", "foo-bar-baz"}; + doc1["tag"] = "foo-bar-baz"; nlohmann::json doc2; doc2["id"] = "1"; doc2["name"] = "david"; doc2["tags"] = {"alpha-gamma-beta", "bar-foo-baz"}; + doc2["tag"] = "alpha-beta"; ASSERT_TRUE(coll1->add(doc1.dump()).ok()); ASSERT_TRUE(coll1->add(doc2.dump()).ok()); @@ -2362,5 +2377,12 @@ TEST_F(CollectionFilteringTest, FilteringAfterUpsertOnArrayWithSymbolsToIndex) { ASSERT_EQ(1, results["hits"].size()); ASSERT_EQ("1", results["hits"][0]["document"]["id"].get()); + // repeat for singular string field: upsert with "foo-bar-baz" removed + doc1["tag"] = "alpha-beta-gamma"; + coll1->add(doc1.dump(), UPSERT); + + results = coll1->search("david", {"name"},"tag:=[foo-bar-baz]", {}, {}, {0}, 10, 1, FREQUENCY, {false}).get(); + ASSERT_EQ(0, results["hits"].size()); + collectionManager.drop_collection("coll1"); }