mirror of
https://github.com/typesense/typesense.git
synced 2025-05-24 15:50:42 +08:00
Allow indexing of null values for auto/string* fields.
This commit is contained in:
parent
a365bf9677
commit
4a3d2cc209
@ -2272,6 +2272,13 @@ Option<bool> Collection::check_and_update_schema(nlohmann::json& document, const
|
||||
if(test_field_type == field_types::AUTO || field_types::is_string_or_array(test_field_type)) {
|
||||
parseable = field::get_type(kv.value(), field_type);
|
||||
if(!parseable) {
|
||||
|
||||
if(kv.value().is_null() && new_field.optional) {
|
||||
// null values are allowed only if field is optional
|
||||
kv++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if(dirty_values == DIRTY_VALUES::REJECT || dirty_values == DIRTY_VALUES::COERCE_OR_REJECT) {
|
||||
return Option<bool>(400, "Type of field `" + kv.key() + "` is invalid.");
|
||||
} else {
|
||||
|
@ -915,6 +915,36 @@ TEST_F(CollectionAllFieldsTest, DynamicFieldsMustOnlyBeOptional) {
|
||||
collectionManager.drop_collection("coll1");
|
||||
}
|
||||
|
||||
TEST_F(CollectionAllFieldsTest, AutoAndStringStarFieldsShouldAcceptNullValues) {
|
||||
Collection *coll1;
|
||||
|
||||
std::vector<field> fields = {
|
||||
field("foo", "string*", true, true),
|
||||
//field("buzz", "auto", true, true),
|
||||
field("bar.*", "string*", true, true),
|
||||
field("baz.*", "auto", true, true),
|
||||
};
|
||||
|
||||
coll1 = collectionManager.get_collection("coll1").get();
|
||||
if (coll1 == nullptr) {
|
||||
auto coll_op = collectionManager.create_collection("coll1", 1, fields, "", 0);
|
||||
ASSERT_TRUE(coll_op.ok());
|
||||
coll1 = coll_op.get();
|
||||
}
|
||||
|
||||
nlohmann::json doc;
|
||||
doc["foo"] = nullptr;
|
||||
//doc["buzz"] = nullptr;
|
||||
doc["bar_one"] = nullptr;
|
||||
doc["baz_one"] = nullptr;
|
||||
|
||||
// should allow indexing of null values since all are optional
|
||||
auto add_op = coll1->add(doc.dump(), CREATE);
|
||||
ASSERT_TRUE(add_op.ok());
|
||||
|
||||
collectionManager.drop_collection("coll1");
|
||||
}
|
||||
|
||||
TEST_F(CollectionAllFieldsTest, BothFallbackAndDynamicFields) {
|
||||
Collection *coll1;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user