Search: Add altitude range filter (#3800)

* Add Altitude filters using IntRange

* Rename Altitude test
This commit is contained in:
Gilbert32 2023-10-20 12:23:20 +02:00 committed by GitHub
parent f32d62cfe1
commit 132237e47b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 44 additions and 0 deletions

View file

@ -48,6 +48,7 @@ type SearchPhotos struct {
Olc string `form:"olc" example:"olc:8FWCHX7W+" notes:"OLC Position (Open Location Code)"`
Lat float64 `form:"lat" example:"lat:41.894043" notes:"GPS Position (Latitude)"`
Lng float64 `form:"lng" example:"lng:-87.62448" notes:"GPS Position (Longitude)"`
Alt string `form:"alt" example:"alt:300-500" notes:"GPS Altitude Range"`
Dist float64 `form:"dist" example:"dist:50" notes:"Distance to Position (km)"`
Latlng string `form:"latlng" notes:"GPS Bounding Box (Lat N, Lng E, Lat S, Lng W)"`
Fmin float32 `form:"fmin" notes:"F-number (min)"`

View file

@ -47,6 +47,7 @@ type SearchPhotosGeo struct {
Lat float64 `form:"lat" example:"lat:41.894043" notes:"GPS Position (Latitude)"`
Lng float64 `form:"lng" example:"lng:-87.62448" notes:"GPS Position (Longitude)"`
Dist float64 `form:"dist" example:"dist:50" notes:"Distance to Position (km)"`
Alt string `form:"alt" example:"alt:300-500" notes:"GPS Altitude Range"`
Latlng string `form:"latlng" notes:"GPS Bounding Box (Lat N, Lng E, Lat S, Lng W)"`
Person string `form:"person"` // Alias for Subject
Subjects string `form:"subjects"` // Text

View file

@ -651,6 +651,17 @@ func TestParseQueryString(t *testing.T) {
assert.Equal(t, "cat", form.Lens)
})
t.Run("Altitude", func(t *testing.T) {
form := &SearchPhotos{Query: "alt:200-500"}
err := form.ParseQueryString()
if err != nil {
t.Fatal(err)
}
assert.Equal(t, "200-500", form.Alt)
})
t.Run("query for before with invalid type", func(t *testing.T) {
form := &SearchPhotos{Query: "before:cat"}

View file

@ -700,6 +700,11 @@ func searchPhotos(f form.SearchPhotos, sess *entity.Session, resultCols string)
s = s.Where("photos.photo_lng BETWEEN ? AND ?", lngW, lngE)
}
// Filter by GPS Altitude
if rangeStart, rangeEnd, rangeErr := txt.IntRange(f.Alt, 0, 1000000); rangeErr == nil {
s = s.Where("photos.photo_altitude >= ? AND photos.photo_altitude <= ?", rangeStart, rangeEnd)
}
// Find photos taken before date.
if !f.Before.IsZero() {
s = s.Where("photos.taken_at <= ?", f.Before.Format("2006-01-02"))

View file

@ -593,6 +593,11 @@ func UserPhotosGeo(f form.SearchPhotosGeo, sess *entity.Session) (results GeoRes
s = s.Where("photos.photo_lat BETWEEN ? AND ?", latS, latN)
}
// Filter by GPS Altitude
if rangeStart, rangeEnd, rangeErr := txt.IntRange(f.Alt, 0, 1000000); rangeErr == nil {
s = s.Where("photos.photo_altitude >= ? AND photos.photo_altitude <= ?", rangeStart, rangeEnd)
}
// Filter by GPS Longitude (from -180 to +180 degrees).
if lngE, lngW, lngErr := clean.GPSLngRange(f.Lng, f.Dist); lngErr == nil {
s = s.Where("photos.photo_lng BETWEEN ? AND ?", lngW, lngE)

View file

@ -172,6 +172,27 @@ func TestGeo(t *testing.T) {
assert.LessOrEqual(t, 3, len(result))
assert.IsType(t, GeoResults{}, result)
})
t.Run("search for min and max altitude", func(t *testing.T) {
f := form.SearchPhotosGeo{
Query: "",
Before: time.Time{},
After: time.Time{},
Favorite: "false",
Lat: 0,
Lng: 0,
S2: "",
Olc: "",
Dist: 0,
Alt: "200-500",
}
result, err := PhotosGeo(f)
if err != nil {
t.Fatal(err)
}
assert.IsType(t, GeoResults{}, result)
})
t.Run("search for s2", func(t *testing.T) {
f := form.SearchPhotosGeo{
Query: "",