mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-12-05 05:43:36 -05:00
refactor(kql): read a geo predicate without its field as free text
This commit is contained in:
1 parent
7b72225934
commit
69cc8e13ce
7 files changed
+821
-918
No files matched your search
@@ -104,9 +104,6 @@ GeoPropertyRestrictionNode <-
|
||||
} /
|
||||
k:Key (OperatorColonNode / OperatorEqualNode) "geo.polygon(" a:GeoArgs ")" {
|
||||
return buildGeoPolygonNode(k, a, c.text, c.pos)
|
||||
} /
|
||||
p:("geo.distance" / "geo.bbox" / "geo.polygon") "(" GeoArgs ")" {
|
||||
return rejectGeoPredicateWithoutField(p)
|
||||
}
|
||||
|
||||
GeoArgs <-
|
||||
|
||||
+815
-899
File diff suppressed because it is too large.
Load diff
@@ -306,11 +306,3 @@ func buildGeoPolygonNode(k, a any, text []byte, pos position) (*ast.GeoPolygonNo
|
||||
}
|
||||
return &ast.GeoPolygonNode{Base: b, Key: key, Points: points}, nil
|
||||
}
|
||||
|
||||
func rejectGeoPredicateWithoutField(p any) (ast.Node, error) {
|
||||
predicate, err := toString(p)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, geoErr(predicate, "must directly follow a field, as in location:%s(...)", predicate)
|
||||
}
|
||||
@@ -105,7 +105,5 @@ var _ = Describe("geo KQL predicates", func() {
|
||||
Entry("polygon repeating a point", "location:geo.polygon(1 2, 1 2, 3 4, 5 6)", `geo.polygon: repeats the point "1 2"`),
|
||||
Entry("polygon point without a lon", "location:geo.polygon(1, 2, 3)", `geo.polygon: point "1" must be 'lat lon'`),
|
||||
Entry("polygon longitude out of range", "location:geo.polygon(1 2, 3 181, 5 6)", `geo.polygon: longitude 181 is outside -180..180`),
|
||||
Entry("predicate without a field", "geo.distance(48.2, 16.37, 5km)", `geo.distance: must directly follow a field, as in location:geo.distance(...)`),
|
||||
Entry("predicate inside a keyed group", "location:(geo.bbox(1, 2, 3, 4))", `geo.bbox: must directly follow a field, as in location:geo.bbox(...)`),
|
||||
)
|
||||
})
|
||||
@@ -101,7 +101,7 @@ OpenCloud supports filtering on geopoint fields (currently `location`) with geo
|
||||
* `location:geo.bbox(minLat, minLon, maxLat, maxLon)` inside a bounding box
|
||||
* `location:geo.polygon(lat lon, lat lon, ...)` inside a polygon (at least three vertices)
|
||||
|
||||
A predicate has to follow its field directly. Latitudes outside -90..90, longitudes outside -180..180, a radius that is not greater than zero, a box without area and a polygon with fewer than three distinct points or a repeated point are rejected as a bad request.
|
||||
Latitudes outside -90..90, longitudes outside -180..180, a radius that is not greater than zero, a box without area and a polygon with fewer than three distinct points or a repeated point are rejected as a bad request.
|
||||
|
||||
### Quoting values
|
||||
|
||||
|
||||
@@ -540,8 +540,8 @@ Fixtures:
|
||||
| GEO-19 | `location:geo.bbox(47.9, 16.3738, 48.3, 16.3738)` | bad request | bad request | bad request | ✅ |
|
||||
| GEO-20 | `location:geo.polygon(48.3 16.1, 48.3 16.5, 48.3 16.1)` | bad request | bad request | bad request | ✅ |
|
||||
| GEO-21 | `location:geo.polygon(48.3 16.1, 48.3 16.1, 48.3 16.5, 47.9 16.5)` | bad request | bad request | bad request | ✅ |
|
||||
| GEO-22 | `geo.distance(48.2082, 16.3738, 5km)` | bad request | bad request | bad request | ✅ |
|
||||
| GEO-23 | `location:(geo.distance(48.2082, 16.3738, 5km))` | bad request | bad request | bad request | ✅ |
|
||||
| GEO-22 | `geo.distance(48.2082, 16.3738, 5km)` | no match | no match | no match | ✅ |
|
||||
| GEO-23 | `location:(geo.distance(48.2082, 16.3738, 5km))` | no match | no match | no match | ✅ |
|
||||
|
||||
### scope
|
||||
|
||||
|
||||
@@ -52,9 +52,9 @@ func geoGroup() queryGroup {
|
||||
{id: 19, query: `location:geo.bbox(47.9, 16.3738, 48.3, 16.3738)`, wantBadRequest: true},
|
||||
{id: 20, query: `location:geo.polygon(48.3 16.1, 48.3 16.5, 48.3 16.1)`, wantBadRequest: true},
|
||||
{id: 21, query: `location:geo.polygon(48.3 16.1, 48.3 16.1, 48.3 16.5, 47.9 16.5)`, wantBadRequest: true},
|
||||
// a predicate needs its field directly in front
|
||||
{id: 22, query: `geo.distance(48.2082, 16.3738, 5km)`, wantBadRequest: true},
|
||||
{id: 23, query: `location:(geo.distance(48.2082, 16.3738, 5km))`, wantBadRequest: true},
|
||||
// without its field in front a predicate is free text, like any other word
|
||||
{id: 22, query: `geo.distance(48.2082, 16.3738, 5km)`},
|
||||
{id: 23, query: `location:(geo.distance(48.2082, 16.3738, 5km))`},
|
||||
},
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user