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

Handle bad data in ingestion text gracefully.

Kishore Nallanb4c222064c6b
diff --git a/src/collection.cpp b/src/collection.cpp
index d754d66c..aaf0d11f 100644
--- a/src/collection.cpp
+++ b/src/collection.cpp
@@ -337,7 +337,8 @@ void Collection::batch_index(std::vector<std::vector<index_record>> &index_batch
res["code"] = index_record.indexed.code();
}
- json_out[index_record.position] = res.dump();
+ json_out[index_record.position] = res.dump(-1, ' ', false,
+ nlohmann::detail::error_handler_t::ignore);
}
}
}
diff --git a/test/collection_specific_test.cpp b/test/collection_specific_test.cpp
index f36be260..4fc657e7 100644
--- a/test/collection_specific_test.cpp
+++ b/test/collection_specific_test.cpp
@@ -676,3 +676,16 @@ TEST_F(CollectionSpecificTest, GuardAgainstIdFieldInSchema) {
collectionManager.drop_collection("coll1");
}
+
+TEST_F(CollectionSpecificTest, HandleBadCharactersInStringGracefully) {
+ std::vector<field> fields = {field("title", field_types::STRING, false),
+ field("points", field_types::INT32, false),};
+
+ Collection* coll1 = collectionManager.create_collection("coll1", 1, fields, "points").get();
+ std::string doc_str = "不推荐。\",\"price\":10.12,\"ratings\":5}";
+
+ auto add_op = coll1->add(doc_str);
+ ASSERT_FALSE(add_op.ok());
+
+ collectionManager.drop_collection("coll1");
+}