Fix root synonym erase.
Some checks failed
tests / test (push) Has been cancelled

This commit is contained in:
Kishore Nallan 2025-01-15 12:38:34 +05:30
parent 330f0d664f
commit 871d576783
2 changed files with 46 additions and 1 deletions

View File

@ -188,7 +188,10 @@ Option<bool> SynonymIndex::remove_synonym(const std::string & collection_name, c
const auto& synonym = synonym_definitions.at(syn_iter->second);
std::vector<std::string> keys;
keys.insert(keys.end(), synonym.root.begin(), synonym.root.end());
auto root_str = StringUtils::join(synonym.root, " ");
keys.push_back(root_str);
for(const auto & syn_tokens : synonym.synonyms) {
auto synonyms_str = StringUtils::join(syn_tokens, " ");
keys.push_back(synonyms_str);

View File

@ -925,6 +925,48 @@ TEST_F(CollectionSynonymsTest, SynonymQueriesMustHavePrefixEnabled) {
collectionManager.drop_collection("coll1");
}
TEST_F(CollectionSynonymsTest, SynonymUpsertTwice) {
Collection *coll1;
std::vector<field> fields = {field("title", field_types::STRING, false),
field("points", field_types::INT32, false),};
coll1 = collectionManager.get_collection("coll1").get();
if(coll1 == nullptr) {
coll1 = collectionManager.create_collection("coll1", 1, fields, "points").get();
}
coll1->add_synonym(R"({"id": "syn-1", "root": "prairie city", "synonyms": ["prairie", "prairiecty"]})"_json);
coll1->add_synonym(R"({"id": "syn-1", "root": "prairie city", "synonyms": ["prairie", "prairiecty"]})"_json);
auto res = coll1->search("prairie city", {"title"}, "", {}, {}, {2}, 10, 1, FREQUENCY, {true}, 0).get();
ASSERT_EQ(0, res["hits"].size());
ASSERT_EQ(0, res["found"].get<uint32_t>());
collectionManager.drop_collection("coll1");
}
TEST_F(CollectionSynonymsTest, SynonymUpsertTwiceLocale) {
Collection *coll1;
std::vector<field> fields = {field("title", field_types::STRING, false),
field("points", field_types::INT32, false),};
coll1 = collectionManager.get_collection("coll1").get();
if(coll1 == nullptr) {
coll1 = collectionManager.create_collection("coll1", 1, fields, "points").get();
}
coll1->add_synonym(R"({"id": "syn-1", "locale": "th", "root": "", "synonyms": [""]})"_json);
coll1->add_synonym(R"({"id": "syn-1", "locale": "th", "root": "", "synonyms": [""]})"_json);
auto res = coll1->search("สวัสดีตอนเช้าครับ", {"title"}, "", {}, {}, {2}, 10, 1, FREQUENCY, {true}, 0).get();
ASSERT_EQ(0, res["hits"].size());
ASSERT_EQ(0, res["found"].get<uint32_t>());
collectionManager.drop_collection("coll1");
}
TEST_F(CollectionSynonymsTest, HandleSpecialSymbols) {
Collection *coll1;