Skip to content

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

Log Bad JSON error.

Kishore Nallan92335438b38c
diff --git a/include/collection.h b/include/collection.h
index 7b53462e..2bd98c9a 100644
--- a/include/collection.h
+++ b/include/collection.h
@@ -25,8 +25,6 @@ private:
size_t num_documents;
- size_t num_indices;
-
std::vector<Index*> indices;
std::vector<std::thread*> index_threads;
@@ -46,6 +44,8 @@ private:
std::string token_ranking_field;
+ size_t num_indices;
+
std::string get_doc_id_key(const std::string & doc_id);
std::string get_seq_id_key(uint32_t seq_id);
diff --git a/src/api.cpp b/src/api.cpp
index 0be38dc8..06c4dc89 100644
--- a/src/api.cpp
+++ b/src/api.cpp
@@ -57,7 +57,8 @@ void post_create_collection(http_req & req, http_res & res) {
try {
req_json = nlohmann::json::parse(req.body);
- } catch(...) {
+ } catch(const std::exception& e) {
+ LOG(WARNING) << "JSON error: " << e.what();
return res.send_400("Bad JSON.");
}
diff --git a/src/collection.cpp b/src/collection.cpp
index 2391c654..c808d853 100644
--- a/src/collection.cpp
+++ b/src/collection.cpp
@@ -12,7 +12,8 @@
#include "logger.h"
Collection::Collection(const std::string name, const uint32_t collection_id, const uint32_t next_seq_id, Store *store,
- const std::vector<field> &fields, const std::string & token_ranking_field):
+ const std::vector<field> &fields, const std::string & token_ranking_field,
+ const size_t num_indices):
name(name), collection_id(collection_id), next_seq_id(next_seq_id), store(store),
fields(fields), token_ranking_field(token_ranking_field), num_indices(num_indices) {
@@ -69,7 +70,8 @@ Option<nlohmann::json> Collection::add(const std::string & json_str) {
nlohmann::json document;
try {
document = nlohmann::json::parse(json_str);
- } catch(...) {
+ } catch(const std::exception& e) {
+ LOG(WARNING) << "JSON error: " << e.what();
return Option<nlohmann::json>(400, "Bad JSON.");
}
@@ -599,8 +601,8 @@ Option<nlohmann::json> Collection::search(std::string query, const std::vector<s
snippet_stream << tokens[snippet_index];
}
- wrapper_doc["_highlight"] = nlohmann::json::object();
- wrapper_doc["_highlight"][field_name] = snippet_stream.str();
+ wrapper_doc["highlight"] = nlohmann::json::object();
+ wrapper_doc["highlight"][field_name] = snippet_stream.str();
}
result["hits"].push_back(wrapper_doc);