mirror of
https://github.com/typesense/typesense.git
synced 2025-05-16 19:55:21 +08:00
geopoint[]
field inside an object[]
should be treated as geopoint
. (#2116)
This commit is contained in:
parent
2b1c4f7c24
commit
49d746deba
@ -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",
|
||||
|
Loading…
x
Reference in New Issue
Block a user