People: Simplify "faces" search #22

This commit is contained in:
Michael Mayer 2021-05-26 10:46:32 +02:00
parent 5ecba4926a
commit 0d160fe833
6 changed files with 24 additions and 20 deletions

View file

@ -19,8 +19,7 @@ type GeoSearch struct {
Private bool `form:"private"`
Review bool `form:"review"`
Quality int `form:"quality"`
Faces int `form:"faces"` // Number of faces if detected
People string `form:"people"` // Find or exclude people if detected
Faces string `form:"faces"` // Find or exclude faces if detected.
Lat float32 `form:"lat"`
Lng float32 `form:"lng"`
S2 string `form:"s2"`

View file

@ -51,8 +51,7 @@ type PhotoSearch struct {
Month int `form:"month"` // Moments
Day int `form:"day"` // Moments
Color string `form:"color"`
Faces int `form:"faces"` // Number of faces if detected
People string `form:"people"` // Find or exclude people if detected
Faces string `form:"faces"` // Find or exclude faces if detected.
Quality int `form:"quality"`
Review bool `form:"review"`
Camera int `form:"camera"`

View file

@ -103,15 +103,12 @@ func Geo(f form.GeoSearch) (results GeoResults, err error) {
s = s.Where("photos.photo_day = ?", f.Day)
}
// Number of faces if detected.
if f.Faces > 0 {
s = s.Where("photos.photo_faces >= ?", f.Faces)
}
// Find or exclude people if detected.
if txt.Yes(f.People) {
if txt.IsUInt(f.Faces) {
s = s.Where("photos.photo_faces >= ?", txt.Int(f.Faces))
} else if txt.Yes(f.Faces) {
s = s.Where("photos.photo_faces > 0")
} else if txt.No(f.People) {
} else if txt.No(f.Faces) {
s = s.Where("photos.photo_faces = 0")
}

View file

@ -219,4 +219,16 @@ func TestGeo(t *testing.T) {
assert.IsType(t, GeoResults{}, result)
})
t.Run("faces", func(t *testing.T) {
var f form.GeoSearch
f.Query = "faces:true"
photos, err := Geo(f)
if err != nil {
t.Fatal(err)
}
assert.GreaterOrEqual(t, 3, len(photos))
})
}

View file

@ -212,15 +212,12 @@ func PhotoSearch(f form.PhotoSearch) (results PhotoResults, count int, err error
s = s.Where("photos.photo_day = ?", f.Day)
}
// Number of faces if detected.
if f.Faces > 0 {
s = s.Where("photos.photo_faces >= ?", f.Faces)
}
// Find or exclude people if detected.
if txt.Yes(f.People) {
if txt.IsUInt(f.Faces) {
s = s.Where("photos.photo_faces >= ?", txt.Int(f.Faces))
} else if txt.Yes(f.Faces) {
s = s.Where("photos.photo_faces > 0")
} else if txt.No(f.People) {
} else if txt.No(f.Faces) {
s = s.Where("photos.photo_faces = 0")
}

View file

@ -717,9 +717,9 @@ func TestPhotoSearch(t *testing.T) {
}
}
})
t.Run("people", func(t *testing.T) {
t.Run("faces", func(t *testing.T) {
var f form.PhotoSearch
f.Query = "people:true"
f.Query = "faces:true"
f.Count = 10
f.Offset = 0