Search: Strip file path and extension when filtering by name
This commit is contained in:
parent
74233809b9
commit
39dc5cb777
|
@ -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)
|
||||
|
|
|
@ -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)))
|
||||
}
|
||||
|
||||
// Filter by actual file name.
|
||||
s = s.Where(where, names...)
|
||||
}
|
||||
|
||||
// Filter by complete file names.
|
||||
if f.Filename != "" {
|
||||
where, values := OrLike("files.file_name", f.Filename)
|
||||
s = s.Where(where, values...)
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue
Block a user