diff --git a/internal/search/like.go b/internal/search/like.go index f988c2906..d409ecf67 100644 --- a/internal/search/like.go +++ b/internal/search/like.go @@ -249,7 +249,7 @@ func OrLike(col, s string) (where string, values []interface{}) { values = make([]interface{}, len(terms)) for i := range terms { - values[i] = terms[i] + values[i] = strings.TrimSpace(terms[i]) } like := fmt.Sprintf("%s LIKE ?", col) diff --git a/internal/search/photos.go b/internal/search/photos.go index e950fa73f..6e0b21fc7 100644 --- a/internal/search/photos.go +++ b/internal/search/photos.go @@ -2,15 +2,16 @@ package search import ( "fmt" + "path" "strings" "time" "github.com/dustin/go-humanize/english" - "github.com/jinzhu/gorm" "github.com/photoprism/photoprism/internal/entity" "github.com/photoprism/photoprism/internal/form" + "github.com/photoprism/photoprism/pkg/fs" "github.com/photoprism/photoprism/pkg/rnd" "github.com/photoprism/photoprism/pkg/txt" ) @@ -370,13 +371,19 @@ func Photos(f form.PhotoSearch) (results PhotoResults, count int, err error) { } } - // Filter by main file name. + // Filter by primary file name without path and extension. if f.Name != "" { - where, values := OrLike("photos.photo_name", f.Name) - s = s.Where(where, values...) + where, names := OrLike("photos.photo_name", f.Name) + + // Omit file path and known extensions. + for i := range names { + names[i] = fs.StripKnownExt(path.Base(names[i].(string))) + } + + s = s.Where(where, names...) } - // Filter by actual file name. + // Filter by complete file names. if f.Filename != "" { where, values := OrLike("files.file_name", f.Filename) s = s.Where(where, values...) diff --git a/internal/search/photos_geo.go b/internal/search/photos_geo.go index 88a834a58..6dbf5f87e 100644 --- a/internal/search/photos_geo.go +++ b/internal/search/photos_geo.go @@ -2,15 +2,16 @@ package search import ( "fmt" + "path" "strings" "time" "github.com/dustin/go-humanize/english" - "github.com/jinzhu/gorm" "github.com/photoprism/photoprism/internal/entity" "github.com/photoprism/photoprism/internal/form" + "github.com/photoprism/photoprism/pkg/fs" "github.com/photoprism/photoprism/pkg/pluscode" "github.com/photoprism/photoprism/pkg/rnd" "github.com/photoprism/photoprism/pkg/s2" @@ -225,10 +226,16 @@ func PhotosGeo(f form.PhotoSearchGeo) (results GeoResults, err error) { } } - // Filter by main file name. + // Filter by primary file name without path and extension. if f.Name != "" { - where, values := OrLike("photos.photo_name", f.Name) - s = s.Where(where, values...) + where, names := OrLike("photos.photo_name", f.Name) + + // Omit file path and known extensions. + for i := range names { + names[i] = fs.StripKnownExt(path.Base(names[i].(string))) + } + + s = s.Where(where, names...) } // Filter by photo title.