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
Take care of underlying req being null.
Kishore Nallanf380bd5fa96a
diff --git a/include/collection_manager.h b/include/collection_manager.hindex e65d9ce4..6c4f8e1f 100644--- a/include/collection_manager.h+++ b/include/collection_manager.h@@ -177,7 +177,8 @@ public:static Option<bool> do_search(std::map<std::string, std::string>& req_params,nlohmann::json& embedded_params,- std::string& results_json_str);+ std::string& results_json_str,+ uint64_t start_ts);static bool parse_sort_by_str(std::string sort_by_str, std::vector<sort_by>& sort_fields);diff --git a/include/http_data.h b/include/http_data.hindex f51ed2d1..29d9bd2e 100644--- a/include/http_data.h+++ b/include/http_data.h@@ -261,11 +261,13 @@ struct http_req {chunk_len(0), body(body), body_index(0), data(nullptr), ready(false),log_index(0), is_diposed(false), client_ip(client_ip) {- const auto& tv = _req->processed_at.at;- start_ts = (tv.tv_sec * 1000 * 1000) + tv.tv_usec;-if(_req != nullptr) {+ const auto& tv = _req->processed_at.at;+ start_ts = (tv.tv_sec * 1000 * 1000) + tv.tv_usec;is_http_v1 = (_req->version < 0x200);+ } else {+ start_ts = std::chrono::duration_cast<std::chrono::microseconds>(+ std::chrono::system_clock::now().time_since_epoch()).count();}}diff --git a/src/collection_manager.cpp b/src/collection_manager.cppindex 81098b6c..ffbb704f 100644--- a/src/collection_manager.cpp+++ b/src/collection_manager.cpp@@ -630,7 +630,9 @@ Option<bool> add_unsigned_int_list_param(const std::string& param_name, const stOption<bool> CollectionManager::do_search(std::map<std::string, std::string>& req_params,nlohmann::json& embedded_params,- std::string& results_json_str) {+ std::string& results_json_str,+ uint64_t start_ts) {+auto begin = std::chrono::high_resolution_clock::now();const char *NUM_TYPOS = "num_typos";@@ -981,7 +983,8 @@ Option<bool> CollectionManager::do_search(std::map<std::string, std::string>& refilter_curated_hits_option,prioritize_token_position,vector_query,- enable_highlight_v1+ enable_highlight_v1,+ start_ts);uint64_t timeMillis = std::chrono::duration_cast<std::chrono::milliseconds>(diff --git a/src/core_api.cpp b/src/core_api.cppindex acb351ce..1599ddd2 100644--- a/src/core_api.cpp+++ b/src/core_api.cpp@@ -376,7 +376,8 @@ bool get_search(const std::shared_ptr<http_req>& req, const std::shared_ptr<http}std::string results_json_str;- Option<bool> search_op = CollectionManager::do_search(req->params, req->embedded_params_vec[0], results_json_str);+ Option<bool> search_op = CollectionManager::do_search(req->params, req->embedded_params_vec[0],+ results_json_str, req->start_ts);if(!search_op.ok()) {res->set(search_op.code(), search_op.error());@@ -523,7 +524,8 @@ bool post_multi_search(const std::shared_ptr<http_req>& req, const std::shared_p}std::string results_json_str;- Option<bool> search_op = CollectionManager::do_search(req->params, req->embedded_params_vec[i], results_json_str);+ Option<bool> search_op = CollectionManager::do_search(req->params, req->embedded_params_vec[i],+ results_json_str, req->start_ts);if(search_op.ok()) {response["results"].push_back(nlohmann::json::parse(results_json_str));diff --git a/test/collection_manager_test.cpp b/test/collection_manager_test.cppindex a3faceda..c0643ed2 100644--- a/test/collection_manager_test.cpp+++ b/test/collection_manager_test.cpp@@ -526,7 +526,10 @@ TEST_F(CollectionManagerTest, VerifyEmbeddedParametersOfScopedAPIKey) {embedded_params["filter_by"] = "points: 200";std::string json_res;- auto search_op = collectionManager.do_search(req_params, embedded_params, json_res);+ auto now_ts = std::chrono::duration_cast<std::chrono::microseconds>(+ std::chrono::system_clock::now().time_since_epoch()).count();++ auto search_op = collectionManager.do_search(req_params, embedded_params, json_res, now_ts);ASSERT_TRUE(search_op.ok());nlohmann::json res_obj = nlohmann::json::parse(json_res);@@ -540,7 +543,7 @@ TEST_F(CollectionManagerTest, VerifyEmbeddedParametersOfScopedAPIKey) {req_params["filter_by"] = "year: 1922";req_params["q"] = "*";- search_op = collectionManager.do_search(req_params, embedded_params, json_res);+ search_op = collectionManager.do_search(req_params, embedded_params, json_res, now_ts);ASSERT_TRUE(search_op.ok());res_obj = nlohmann::json::parse(json_res);