Ignore explicit wildcard named field.

This commit is contained in:
Kishore Nallan 2022-05-28 19:00:06 +05:30
parent cf3b28bb77
commit fa607f0013
2 changed files with 19 additions and 3 deletions

View File

@ -2996,6 +2996,7 @@ Option<bool> Collection::detect_new_fields(nlohmann::json& document,
bool parseable;
bool found_dynamic_field = false;
bool skip_field = false;
// check against dynamic field definitions
for(const auto& dynamic_field: dyn_fields) {
@ -3003,7 +3004,8 @@ Option<bool> Collection::detect_new_fields(nlohmann::json& document,
// unless the field is auto or string*, ignore field name matching regexp pattern
if(kv.key() == dynamic_field.first && !dynamic_field.second.is_auto() &&
!dynamic_field.second.is_string_star()) {
continue;
skip_field = true;
break;
}
new_field = dynamic_field.second;
@ -3013,6 +3015,11 @@ Option<bool> Collection::detect_new_fields(nlohmann::json& document,
}
}
if(skip_field) {
kv++;
continue;
}
if(!found_dynamic_field && fallback_field_type.empty()) {
// we will not auto detect schema for non-dynamic fields if auto detection is not enabled
kv++;
@ -3035,6 +3042,11 @@ Option<bool> Collection::detect_new_fields(nlohmann::json& document,
const std::string& test_field_type = found_dynamic_field ? new_field.type : fallback_field_type;
if(test_field_type == field_types::AUTO || field_types::is_string_or_array(test_field_type)) {
if(kv.key() == ".*") {
kv++;
continue;
}
parseable = field::get_type(kv.value(), field_type);
if(!parseable) {

View File

@ -1507,23 +1507,27 @@ TEST_F(CollectionAllFieldsTest, SchemaUpdateShouldBeAtomicForAllFields) {
}
TEST_F(CollectionAllFieldsTest, FieldNameMatchingRegexpShouldNotBeIndexed) {
std::vector<field> fields = {field("title", field_types::STRING, false),
std::vector<field> fields = {field(".*", field_types::AUTO, false, true),
field("title", field_types::STRING, false),
field("name.*", field_types::STRING, true, true)};
Collection* coll1 = collectionManager.create_collection("coll1", 1, fields).get();
Collection* coll1 = collectionManager.create_collection("coll1", 1, fields, "", 0, field_types::AUTO).get();
nlohmann::json doc1;
doc1["id"] = "0";
doc1["title"] = "One Two Three";
doc1["name.*"] = "Rowling";
doc1[".*"] = "foo";
std::vector<std::string> json_lines;
json_lines.push_back(doc1.dump());
coll1->add_many(json_lines, doc1, UPSERT);
json_lines[0] = doc1.dump();
coll1->add_many(json_lines, doc1, UPSERT);
ASSERT_EQ(1, coll1->_get_index()->_get_search_index().size());
ASSERT_EQ(3, coll1->get_fields().size());
auto results = coll1->search("one", {"title"},
"", {}, {}, {2}, 10,