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
Handle dropping of optional field.
Kishore Nallan81ad4c2ba625
diff --git a/src/index.cpp b/src/index.cppindex fe589a45..fd000a3d 100644--- a/src/index.cpp+++ b/src/index.cpp@@ -4456,6 +4456,10 @@ Option<uint32_t> Index::remove(const uint32_t seq_id, const nlohmann::json & docif(!del_fields.empty()) {for(auto& the_field: del_fields) {+ if(!document.contains(the_field.name)) {+ // could be an optional field+ continue;+ }remove_field(seq_id, document, the_field.name);}} else {diff --git a/test/collection_filtering_test.cpp b/test/collection_filtering_test.cppindex 49b593fa..1e65258b 100644--- a/test/collection_filtering_test.cpp+++ b/test/collection_filtering_test.cpp@@ -1890,6 +1890,37 @@ TEST_F(CollectionFilteringTest, NumericalRangeFilter) {collectionManager.drop_collection("coll1");}+TEST_F(CollectionFilteringTest, RangeFilterOnTimestamp) {+ std::vector<field> fields = {field("ts", field_types::INT64, false)};++ Collection* coll1 = collectionManager.create_collection(+ "coll1", 1, fields, "", 0, "", {}, {"."}+ ).get();++ nlohmann::json doc1;+ doc1["id"] = "0";+ doc1["ts"] = 1646092800000;++ nlohmann::json doc2;+ doc2["id"] = "1";+ doc2["ts"] = 1648771199000;++ nlohmann::json doc3;+ doc3["id"] = "2";+ doc3["ts"] = 1647111199000;++ ASSERT_TRUE(coll1->add(doc1.dump()).ok());+ ASSERT_TRUE(coll1->add(doc2.dump()).ok());+ ASSERT_TRUE(coll1->add(doc3.dump()).ok());++ auto results = coll1->search("*", {},"ts:[1646092800000..1648771199000]", {}, {}, {0}, 10,+ 1, FREQUENCY, {false}).get();++ ASSERT_EQ(3, results["hits"].size());++ collectionManager.drop_collection("coll1");+}+TEST_F(CollectionFilteringTest, QueryBoolFields) {Collection *coll_bool;diff --git a/test/collection_schema_change_test.cpp b/test/collection_schema_change_test.cppindex 3e3fcbf4..bbebe994 100644--- a/test/collection_schema_change_test.cpp+++ b/test/collection_schema_change_test.cpp@@ -710,3 +710,26 @@ TEST_F(CollectionSchemaChangeTest, AddDynamicFieldMatchingMultipleFields) {ASSERT_EQ(2, coll1->get_fields().size());ASSERT_EQ(0, coll1->get_dynamic_fields().size());}++TEST_F(CollectionSchemaChangeTest, DropFieldNotExistingInDocuments) {+ // optional title field+ std::vector<field> fields = {field("title", field_types::STRING, false, true, true, "", 1, 1),+ field("points", field_types::INT32, true),};++ Collection* coll1 = collectionManager.create_collection("coll1", 1, fields, "points", 0, "").get();++ nlohmann::json doc;+ doc["id"] = "0";+ doc["points"] = 100;++ ASSERT_TRUE(coll1->add(doc.dump()).ok());++ auto schema_changes = R"({+ "fields": [+ {"name": "title", "drop": true}+ ]+ })"_json;++ auto alter_op = coll1->alter(schema_changes);+ ASSERT_TRUE(alter_op.ok());+}\ No newline at end of file