geopoint[] field inside an object[] should be treated as geopoint. ()

This commit is contained in:
Harpreet Sangar 2024-12-19 21:17:06 +05:30 committed by GitHub
parent 2b1c4f7c24
commit 49d746deba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 33 additions and 1 deletions

@ -6614,7 +6614,9 @@ void Index::remove_field(uint32_t seq_id, nlohmann::json& document, const std::s
options.set_index_contains_points_only(true);
S2RegionTermIndexer indexer(options);
const std::vector<std::vector<double>>& latlongs = search_field.is_single_geopoint() ?
// Geopoint field that is part of an object array will be marked as `geopoint[]` type, but it should be treated
// as a `geopoint` type.
const std::vector<std::vector<double>>& latlongs = search_field.is_single_geopoint() || search_field.nested_array ?
std::vector<std::vector<double>>{document[field_name].get<std::vector<double>>()} :
document[field_name].get<std::vector<std::vector<double>>>();

@ -2064,6 +2064,36 @@ TEST_F(CollectionNestedFieldsTest, NestedFieldWithGeopointArray) {
ASSERT_EQ("Field `addresses.geoPoint` must be an array of geopoint.", create_op.error());
}
TEST_F(CollectionNestedFieldsTest, ObjectArrayWithGeopoint) {
nlohmann::json schema = R"({
"name": "coll1",
"enable_nested_fields": true,
"fields": [
{"name": "addresses", "type": "object[]"},
{"name": "addresses.geoPoint", "type": "geopoint[]"}
]
})"_json;
auto op = collectionManager.create_collection(schema);
ASSERT_TRUE(op.ok());
Collection* coll1 = op.get();
auto doc1 = R"({"addresses": [{"geoPoint": [19.07283, 72.88261]}] })"_json;
auto add_op = coll1->add(doc1.dump(), CREATE);
ASSERT_TRUE(add_op.ok());
auto results = coll1->search("*", {}, "addresses.geoPoint: (19.07, 72.882, 1 mi)",
{}, {}, {0}, 10, 1, FREQUENCY).get();
ASSERT_EQ(1, results["found"]);
auto remove_op = coll1->remove("0");
ASSERT_TRUE(remove_op.ok());
results = coll1->search("*", {}, "addresses.geoPoint: (19.07, 72.882, 1 mi)",
{}, {}, {0}, 10, 1, FREQUENCY).get();
ASSERT_EQ(0, results["found"]);
}
TEST_F(CollectionNestedFieldsTest, NestedFieldWithGeopoint) {
nlohmann::json schema = R"({
"name": "coll1",