Search: Allow searching for favorite:false to find other pictures

Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
Michael Mayer 2023-09-01 20:30:54 +02:00
parent afe2190797
commit 20d20c7fa9
7 changed files with 21 additions and 17 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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