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
Ensure that overrides and synonyms on disk are deleted during colllection drop.
Kishore Nalland840a8802029
diff --git a/src/collection_manager.cpp b/src/collection_manager.cppindex dd64ef8d..d50e856d 100644--- a/src/collection_manager.cpp+++ b/src/collection_manager.cpp@@ -351,6 +351,26 @@ Option<nlohmann::json> CollectionManager::drop_collection(const std::string& col}delete iter;+ // delete overrides+ const std::string& del_override_prefix =+ std::string(Collection::COLLECTION_OVERRIDE_PREFIX) + "_" + actual_coll_name + "_";+ iter = store->scan(del_override_prefix);+ while(iter->Valid() && iter->key().starts_with(del_override_prefix)) {+ store->remove(iter->key().ToString());+ iter->Next();+ }+ delete iter;++ // delete synonyms+ const std::string& del_synonym_prefix =+ std::string(Collection::COLLECTION_SYNONYM_PREFIX) + "_" + actual_coll_name + "_";+ iter = store->scan(del_synonym_prefix);+ while(iter->Valid() && iter->key().starts_with(del_synonym_prefix)) {+ store->remove(iter->key().ToString());+ iter->Next();+ }+ delete iter;+store->remove(Collection::get_next_seq_id_key(actual_coll_name));store->remove(Collection::get_meta_key(actual_coll_name));}diff --git a/test/collection_specific_test.cpp b/test/collection_specific_test.cppindex 015ba78b..1e7c72a4 100644--- a/test/collection_specific_test.cpp+++ b/test/collection_specific_test.cpp@@ -15,7 +15,7 @@ protected:std::vector<sort_by> sort_fields;void setupCollection() {- std::string state_dir_path = "/tmp/typesense_test/collection_filtering";+ std::string state_dir_path = "/tmp/typesense_test/collection_specific";LOG(INFO) << "Truncating and creating: " << state_dir_path;system(("rm -rf "+state_dir_path+" && mkdir -p "+state_dir_path).c_str());@@ -175,3 +175,51 @@ TEST_F(CollectionSpecificTest, CreateManyCollectionsAndDeleteOneOfThem) {collectionManager.drop_collection(coll_name);}}++TEST_F(CollectionSpecificTest, DeleteOverridesAndSynonymsOnDiskDuringCollDrop) {+ std::vector<field> fields = {field("title", field_types::STRING, false),+ field("points", field_types::INT32, false),};++ for (size_t i = 0; i <= 10; i++) {+ const std::string& coll_name = "coll" + std::to_string(i);+ collectionManager.drop_collection(coll_name);+ ASSERT_TRUE(collectionManager.create_collection(coll_name, 1, fields, "points").ok());+ }++ auto coll1 = collectionManager.get_collection_unsafe("coll1");++ nlohmann::json override_json = {+ {"id", "exclude-rule"},+ {+ "rule", {+ {"query", "of"},+ {"match", override_t::MATCH_EXACT}+ }+ }+ };+ override_json["excludes"] = nlohmann::json::array();+ override_json["excludes"][0] = nlohmann::json::object();+ override_json["excludes"][0]["id"] = "4";++ override_json["excludes"][1] = nlohmann::json::object();+ override_json["excludes"][1]["id"] = "11";++ override_t override;+ override_t::parse(override_json, "", override);+ coll1->add_override(override);++ // add synonym+ synonym_t synonym1{"ipod-synonyms", {}, {{"ipod"}, {"i", "pod"}, {"pod"}} };+ coll1->add_synonym(synonym1);++ collectionManager.drop_collection("coll1");++ // overrides should have been deleted from the store+ std::vector<std::string> stored_values;+ store->scan_fill(Collection::COLLECTION_OVERRIDE_PREFIX, stored_values);+ ASSERT_TRUE(stored_values.empty());++ // synonyms should also have been deleted from the store+ store->scan_fill(Collection::COLLECTION_SYNONYM_PREFIX, stored_values);+ ASSERT_TRUE(stored_values.empty());+}