Allow unindexed non-optional field in schema.

This commit is contained in:
Kishore Nallan 2023-09-24 16:38:49 +05:30
parent 2ef1b42d2d
commit 00be933b23
3 changed files with 25 additions and 5 deletions

View File

@ -367,10 +367,6 @@ struct field {
return Option<bool>(400, "Field `" + field.name + "` must be an optional field.");
}
if(!field.index && !field.optional) {
return Option<bool>(400, "Field `" + field.name + "` must be optional since it is marked as non-indexable.");
}
if(field.name == ".*" && !field.index) {
return Option<bool>(400, "Field `" + field.name + "` cannot be marked as non-indexable.");
}

View File

@ -1279,7 +1279,7 @@ TEST_F(CollectionAllFieldsTest, DoNotIndexFieldMarkedAsNonIndex) {
auto op = collectionManager.create_collection("coll2", 1, fields, "", 0, field_types::AUTO);
ASSERT_FALSE(op.ok());
ASSERT_EQ("Field `post` must be optional since it is marked as non-indexable.", op.error());
ASSERT_EQ("Field `.*_txt` cannot be a facet since it's marked as non-indexable.", op.error());
fields = {field("company_name", field_types::STRING, false),
field("num_employees", field_types::INT32, false),

View File

@ -1511,6 +1511,30 @@ TEST_F(CollectionNestedFieldsTest, UnindexedNestedFieldShouldNotClutterSchema) {
ASSERT_EQ(1, coll1->get_fields().size());
}
TEST_F(CollectionNestedFieldsTest, UnindexedNonOptionalFieldShouldBeAllowed) {
nlohmann::json schema = R"({
"name": "coll1",
"enable_nested_fields": true,
"fields": [
{"name": "block", "type": "object", "index": false}
]
})"_json;
auto op = collectionManager.create_collection(schema);
ASSERT_TRUE(op.ok());
Collection* coll1 = op.get();
auto doc1 = R"({
"block": {"text": "Hello world."}
})"_json;
auto add_op = coll1->add(doc1.dump(), CREATE);
ASSERT_TRUE(add_op.ok());
// child fields should not become part of schema
ASSERT_EQ(1, coll1->get_fields().size());
}
TEST_F(CollectionNestedFieldsTest, SortByNestedField) {
nlohmann::json schema = R"({
"name": "coll1",