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
Add health check end-point.
Kishore Nallanad42c40e6d94
diff --git a/include/core_api.h b/include/core_api.hindex 89ef7d7a..48489519 100644--- a/include/core_api.h+++ b/include/core_api.h@@ -12,6 +12,8 @@ void del_drop_collection(http_req & req, http_res & res);void get_debug(http_req & req, http_res & res);+void get_health(http_req & req, http_res & res);+void get_search(http_req & req, http_res & res);void get_collection_summary(http_req & req, http_res & res);diff --git a/include/string_utils.h b/include/string_utils.hindex 5672469a..919538c8 100644--- a/include/string_utils.h+++ b/include/string_utils.h@@ -41,6 +41,18 @@ struct StringUtils {}}+ static std::string join(std::vector<std::string> vec, std::string delimiter, size_t start_index = 0) {+ std::stringstream ss;+ for(size_t i = start_index; i <= vec.size()-1; i++) {+ if(i != start_index) {+ ss << delimiter;+ }+ ss << vec[i];+ }++ return ss.str();+ }+// Adapted from: http://stackoverflow.com/a/36000453/131050static std::string & trim(std::string & str) {// right trimdiff --git a/src/core_api.cpp b/src/core_api.cppindex 6e3158c0..193e7976 100644--- a/src/core_api.cpp+++ b/src/core_api.cpp@@ -32,8 +32,7 @@ nlohmann::json collection_summary_json(Collection *collection) {bool handle_authentication(const route_path & rpath, const std::string & auth_key) {CollectionManager & collectionManager = CollectionManager::get_instance();-- return collectionManager.auth_key_matches(auth_key) ||+ return rpath.handler == get_health || collectionManager.auth_key_matches(auth_key) ||(rpath.handler == get_search && collectionManager.search_only_auth_key_matches(auth_key));}@@ -156,6 +155,12 @@ void get_debug(http_req & req, http_res & res) {res.send_200(result.dump());}+void get_health(http_req & req, http_res & res) {+ nlohmann::json result;+ result["ok"] = true;+ res.send_200(result.dump());+}+void get_search(http_req & req, http_res & res) {auto begin = std::chrono::high_resolution_clock::now();diff --git a/src/main/typesense_server.cpp b/src/main/typesense_server.cppindex e0b5ae79..0f768e66 100644--- a/src/main/typesense_server.cpp+++ b/src/main/typesense_server.cpp@@ -17,6 +17,7 @@ void master_server_routes() {// metaserver->get("/debug", get_debug);+ server->get("/health", get_health);// replicationserver->get("/replication/updates", get_replication_updates, true);diff --git a/test/string_utils_test.cpp b/test/string_utils_test.cppindex aa140e62..7e55189f 100644--- a/test/string_utils_test.cpp+++ b/test/string_utils_test.cpp@@ -23,4 +23,14 @@ TEST(StringUtilsTest, ShouldNormalizeString) {std::string tamil_unicodechars = "தமிழ் நாடு";string_utils.unicode_normalize(tamil_unicodechars);ASSERT_STREQ("தமிழ்நாடு", tamil_unicodechars.c_str());+}++TEST(StringUtilsTest, ShouldJoinString) {+ std::vector<std::string> parts = {"foo", "bar", "baz", "bazinga"};++ const std::string & joined_str1 = StringUtils::join(parts, "/");+ ASSERT_STREQ("foo/bar/baz/bazinga", joined_str1.c_str());++ const std::string & joined_str2 = StringUtils::join(parts, "/", 2);+ ASSERT_STREQ("baz/bazinga", joined_str2.c_str());}\ No newline at end of file