Skip to content

Commit be0fdc1

Browse files
committed
Search: Add "scan:false" filter to find photos that are not scans #3589
Signed-off-by: Michael Mayer <michael@photoprism.app>
1 parent cb9d601 commit be0fdc1

File tree

7 files changed

+16
-13
lines changed

7 files changed

+16
-13
lines changed

internal/form/search_photos.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ type SearchPhotos struct {
3131
Photo bool `form:"photo" notes:"Finds only photos, no videos"`
3232
Raw bool `form:"raw" notes:"Finds pictures with RAW image file"`
3333
Live bool `form:"live" notes:"Finds Live Photos and short videos"`
34-
Scan bool `form:"scan" notes:"Finds scanned images and documents"`
34+
Scan string `form:"scan" example:"scan:true scan:false" notes:"Finds scanned photos and documents"`
3535
Panorama bool `form:"panorama" notes:"Finds pictures with an aspect ratio > 1.9:1"`
3636
Portrait bool `form:"portrait" notes:"Finds pictures in portrait format"`
3737
Landscape bool `form:"landscape" notes:"Finds pictures in landscape format"`

internal/form/search_photos_geo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ type SearchPhotosGeo struct {
2929
Photo bool `form:"photo"`
3030
Raw bool `form:"raw"`
3131
Live bool `form:"live"`
32-
Scan bool `form:"scan"`
32+
Scan string `form:"scan" example:"scan:true scan:false" notes:"Finds scanned photos and documents"`
3333
Panorama bool `form:"panorama"`
3434
Portrait bool `form:"portrait"`
3535
Landscape bool `form:"landscape"`

internal/form/search_photos_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ func TestParseQueryString(t *testing.T) {
311311
t.Fatal(err)
312312
}
313313

314-
assert.True(t, form.Scan)
314+
assert.Equal(t, ";cat", form.Scan)
315315
})
316316
t.Run("query for panorama with uncommon bool value", func(t *testing.T) {
317317
form := &SearchPhotos{Query: "panorama:*cat"}

internal/search/photos.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ func searchPhotos(f form.SearchPhotos, sess *entity.Session, resultCols string)
309309
f.Panorama = true
310310
case terms["scans"]:
311311
f.Query = strings.ReplaceAll(f.Query, "scans", "")
312-
f.Scan = true
312+
f.Scan = "true"
313313
case terms["monochrome"]:
314314
f.Query = strings.ReplaceAll(f.Query, "monochrome", "")
315315
f.Mono = true
@@ -483,8 +483,10 @@ func searchPhotos(f form.SearchPhotos, sess *entity.Session, resultCols string)
483483
s = s.Where("photos.photo_favorite = 1")
484484
}
485485

486-
// Find scans only.
487-
if f.Scan {
486+
// Filter by scan flag.
487+
if txt.No(f.Scan) {
488+
s = s.Where("photos.photo_scan = 0")
489+
} else if txt.NotEmpty(f.Scan) {
488490
s = s.Where("photos.photo_scan = 1")
489491
}
490492

internal/search/photos_geo.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ func UserPhotosGeo(f form.SearchPhotosGeo, sess *entity.Session) (results GeoRes
236236
f.Panorama = true
237237
case terms["scans"]:
238238
f.Query = strings.ReplaceAll(f.Query, "scans", "")
239-
f.Scan = true
239+
f.Scan = "true"
240240
case terms["monochrome"]:
241241
f.Query = strings.ReplaceAll(f.Query, "monochrome", "")
242242
f.Mono = true
@@ -391,8 +391,10 @@ func UserPhotosGeo(f form.SearchPhotosGeo, sess *entity.Session) (results GeoRes
391391
s = s.Where("photos.photo_favorite = 1")
392392
}
393393

394-
// Find scans only.
395-
if f.Scan {
394+
// Filter by scan flag.
395+
if txt.No(f.Scan) {
396+
s = s.Where("photos.photo_scan = 0")
397+
} else if txt.NotEmpty(f.Scan) {
396398
s = s.Where("photos.photo_scan = 1")
397399
}
398400

internal/search/photos_geo_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -777,11 +777,10 @@ func TestGeo(t *testing.T) {
777777

778778
assert.Equal(t, len(photos5), len(photos4))
779779
})
780-
781780
t.Run("f.Scan = true", func(t *testing.T) {
782781
var frm form.SearchPhotosGeo
783782

784-
frm.Scan = true
783+
frm.Scan = "true"
785784

786785
photos, err := PhotosGeo(frm)
787786

internal/search/photos_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -919,7 +919,7 @@ func TestPhotos(t *testing.T) {
919919
t.Run("search with multiple parameters", func(t *testing.T) {
920920
var f form.SearchPhotos
921921
f.Hidden = true
922-
f.Scan = true
922+
f.Scan = "true"
923923
f.Year = "2010"
924924
f.Day = "1"
925925
f.Photo = true
@@ -939,7 +939,7 @@ func TestPhotos(t *testing.T) {
939939
t.Run("search with multiple parameters", func(t *testing.T) {
940940
var f form.SearchPhotos
941941
f.Hidden = true
942-
f.Scan = true
942+
f.Scan = "true"
943943
f.Year = strconv.Itoa(2010)
944944
f.Day = strconv.Itoa(1)
945945
f.Video = true

0 commit comments

Comments
 (0)