diff --git a/internal/form/search_photos.go b/internal/form/search_photos.go index e33625e6c..3baec3f92 100644 --- a/internal/form/search_photos.go +++ b/internal/form/search_photos.go @@ -41,7 +41,7 @@ type SearchPhotos struct { Archived bool `form:"archived" notes:"Finds archived pictures"` Public bool `form:"public" notes:"Excludes private pictures"` Private bool `form:"private" notes:"Finds private pictures"` - Favorite bool `form:"favorite" notes:"Finds favorites only"` + Favorite string `form:"favorite" example:"favorite:yes" notes:"Finds favorites only"` Unsorted bool `form:"unsorted" notes:"Finds pictures not in an album"` Lat float32 `form:"lat" notes:"Latitude (GPS Position)"` Lng float32 `form:"lng" notes:"Longitude (GPS Position)"` diff --git a/internal/form/search_photos_geo.go b/internal/form/search_photos_geo.go index 31bce6da6..c8ff83bae 100644 --- a/internal/form/search_photos_geo.go +++ b/internal/form/search_photos_geo.go @@ -21,7 +21,7 @@ type SearchPhotosGeo struct { Title string `form:"title"` Before time.Time `form:"before" time_format:"2006-01-02"` After time.Time `form:"after" time_format:"2006-01-02"` - Favorite bool `form:"favorite"` + Favorite string `form:"favorite" example:"favorite:yes" notes:"Finds favorites only"` Unsorted bool `form:"unsorted"` Video bool `form:"video"` Vector bool `form:"vector"` diff --git a/internal/form/search_photos_geo_test.go b/internal/form/search_photos_geo_test.go index eb708bc4d..4cc905aae 100644 --- a/internal/form/search_photos_geo_test.go +++ b/internal/form/search_photos_geo_test.go @@ -193,7 +193,7 @@ func TestSearchPhotosGeo(t *testing.T) { t.Fatal(err) } - assert.True(t, form.Favorite) + assert.Equal(t, "cat", form.Favorite) }) t.Run("query for before with invalid type", func(t *testing.T) { form := &SearchPhotosGeo{Query: "before:cat"} @@ -242,13 +242,13 @@ func TestSearchPhotosGeo(t *testing.T) { } func TestSearchPhotosGeo_Serialize(t *testing.T) { - form := &SearchPhotosGeo{Query: "q:\"fooBar baz\"", Favorite: true} + form := &SearchPhotosGeo{Query: "q:\"fooBar baz\"", Favorite: "true"} assert.Equal(t, "q:\"q:fooBar baz\" favorite:true", form.Serialize()) } func TestSearchPhotosGeo_SerializeAll(t *testing.T) { - form := &SearchPhotosGeo{Query: "q:\"fooBar baz\"", Favorite: true} + form := &SearchPhotosGeo{Query: "q:\"fooBar baz\"", Favorite: "true"} assert.Equal(t, "q:\"q:fooBar baz\" favorite:true", form.SerializeAll()) } diff --git a/internal/form/search_photos_test.go b/internal/form/search_photos_test.go index c7678013f..dbc6d1254 100644 --- a/internal/form/search_photos_test.go +++ b/internal/form/search_photos_test.go @@ -120,7 +120,7 @@ func TestParseQueryString(t *testing.T) { assert.Equal(t, "fooBar baz", form.Query) assert.Equal(t, "23", form.Camera) assert.Equal(t, time.Date(2019, 01, 15, 0, 0, 0, 0, time.UTC), form.Before) - assert.Equal(t, false, form.Favorite) + assert.Equal(t, "false", form.Favorite) assert.Equal(t, uint(0x61a8), form.Dist) assert.Equal(t, float32(33.45343), form.Lat) }) @@ -190,7 +190,7 @@ func TestParseQueryString(t *testing.T) { t.Fatal(err) } - assert.True(t, form.Favorite) + assert.Equal(t, "cat", form.Favorite) }) t.Run("query for primary with uncommon bool value", func(t *testing.T) { form := &SearchPhotos{Query: "primary:&cat"} diff --git a/internal/search/photos.go b/internal/search/photos.go index 0d2a2fec8..6a7cf3040 100644 --- a/internal/search/photos.go +++ b/internal/search/photos.go @@ -300,7 +300,7 @@ func searchPhotos(f form.SearchPhotos, sess *entity.Session, resultCols string) f.Raw = true case terms["favorites"]: f.Query = strings.ReplaceAll(f.Query, "favorites", "") - f.Favorite = true + f.Favorite = "true" case terms["stacks"]: f.Query = strings.ReplaceAll(f.Query, "stacks", "") f.Stack = true @@ -478,8 +478,10 @@ func searchPhotos(f form.SearchPhotos, sess *entity.Session, resultCols string) s = s.Where("files.file_main_color IN (?)", SplitOr(strings.ToLower(f.Color))) } - // Find favorites only. - if f.Favorite { + // Filter by favorite flag. + if txt.No(f.Favorite) { + s = s.Where("photos.photo_favorite = 0") + } else if txt.NotEmpty(f.Favorite) { s = s.Where("photos.photo_favorite = 1") } diff --git a/internal/search/photos_geo.go b/internal/search/photos_geo.go index 44cc9c04c..aec070d0a 100644 --- a/internal/search/photos_geo.go +++ b/internal/search/photos_geo.go @@ -230,7 +230,7 @@ func UserPhotosGeo(f form.SearchPhotosGeo, sess *entity.Session) (results GeoRes f.Raw = true case terms["favorites"]: f.Query = strings.ReplaceAll(f.Query, "favorites", "") - f.Favorite = true + f.Favorite = "true" case terms["panoramas"]: f.Query = strings.ReplaceAll(f.Query, "panoramas", "") f.Panorama = true @@ -386,8 +386,10 @@ func UserPhotosGeo(f form.SearchPhotosGeo, sess *entity.Session) (results GeoRes s = s.Where("files.file_main_color IN (?)", SplitOr(strings.ToLower(f.Color))) } - // Find favorites only. - if f.Favorite { + // Filter by favorite flag. + if txt.No(f.Favorite) { + s = s.Where("photos.photo_favorite = 0") + } else if txt.NotEmpty(f.Favorite) { s = s.Where("photos.photo_favorite = 1") } diff --git a/internal/search/photos_geo_test.go b/internal/search/photos_geo_test.go index e05e2b34d..aaf26cff8 100644 --- a/internal/search/photos_geo_test.go +++ b/internal/search/photos_geo_test.go @@ -126,7 +126,7 @@ func TestGeo(t *testing.T) { Query: "", Before: time.Time{}, After: time.Time{}, - Favorite: true, + Favorite: "true", Lat: 1.234, Lng: 4.321, S2: "", @@ -154,7 +154,7 @@ func TestGeo(t *testing.T) { Query: "", Before: time.Time{}, After: time.Time{}, - Favorite: false, + Favorite: "false", Lat: 0, Lng: 0, S2: "", @@ -177,7 +177,7 @@ func TestGeo(t *testing.T) { Query: "", Before: time.Time{}, After: time.Time{}, - Favorite: false, + Favorite: "false", Lat: 0, Lng: 0, S2: "85", @@ -200,7 +200,7 @@ func TestGeo(t *testing.T) { Query: "", Before: time.Time{}, After: time.Time{}, - Favorite: false, + Favorite: "false", Lat: 0, Lng: 0, S2: "",