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

Minor refactor of import API.

kishorenc5c942e7f4a2c
diff --git a/src/collection.cpp b/src/collection.cpp
index cf06466c..adf4ea8c 100644
--- a/src/collection.cpp
+++ b/src/collection.cpp
@@ -155,7 +155,7 @@ Option<nlohmann::json> Collection::add_many(const std::string & json_lines_str)
std::vector<std::string> json_lines;
StringUtils::split(json_lines_str, json_lines, "\n");
- if(json_lines.size() == 0) {
+ if(json_lines.empty()) {
return Option<nlohmann::json>(400, "The request body was empty. So, no records were imported.");
}
diff --git a/src/core_api.cpp b/src/core_api.cpp
index cb0c988e..2c78ff00 100644
--- a/src/core_api.cpp
+++ b/src/core_api.cpp
@@ -513,15 +513,16 @@ bool post_import_documents(http_req & req, http_res & res) {
return false;
}
- Option<nlohmann::json> result = collection->add_many(req.body);
+ Option<nlohmann::json> res_op = collection->add_many(req.body);
- if(!result.ok()) {
- res.set(result.code(), result.error());
+ if(!res_op.ok()) {
+ res.set(res_op.code(), res_op.error());
return false;
}
- res.set_200(result.get().dump());
- return true;
+ const nlohmann::json& result = res_op.get();
+ res.set_200(result.dump());
+ return result["success"].get<bool>();
}
bool get_fetch_document(http_req & req, http_res & res) {