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

Fix nested field with regex name in schema.

Kishore Nalland2cf4b02019e
diff --git a/src/field.cpp b/src/field.cpp
index ca7d5149..bccd8da5 100644
--- a/src/field.cpp
+++ b/src/field.cpp
@@ -852,7 +852,7 @@ bool field::flatten_obj(nlohmann::json& doc, nlohmann::json& value, bool has_arr
continue;
}
- if(std::regex_match(flat_name, std::regex(flat_name))) {
+ if(std::regex_match(flat_name, std::regex(dynamic_field.name))) {
detected_type = dynamic_field.type;
found_dynamic_field = true;
break;
diff --git a/test/collection_nested_fields_test.cpp b/test/collection_nested_fields_test.cpp
index 20490d4a..a2eef13d 100644
--- a/test/collection_nested_fields_test.cpp
+++ b/test/collection_nested_fields_test.cpp
@@ -2867,6 +2867,42 @@ TEST_F(CollectionNestedFieldsTest, FloatInsideNestedObject) {
ASSERT_TRUE(add_op.ok());
}
+TEST_F(CollectionNestedFieldsTest, NestedFieldWithRegexName) {
+ nlohmann::json schema = R"({
+ "name": "coll1",
+ "enable_nested_fields": true,
+ "fields": [
+ {"name":"titles", "type":"object"},
+ {"name": "titles\\..*", "type":"string"},
+ {"name":"start_date", "type":"object"},
+ {"name":"start_date\\..*", "type":"int32", "facet":true, "optional":true}
+ ]
+ })"_json;
+
+ auto op = collectionManager.create_collection(schema);
+ ASSERT_TRUE(op.ok());
+ Collection *coll1 = op.get();
+
+ auto doc1 = R"({
+ "titles": {
+ "en": "Foobar baz"
+ },
+ "start_date": {
+ "year": 2020,
+ "month": 2,
+ "day": 3
+ }
+ })"_json;
+
+ auto add_op = coll1->add(doc1.dump(), CREATE);
+ ASSERT_TRUE(add_op.ok());
+
+ auto results = coll1->search("foobar", {"titles.en"}, "start_date.year: 2020", {}, {}, {2}, 10,
+ 1, FREQUENCY, {true}).get();
+
+ ASSERT_EQ(1, results["found"].get<size_t>());
+}
+
TEST_F(CollectionNestedFieldsTest, HighlightOnFlatFieldWithSnippeting) {
std::vector<field> fields = {field("title", field_types::STRING, false),
field("body", field_types::STRING, false)};