Search: Add city and state search filter to geo search

This commit is contained in:
theresa 2022-09-05 15:35:02 +02:00
parent fd95e60bb9
commit 3ebd2119d7
3 changed files with 30 additions and 0 deletions

View file

@ -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

View file

@ -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)))

View file

@ -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"