diff --git a/internal/form/search_photos_geo.go b/internal/form/search_photos_geo.go index 8c7ba1ad7..bf7cb0237 100644 --- a/internal/form/search_photos_geo.go +++ b/internal/form/search_photos_geo.go @@ -51,6 +51,8 @@ type SearchPhotosGeo struct { Album string `form:"album"` Albums string `form:"albums"` Country string `form:"country"` + State string `form:"state"` // Moments + City string `form:"city"` Year string `form:"year"` // Moments Month string `form:"month"` // Moments Day string `form:"day"` // Moments diff --git a/internal/search/photos_geo.go b/internal/search/photos_geo.go index cb62ff156..581fa6ee7 100644 --- a/internal/search/photos_geo.go +++ b/internal/search/photos_geo.go @@ -49,6 +49,7 @@ func PhotosGeo(f form.SearchPhotosGeo) (results GeoResults, err error) { s = s.Table("photos").Select(GeoCols). Joins(`JOIN files ON files.photo_id = photos.id AND files.file_primary = 1 AND files.media_id IS NOT NULL`). + Joins("LEFT JOIN places ON photos.place_id = places.id"). Where("photos.deleted_at IS NULL"). Where("photos.photo_lat <> 0") @@ -272,6 +273,16 @@ func PhotosGeo(f form.SearchPhotosGeo) (results GeoResults, err error) { s = s.Where("photos.photo_country IN (?)", SplitOr(strings.ToLower(f.Country))) } + // Filter by location state? + if txt.NotEmpty(f.State) { + s = s.Where("places.place_state IN (?)", SplitOr(f.State)) + } + + // Filter by location city? + if txt.NotEmpty(f.City) { + s = s.Where("places.place_city IN (?)", SplitOr(f.City)) + } + // Filter by media type? if txt.NotEmpty(f.Type) { s = s.Where("photos.photo_type IN (?)", SplitOr(strings.ToLower(f.Type))) diff --git a/internal/search/photos_geo_test.go b/internal/search/photos_geo_test.go index 88dece03d..1d51ee77c 100644 --- a/internal/search/photos_geo_test.go +++ b/internal/search/photos_geo_test.go @@ -517,6 +517,23 @@ func TestGeo(t *testing.T) { assert.Equal(t, 2, len(photos)) }) + t.Run("City", func(t *testing.T) { + var f form.SearchPhotosGeo + f.City = "Teotihuacán" + + // Parse query string and filter. + if err := f.ParseQueryString(); err != nil { + t.Fatal(err) + } + + photos, err := PhotosGeo(f) + + if err != nil { + t.Fatal(err) + } + + assert.Equal(t, 8, len(photos)) + }) t.Run("PathOrPath", func(t *testing.T) { var f form.SearchPhotosGeo f.Path = "1990/04" + "|" + "2015/11"