From a3e8457ad524a130a156f9b2b3ded55e32a73316 Mon Sep 17 00:00:00 2001 From: Michael Mayer Date: Wed, 29 Sep 2021 22:57:26 +0200 Subject: [PATCH] Search: Use photo title as fallback #1517 #1560 --- internal/form/photo_search_geo.go | 1 + internal/search/photos.go | 11 ++++------- internal/search/photos_geo.go | 17 ++++++++++------- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/internal/form/photo_search_geo.go b/internal/form/photo_search_geo.go index d3ec90ac0..0ecfe97a6 100644 --- a/internal/form/photo_search_geo.go +++ b/internal/form/photo_search_geo.go @@ -9,6 +9,7 @@ type PhotoSearchGeo struct { Path string `form:"path"` Folder string `form:"folder"` // Alias for Path Name string `form:"name"` + 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"` diff --git a/internal/search/photos.go b/internal/search/photos.go index 21a3c8be0..f1192f92a 100644 --- a/internal/search/photos.go +++ b/internal/search/photos.go @@ -5,13 +5,11 @@ import ( "strings" "time" - "github.com/photoprism/photoprism/pkg/rnd" - - "github.com/photoprism/photoprism/pkg/fs" - "github.com/jinzhu/gorm" + "github.com/photoprism/photoprism/internal/entity" "github.com/photoprism/photoprism/internal/form" + "github.com/photoprism/photoprism/pkg/rnd" "github.com/photoprism/photoprism/pkg/txt" ) @@ -139,9 +137,8 @@ func Photos(f form.PhotoSearch) (results PhotoResults, count int, err error) { // Set search filters based on search terms. if terms := txt.SearchTerms(f.Query); f.Query != "" && len(terms) == 0 { - if f.Name == "" { - name := strings.Trim(fs.StripKnownExt(f.Query), "%*") - f.Name = fmt.Sprintf("%s*|%s*", name, strings.ToUpper(name)) + if f.Title == "" { + f.Title = fmt.Sprintf("%s*", strings.Trim(f.Query, "%*")) f.Query = "" } } else if len(terms) > 0 { diff --git a/internal/search/photos_geo.go b/internal/search/photos_geo.go index 5a025d11c..2193fda25 100644 --- a/internal/search/photos_geo.go +++ b/internal/search/photos_geo.go @@ -5,14 +5,12 @@ import ( "strings" "time" - "github.com/photoprism/photoprism/pkg/rnd" - - "github.com/photoprism/photoprism/pkg/fs" - "github.com/jinzhu/gorm" + "github.com/photoprism/photoprism/internal/entity" "github.com/photoprism/photoprism/internal/form" "github.com/photoprism/photoprism/pkg/pluscode" + "github.com/photoprism/photoprism/pkg/rnd" "github.com/photoprism/photoprism/pkg/s2" "github.com/photoprism/photoprism/pkg/txt" ) @@ -43,9 +41,8 @@ func PhotosGeo(f form.PhotoSearchGeo) (results GeoResults, err error) { // Set search filters based on search terms. if terms := txt.SearchTerms(f.Query); f.Query != "" && len(terms) == 0 { - if f.Name == "" { - name := strings.Trim(fs.StripKnownExt(f.Query), "%*") - f.Name = fmt.Sprintf("%s*|%s*", name, strings.ToUpper(name)) + if f.Title == "" { + f.Title = fmt.Sprintf("%s*", strings.Trim(f.Query, "%*")) f.Query = "" } } else if len(terms) > 0 { @@ -232,6 +229,12 @@ func PhotosGeo(f form.PhotoSearchGeo) (results GeoResults, err error) { s = s.Where(where, values...) } + // Filter by photo title. + if f.Title != "" { + where, values := OrLike("photos.photo_title", f.Title) + s = s.Where(where, values...) + } + // Filter by status. if f.Archived { s = s.Where("photos.photo_quality > -1")