Skip to content

Commit

Permalink
Search: Add "scan:false" filter to find photos that are not scans #3589
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Mayer <michael@photoprism.app>
  • Loading branch information
lastzero committed Aug 16, 2023
1 parent cb9d601 commit be0fdc1
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion internal/form/search_photos.go
Expand Up @@ -31,7 +31,7 @@ type SearchPhotos struct {
Photo bool `form:"photo" notes:"Finds only photos, no videos"`
Raw bool `form:"raw" notes:"Finds pictures with RAW image file"`
Live bool `form:"live" notes:"Finds Live Photos and short videos"`
Scan bool `form:"scan" notes:"Finds scanned images and documents"`
Scan string `form:"scan" example:"scan:true scan:false" notes:"Finds scanned photos and documents"`
Panorama bool `form:"panorama" notes:"Finds pictures with an aspect ratio > 1.9:1"`
Portrait bool `form:"portrait" notes:"Finds pictures in portrait format"`
Landscape bool `form:"landscape" notes:"Finds pictures in landscape format"`
Expand Down
2 changes: 1 addition & 1 deletion internal/form/search_photos_geo.go
Expand Up @@ -29,7 +29,7 @@ type SearchPhotosGeo struct {
Photo bool `form:"photo"`
Raw bool `form:"raw"`
Live bool `form:"live"`
Scan bool `form:"scan"`
Scan string `form:"scan" example:"scan:true scan:false" notes:"Finds scanned photos and documents"`
Panorama bool `form:"panorama"`
Portrait bool `form:"portrait"`
Landscape bool `form:"landscape"`
Expand Down
2 changes: 1 addition & 1 deletion internal/form/search_photos_test.go
Expand Up @@ -311,7 +311,7 @@ func TestParseQueryString(t *testing.T) {
t.Fatal(err)
}

assert.True(t, form.Scan)
assert.Equal(t, ";cat", form.Scan)
})
t.Run("query for panorama with uncommon bool value", func(t *testing.T) {
form := &SearchPhotos{Query: "panorama:*cat"}
Expand Down
8 changes: 5 additions & 3 deletions internal/search/photos.go
Expand Up @@ -309,7 +309,7 @@ func searchPhotos(f form.SearchPhotos, sess *entity.Session, resultCols string)
f.Panorama = true
case terms["scans"]:
f.Query = strings.ReplaceAll(f.Query, "scans", "")
f.Scan = true
f.Scan = "true"
case terms["monochrome"]:
f.Query = strings.ReplaceAll(f.Query, "monochrome", "")
f.Mono = true
Expand Down Expand Up @@ -483,8 +483,10 @@ func searchPhotos(f form.SearchPhotos, sess *entity.Session, resultCols string)
s = s.Where("photos.photo_favorite = 1")
}

// Find scans only.
if f.Scan {
// Filter by scan flag.
if txt.No(f.Scan) {
s = s.Where("photos.photo_scan = 0")
} else if txt.NotEmpty(f.Scan) {
s = s.Where("photos.photo_scan = 1")
}

Expand Down
8 changes: 5 additions & 3 deletions internal/search/photos_geo.go
Expand Up @@ -236,7 +236,7 @@ func UserPhotosGeo(f form.SearchPhotosGeo, sess *entity.Session) (results GeoRes
f.Panorama = true
case terms["scans"]:
f.Query = strings.ReplaceAll(f.Query, "scans", "")
f.Scan = true
f.Scan = "true"
case terms["monochrome"]:
f.Query = strings.ReplaceAll(f.Query, "monochrome", "")
f.Mono = true
Expand Down Expand Up @@ -391,8 +391,10 @@ func UserPhotosGeo(f form.SearchPhotosGeo, sess *entity.Session) (results GeoRes
s = s.Where("photos.photo_favorite = 1")
}

// Find scans only.
if f.Scan {
// Filter by scan flag.
if txt.No(f.Scan) {
s = s.Where("photos.photo_scan = 0")
} else if txt.NotEmpty(f.Scan) {
s = s.Where("photos.photo_scan = 1")
}

Expand Down
3 changes: 1 addition & 2 deletions internal/search/photos_geo_test.go
Expand Up @@ -777,11 +777,10 @@ func TestGeo(t *testing.T) {

assert.Equal(t, len(photos5), len(photos4))
})

t.Run("f.Scan = true", func(t *testing.T) {
var frm form.SearchPhotosGeo

frm.Scan = true
frm.Scan = "true"

photos, err := PhotosGeo(frm)

Expand Down
4 changes: 2 additions & 2 deletions internal/search/photos_test.go
Expand Up @@ -919,7 +919,7 @@ func TestPhotos(t *testing.T) {
t.Run("search with multiple parameters", func(t *testing.T) {
var f form.SearchPhotos
f.Hidden = true
f.Scan = true
f.Scan = "true"
f.Year = "2010"
f.Day = "1"
f.Photo = true
Expand All @@ -939,7 +939,7 @@ func TestPhotos(t *testing.T) {
t.Run("search with multiple parameters", func(t *testing.T) {
var f form.SearchPhotos
f.Hidden = true
f.Scan = true
f.Scan = "true"
f.Year = strconv.Itoa(2010)
f.Day = strconv.Itoa(1)
f.Video = true
Expand Down

0 comments on commit be0fdc1

Please sign in to comment.