From d71110f3979eacd35d623aab10982343587dbe71 Mon Sep 17 00:00:00 2001 From: krunal Date: Tue, 19 Sep 2023 21:41:12 +0530 Subject: [PATCH] adding test for multiple synonym substition in query --- test/collection_synonyms_test.cpp | 59 +++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/test/collection_synonyms_test.cpp b/test/collection_synonyms_test.cpp index c06c7062..6a0b9707 100644 --- a/test/collection_synonyms_test.cpp +++ b/test/collection_synonyms_test.cpp @@ -1008,3 +1008,62 @@ TEST_F(CollectionSynonymsTest, SynonymForKorean) { res = coll1->search("구울", {"title"}, "", {}, {}, {0}, 10, 1, FREQUENCY, {true}, 0).get(); ASSERT_EQ(3, res["hits"].size()); } + +TEST_F(CollectionSynonymsTest, MultipleSynonymSubstitution) { + nlohmann::json schema = R"({ + "name": "coll2", + "fields": [ + {"name": "title", "type": "string"}, + {"name": "gender", "type": "string"} + ] + })"_json; + + auto op = collectionManager.create_collection(schema); + ASSERT_TRUE(op.ok()); + Collection* coll2 = op.get(); + + std::vector> records = { + {"Beautiful Blazer", "Male"}, + }; + + for(size_t i=0; iadd(doc.dump()); + ASSERT_TRUE(add_op.ok()); + } + + nlohmann::json synonym1 = R"({ + "id": "foobar", + "synonyms": ["blazer", "suit"] + })"_json; + + nlohmann::json synonym2 = R"({ + "id": "foobar2", + "synonyms": ["male", "man"] + })"_json; + + + ASSERT_TRUE(coll2->add_synonym(synonym1).ok()); + ASSERT_TRUE(coll2->add_synonym(synonym2).ok()); + + auto res = coll2->search("blazer male", {"title", "gender"}, "", {}, + {}, {0}, 10, 1, FREQUENCY, {true},0).get(); + ASSERT_EQ(1, res["hits"].size()); + + res = coll2->search("blazer man", {"title", "gender"}, "", {}, + {}, {0}, 10, 1, FREQUENCY, {true}, 0).get(); + ASSERT_EQ(1, res["hits"].size()); + + res = coll2->search("suit male", {"title", "gender"}, "", {}, + {}, {0}, 10, 1, FREQUENCY, {true}, 0).get(); + ASSERT_EQ(1, res["hits"].size()); + + res = coll2->search("suit man", {"title", "gender"}, "", {}, + {}, {0}, 10, 1, FREQUENCY, {true}, 0).get(); + ASSERT_EQ(1, res["hits"].size()); +} \ No newline at end of file