mirror of
https://github.com/typesense/typesense.git
synced 2025-05-20 05:32:30 +08:00
Allow unindexed non-optional field in schema.
This commit is contained in:
parent
2ef1b42d2d
commit
00be933b23
@ -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.");
|
||||
}
|
||||
|
@ -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),
|
||||
|
@ -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",
|
||||
|
Loading…
x
Reference in New Issue
Block a user