Search: Remove obsolete "fmin" and "fmax" filters #3818

Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
Michael Mayer 2023-10-21 16:33:00 +02:00
parent 09f8a58404
commit c2b56346b6
7 changed files with 71 additions and 90 deletions

View file

@ -51,11 +51,15 @@ type SearchPhotos struct {
Alt string `form:"alt" example:"alt:300-500" notes:"GPS Altitude (m)"` Alt string `form:"alt" example:"alt:300-500" notes:"GPS Altitude (m)"`
Dist float64 `form:"dist" example:"dist:50" notes:"Distance to Position (km)"` Dist float64 `form:"dist" example:"dist:50" notes:"Distance to Position (km)"`
Latlng string `form:"latlng" notes:"GPS Bounding Box (Lat N, Lng E, Lat S, Lng W)"` Latlng string `form:"latlng" notes:"GPS Bounding Box (Lat N, Lng E, Lat S, Lng W)"`
Fmin float32 `form:"fmin" notes:"F-number (min)"` Camera string `form:"camera" example:"camera:canon" notes:"Camera Make/Model Name"` // Camera UID or name
Fmax float32 `form:"fmax" notes:"F-number (max)"` Lens string `form:"lens" example:"lens:ef24" notes:"Lens Make/Model Name"` // Lens UID or name
Iso string `form:"iso" example:"iso:200-400" notes:"ISO Number (light sensitivity)"`
Mm string `form:"mm" example:"mm:28-35" notes:"Focal Length (35mm equivalent)"`
F string `form:"f" example:"f:2.8-4.5" notes:"Aperture (f-number)"`
Color string `form:"color" example:"color:\"red|blue\"" notes:"Color Name (purple, magenta, pink, red, orange, gold, yellow, lime, green, teal, cyan, blue, brown, white, grey, black) (separate with |)"` // Main color
Chroma int16 `form:"chroma" example:"chroma:70" notes:"Chroma (0-100)"` Chroma int16 `form:"chroma" example:"chroma:70" notes:"Chroma (0-100)"`
Diff uint32 `form:"diff" notes:"Differential Perceptual Hash (000000-FFFFFF)"`
Mono bool `form:"mono" notes:"Finds pictures with few or no colors"` Mono bool `form:"mono" notes:"Finds pictures with few or no colors"`
Diff uint32 `form:"diff" notes:"Differential Perceptual Hash (000000-FFFFFF)"`
Geo string `form:"geo" example:"geo:yes" notes:"Finds pictures with or without coordinates"` Geo string `form:"geo" example:"geo:yes" notes:"Finds pictures with or without coordinates"`
Keywords string `form:"keywords" example:"keywords:\"sand&water\"" notes:"Keywords (combinable with & and |)"` Keywords string `form:"keywords" example:"keywords:\"sand&water\"" notes:"Keywords (combinable with & and |)"`
Label string `form:"label" example:"label:cat|dog" notes:"Label Names (separate with |)"` Label string `form:"label" example:"label:cat|dog" notes:"Label Names (separate with |)"`
@ -74,14 +78,8 @@ type SearchPhotos struct {
People string `form:"people" example:"people:\"Jane & John\"" notes:"Subject Names (combinable with & and |)"` // Alias for Subjects People string `form:"people" example:"people:\"Jane & John\"" notes:"Subject Names (combinable with & and |)"` // Alias for Subjects
Album string `form:"album" example:"album:berlin" notes:"Album UID or Name, supports * wildcards"` // Album UIDs or name Album string `form:"album" example:"album:berlin" notes:"Album UID or Name, supports * wildcards"` // Album UIDs or name
Albums string `form:"albums" example:"albums:\"South Africa & Birds\"" notes:"Album Names (combinable with & and |)"` // Multi search with and/or Albums string `form:"albums" example:"albums:\"South Africa & Birds\"" notes:"Album Names (combinable with & and |)"` // Multi search with and/or
Color string `form:"color" example:"color:\"red|blue\"" notes:"Color Name (purple, magenta, pink, red, orange, gold, yellow, lime, green, teal, cyan, blue, brown, white, grey, black) (separate with |)"` // Main color
Quality int `form:"quality" notes:"Minimum quality score (1-7)"` // Photo quality score Quality int `form:"quality" notes:"Minimum quality score (1-7)"` // Photo quality score
Review bool `form:"review" notes:"Finds pictures in review"` // Find photos in review Review bool `form:"review" notes:"Finds pictures in review"` // Find photos in review
Camera string `form:"camera" example:"camera:canon" notes:"Camera Make/Model Name"` // Camera UID or name
Lens string `form:"lens" example:"lens:ef24" notes:"Lens Make/Model Name"` // Lens UID or name
Iso string `form:"iso" example:"iso:200-400" notes:"ISO Number (light sensitivity)"`
Mm string `form:"mm" example:"mm:28-35" notes:"Focal Length (35mm equivalent)"`
F string `form:"f" example:"f:2.8-4.5" notes:"Aperture (f-number)"`
Before time.Time `form:"before" time_format:"2006-01-02" notes:"Finds pictures taken before this date"` // Finds images taken before date Before time.Time `form:"before" time_format:"2006-01-02" notes:"Finds pictures taken before this date"` // Finds images taken before date
After time.Time `form:"after" time_format:"2006-01-02" notes:"Finds pictures taken after this date"` // Finds images taken after date After time.Time `form:"after" time_format:"2006-01-02" notes:"Finds pictures taken after this date"` // Finds images taken after date
Count int `form:"count" binding:"required" serialize:"-"` // Result FILE limit Count int `form:"count" binding:"required" serialize:"-"` // Result FILE limit

View file

@ -49,11 +49,17 @@ type SearchPhotosGeo struct {
Alt string `form:"alt" example:"alt:300-500" notes:"GPS Altitude (m)"` Alt string `form:"alt" example:"alt:300-500" notes:"GPS Altitude (m)"`
Dist float64 `form:"dist" example:"dist:50" notes:"Distance to Position (km)"` Dist float64 `form:"dist" example:"dist:50" notes:"Distance to Position (km)"`
Latlng string `form:"latlng" notes:"GPS Bounding Box (Lat N, Lng E, Lat S, Lng W)"` Latlng string `form:"latlng" notes:"GPS Bounding Box (Lat N, Lng E, Lat S, Lng W)"`
Camera int `form:"camera"`
Lens int `form:"lens"`
Iso string `form:"iso" example:"iso:200-400" notes:"ISO Number (light sensitivity)"`
Mm string `form:"mm" example:"mm:28-35" notes:"Focal Length (35mm equivalent)"`
F string `form:"f" example:"f:2.8-4.5" notes:"Aperture (f-number)"`
Color string `form:"color"`
Chroma int16 `form:"chroma" example:"chroma:70" notes:"Chroma (0-100)"`
Mono bool `form:"mono" notes:"Finds pictures with few or no colors"`
Person string `form:"person"` // Alias for Subject Person string `form:"person"` // Alias for Subject
Subjects string `form:"subjects"` // Text Subjects string `form:"subjects"` // Text
People string `form:"people"` // Alias for Subjects People string `form:"people"` // Alias for Subjects
Chroma int16 `form:"chroma" example:"chroma:70" notes:"Chroma (0-100)"`
Mono bool `form:"mono" notes:"Finds pictures with few or no colors"`
Keywords string `form:"keywords" example:"keywords:\"sand&water\"" notes:"Keywords (combinable with & and |)"` Keywords string `form:"keywords" example:"keywords:\"sand&water\"" notes:"Keywords (combinable with & and |)"`
Label string `form:"label" example:"label:cat|dog" notes:"Label Names (separate with |)"` Label string `form:"label" example:"label:cat|dog" notes:"Label Names (separate with |)"`
Category string `form:"category" example:"category:airport" notes:"Location Category"` Category string `form:"category" example:"category:airport" notes:"Location Category"`
@ -65,12 +71,6 @@ type SearchPhotosGeo struct {
Year string `form:"year"` // Moments Year string `form:"year"` // Moments
Month string `form:"month"` // Moments Month string `form:"month"` // Moments
Day string `form:"day"` // Moments Day string `form:"day"` // Moments
Color string `form:"color"`
Camera int `form:"camera"`
Lens int `form:"lens"`
Iso string `form:"iso" example:"iso:200-400" notes:"ISO Number (light sensitivity)"`
Mm string `form:"mm" example:"mm:28-35" notes:"Focal Length (35mm equivalent)"`
F string `form:"f" example:"f:2.8-4.5" notes:"Aperture (f-number)"`
Count int `form:"count" serialize:"-"` Count int `form:"count" serialize:"-"`
Offset int `form:"offset" serialize:"-"` Offset int `form:"offset" serialize:"-"`
} }

View file

@ -544,31 +544,24 @@ func TestParseQueryString(t *testing.T) {
assert.Contains(t, err.Error(), "invalid syntax") assert.Contains(t, err.Error(), "invalid syntax")
}) })
t.Run("query for fmin with invalid type", func(t *testing.T) { t.Run("query for f with invalid type", func(t *testing.T) {
form := &SearchPhotos{Query: "fmin:=}cat{"} form := &SearchPhotos{Query: "f:=}cat{"}
err := form.ParseQueryString() err := form.ParseQueryString()
if err == nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
// log.Debugf("%+v\n", form)
assert.Contains(t, err.Error(), "invalid syntax")
}) })
t.Run("query for fmax with invalid type", func(t *testing.T) { t.Run("query for f with invalid type", func(t *testing.T) {
form := &SearchPhotos{Query: "fmax:ca#$t"} form := &SearchPhotos{Query: "f:ca#$t"}
err := form.ParseQueryString() err := form.ParseQueryString()
if err == nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
// log.Debugf("%+v\n", form)
assert.Contains(t, err.Error(), "invalid syntax")
}) })
t.Run("query for chroma with invalid type", func(t *testing.T) { t.Run("query for chroma with invalid type", func(t *testing.T) {
form := &SearchPhotos{Query: "chroma:&|cat"} form := &SearchPhotos{Query: "chroma:&|cat"}

View file

@ -23,11 +23,10 @@ type TestForm struct {
Lat float32 `form:"lat"` Lat float32 `form:"lat"`
Lng float32 `form:"lng"` Lng float32 `form:"lng"`
Dist uint `form:"dist"` Dist uint `form:"dist"`
Fmin float32 `form:"fmin"` Color string `form:"color"`
Fmax float32 `form:"fmax"`
Chroma int16 `form:"chroma"` Chroma int16 `form:"chroma"`
Diff uint32 `form:"diff"`
Mono bool `form:"mono"` Mono bool `form:"mono"`
Diff uint32 `form:"diff"`
Portrait bool `form:"portrait"` Portrait bool `form:"portrait"`
Location bool `form:"location"` Location bool `form:"location"`
Album string `form:"album"` Album string `form:"album"`
@ -35,7 +34,6 @@ type TestForm struct {
Country string `form:"country"` Country string `form:"country"`
Year int `form:"year"` Year int `form:"year"`
Month int `form:"month"` Month int `form:"month"`
Color string `form:"color"`
Quality int `form:"quality"` Quality int `form:"quality"`
Review bool `form:"review"` Review bool `form:"review"`
Camera int `form:"camera"` Camera int `form:"camera"`

View file

@ -529,6 +529,19 @@ func searchPhotos(f form.SearchPhotos, sess *entity.Session, resultCols string)
s = s.Where("files.file_main_color IN (?)", SplitOr(strings.ToLower(f.Color))) s = s.Where("files.file_main_color IN (?)", SplitOr(strings.ToLower(f.Color)))
} }
// Filter by chroma.
if f.Mono {
s = s.Where("files.file_chroma = 0")
} else if f.Chroma > 9 {
s = s.Where("files.file_chroma > ?", f.Chroma)
} else if f.Chroma > 0 {
s = s.Where("files.file_chroma > 0 AND files.file_chroma <= ?", f.Chroma)
}
if f.Diff != 0 {
s = s.Where("files.file_diff = ?", f.Diff)
}
// Filter by favorite flag. // Filter by favorite flag.
if txt.No(f.Favorite) { if txt.No(f.Favorite) {
s = s.Where("photos.photo_favorite = 0") s = s.Where("photos.photo_favorite = 0")
@ -652,27 +665,6 @@ func searchPhotos(f form.SearchPhotos, sess *entity.Session, resultCols string)
s = s.Where("files.file_hash IN (?)", SplitOr(strings.ToLower(f.Hash))) s = s.Where("files.file_hash IN (?)", SplitOr(strings.ToLower(f.Hash)))
} }
// Filter by chroma.
if f.Mono {
s = s.Where("files.file_chroma = 0")
} else if f.Chroma > 9 {
s = s.Where("files.file_chroma > ?", f.Chroma)
} else if f.Chroma > 0 {
s = s.Where("files.file_chroma > 0 AND files.file_chroma <= ?", f.Chroma)
}
if f.Diff != 0 {
s = s.Where("files.file_diff = ?", f.Diff)
}
if f.Fmin > 0 {
s = s.Where("photos.photo_f_number >= ?", f.Fmin)
}
if f.Fmax > 0 {
s = s.Where("photos.photo_f_number <= ?", f.Fmax)
}
// Filter by location code. // Filter by location code.
if txt.NotEmpty(f.S2) { if txt.NotEmpty(f.S2) {
// S2 Cell ID. // S2 Cell ID.

View file

@ -442,6 +442,15 @@ func UserPhotosGeo(f form.SearchPhotosGeo, sess *entity.Session) (results GeoRes
s = s.Where("files.file_main_color IN (?)", SplitOr(strings.ToLower(f.Color))) s = s.Where("files.file_main_color IN (?)", SplitOr(strings.ToLower(f.Color)))
} }
// Filter by chroma.
if f.Mono {
s = s.Where("files.file_chroma = 0")
} else if f.Chroma > 9 {
s = s.Where("files.file_chroma > ?", f.Chroma)
} else if f.Chroma > 0 {
s = s.Where("files.file_chroma > 0 AND files.file_chroma <= ?", f.Chroma)
}
// Filter by favorite flag. // Filter by favorite flag.
if txt.No(f.Favorite) { if txt.No(f.Favorite) {
s = s.Where("photos.photo_favorite = 0") s = s.Where("photos.photo_favorite = 0")
@ -562,15 +571,6 @@ func UserPhotosGeo(f form.SearchPhotosGeo, sess *entity.Session) (results GeoRes
} }
} }
// Filter by chroma.
if f.Mono {
s = s.Where("files.file_chroma = 0")
} else if f.Chroma > 9 {
s = s.Where("files.file_chroma > ?", f.Chroma)
} else if f.Chroma > 0 {
s = s.Where("files.file_chroma > 0 AND files.file_chroma <= ?", f.Chroma)
}
// Filter by location code. // Filter by location code.
if txt.NotEmpty(f.S2) { if txt.NotEmpty(f.S2) {
// S2 Cell ID. // S2 Cell ID.

View file

@ -606,9 +606,9 @@ func TestPhotos(t *testing.T) {
assert.LessOrEqual(t, 1, len(photos)) assert.LessOrEqual(t, 1, len(photos))
}) })
t.Run("form.fmin", func(t *testing.T) { t.Run("form.f", func(t *testing.T) {
var f form.SearchPhotos var f form.SearchPhotos
f.Query = "Fmin:5" f.Query = "F:5-100"
f.Count = 10 f.Count = 10
f.Offset = 0 f.Offset = 0
f.Order = "oldest" f.Order = "oldest"
@ -621,9 +621,9 @@ func TestPhotos(t *testing.T) {
assert.LessOrEqual(t, 1, len(photos)) assert.LessOrEqual(t, 1, len(photos))
}) })
t.Run("form.fmax", func(t *testing.T) { t.Run("form.f", func(t *testing.T) {
var f form.SearchPhotos var f form.SearchPhotos
f.Query = "Fmax:2" f.Query = "F:0-2"
f.Count = 10 f.Count = 10
f.Offset = 0 f.Offset = 0
f.Order = "newest" f.Order = "newest"