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

Allow unindexed non-optional field in schema.

Kishore Nallan00be933b234e
diff --git a/include/field.h b/include/field.h
index 9798e814..ccdb8784 100644
--- a/include/field.h
+++ b/include/field.h
@@ -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.");
}
diff --git a/test/collection_all_fields_test.cpp b/test/collection_all_fields_test.cpp
index 2dc8dd04..08d02490 100644
--- a/test/collection_all_fields_test.cpp
+++ b/test/collection_all_fields_test.cpp
@@ -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),
diff --git a/test/collection_nested_fields_test.cpp b/test/collection_nested_fields_test.cpp
index 88002d4c..f92f7e0b 100644
--- a/test/collection_nested_fields_test.cpp
+++ b/test/collection_nested_fields_test.cpp
@@ -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",