Merge branch 'v0.26-facets' into event_anaylytics

This commit is contained in:
krunal 2023-12-01 15:39:02 +05:30
commit 52add3e742
4 changed files with 80 additions and 4 deletions

View File

@ -2202,9 +2202,9 @@ bool get_stopword(const std::shared_ptr<http_req>& req, const std::shared_ptr<ht
}
nlohmann::json res_json;
res_json["name"] = stopword_name;
res_json["id"] = stopword_name;
for(const auto& stopword : stopwords) {
res_json["value"].push_back(stopword);
res_json["stopwords"].push_back(stopword);
}
res->set_200(res_json.dump());

View File

@ -553,9 +553,11 @@ Option<bool> field::flatten_field(nlohmann::json& doc, nlohmann::json& obj, cons
return flatten_field(doc, it.value(), the_field, path_parts, path_index + 1, has_array, has_obj_array,
is_update, dyn_fields, flattened_fields);
}
} {
} else if(!the_field.optional) {
return Option<bool>(404, "Field `" + the_field.name + "` not found.");
}
return Option<bool>(true);
}
Option<bool> field::flatten_doc(nlohmann::json& document,

View File

@ -3105,6 +3105,81 @@ TEST_F(CollectionNestedFieldsTest, HighlightArrayOfObjects) {
ASSERT_EQ(1, results["hits"][0]["highlight"]["details"][2].size());
}
TEST_F(CollectionNestedFieldsTest, DeepNestedOptionalArrayValue) {
nlohmann::json schema = R"({
"name": "coll1",
"enable_nested_fields": true,
"fields": [
{
"facet": false,
"index": true,
"infix": false,
"locale": "",
"name": "items.name",
"optional": true,
"sort": false,
"type": "string[]"
},
{
"facet": false,
"index": true,
"infix": false,
"locale": "",
"name": "items.description",
"optional": true,
"sort": false,
"type": "string[]"
},
{
"facet": false,
"index": true,
"infix": false,
"locale": "",
"name": "items.nested_items.name",
"optional": true,
"sort": false,
"type": "string[]"
}
]
})"_json;
auto op = collectionManager.create_collection(schema);
ASSERT_TRUE(op.ok());
Collection* coll1 = op.get();
auto doc1 = R"({
"items": [
{
"description": "random description.",
"name": "foobar",
"nested_items": [
{
"isAvailable": true
},
{
"description": "nested description here",
"isAvailable": true,
"name": "naruto"
},
{
"description": "description again",
"isAvailable": true,
"name": "dragon ball"
}
]
}
]
})"_json;
auto add_op = coll1->add(doc1.dump(), CREATE);
ASSERT_TRUE(add_op.ok());
auto results = coll1->search("naruto", {"items.nested_items.name"}, "", {}, {}, {0}, 10, 1, FREQUENCY,
{true}, 1, spp::sparse_hash_set<std::string>(),
spp::sparse_hash_set<std::string>(), 10, "", 30, 4).get();
ASSERT_EQ(1, results["found"].get<size_t>());
}
TEST_F(CollectionNestedFieldsTest, FloatInsideNestedObject) {
nlohmann::json schema = R"({
"name": "coll1",

View File

@ -3122,7 +3122,6 @@ TEST_F(CollectionVectorTest, TryAddingMultipleImageFieldToEmbedFrom) {
ASSERT_EQ(collection_create_op.error(), "Only one field can be used in the `embed.from` property of an embed field when embedding from an image field.");
}
<<<<<<< Updated upstream
TEST_F(CollectionVectorTest, TestInvalidImage) {
auto schema_json =