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
adding test for reload on restart
krunal97c740068964
diff --git a/test/core_api_utils_test.cpp b/test/core_api_utils_test.cppindex 29ea703a..acb597fd 100644--- a/test/core_api_utils_test.cpp+++ b/test/core_api_utils_test.cpp@@ -4,13 +4,11 @@#include <collection_manager.h>#include <core_api.h>#include "core_api_utils.h"-#include "stopwords_manager.h"class CoreAPIUtilsTest : public ::testing::Test {protected:Store *store;CollectionManager & collectionManager = CollectionManager::get_instance();- StopwordsManager& stopwordsManager = StopwordsManager::get_instance();std::atomic<bool> quit = false;std::vector<std::string> query_fields;@@ -24,8 +22,6 @@ protected:store = new Store(state_dir_path);collectionManager.init(store, 1.0, "auth_key", quit);collectionManager.load(8, 1000);-- stopwordsManager.init(store);}virtual void SetUp() {diff --git a/test/stopwords_manager_test.cpp b/test/stopwords_manager_test.cppindex 784e88c3..7324dade 100644--- a/test/stopwords_manager_test.cpp+++ b/test/stopwords_manager_test.cpp@@ -379,4 +379,66 @@ TEST_F(StopwordsManagerTest, StopwordsValidation) {ASSERT_STREQ("{\"message\": \"Parameter `stopwords` is required as string array value\"}", res->body.c_str());collectionManager.drop_collection("coll1");-}\ No newline at end of file+}++TEST_F(StopwordsManagerTest, ReloadStopwordsOnRestart) {+ nlohmann::json schema = R"({+ "name": "coll1",+ "fields": [+ {"name": "title", "type": "string" },+ {"name": "points", "type": "int32" }+ ]+ })"_json;++ auto op = collectionManager.create_collection(schema);+ ASSERT_TRUE(op.ok());+ Collection *coll1 = op.get();++ auto stopword_value = R"(+ {"stopwords": ["Pop", "Indie", "Rock", "Metal", "Folk"], "locale": "en"}+ )"_json;++ std::shared_ptr<http_req> req = std::make_shared<http_req>();+ std::shared_ptr<http_res> res = std::make_shared<http_res>(nullptr);+ req->params["collection"] = "coll1";+ req->params["name"] = "genre";+ req->body = stopword_value.dump();++ auto result = put_upsert_stopword(req, res);+ if(!result) {+ LOG(ERROR) << res->body;+ FAIL();+ }++ auto stopword_config = stopwordsManager.get_stopwords();+ ASSERT_TRUE(stopword_config.find("genre") != stopword_config.end());++ ASSERT_EQ(5, stopword_config["genre"].size());+ ASSERT_TRUE(stopword_config["genre"].find("pop") != stopword_config["genre"].end());+ ASSERT_TRUE(stopword_config["genre"].find("indie") != stopword_config["genre"].end());+ ASSERT_TRUE(stopword_config["genre"].find("rock") != stopword_config["genre"].end());+ ASSERT_TRUE(stopword_config["genre"].find("metal") != stopword_config["genre"].end());+ ASSERT_TRUE(stopword_config["genre"].find("folk") != stopword_config["genre"].end());++ //dispose collection manager and reload all stopwords+ collectionManager.dispose();+ delete store;+ stopword_config.clear();++ std::string state_dir_path = "/tmp/typesense_test/stopwords_manager";+ system(("rm -rf "+state_dir_path+" && mkdir -p "+state_dir_path).c_str());+ store = new Store(state_dir_path);++ collectionManager.init(store, 1.0, "auth_key", quit);+ collectionManager.load(8, 1000);++ stopword_config = stopwordsManager.get_stopwords();+ ASSERT_TRUE(stopword_config.find("genre") != stopword_config.end());++ ASSERT_EQ(5, stopword_config["genre"].size());+ ASSERT_TRUE(stopword_config["genre"].find("pop") != stopword_config["genre"].end());+ ASSERT_TRUE(stopword_config["genre"].find("indie") != stopword_config["genre"].end());+ ASSERT_TRUE(stopword_config["genre"].find("rock") != stopword_config["genre"].end());+ ASSERT_TRUE(stopword_config["genre"].find("metal") != stopword_config["genre"].end());+ ASSERT_TRUE(stopword_config["genre"].find("folk") != stopword_config["genre"].end());+}