Skip to content

Commit 39dc5cb

Browse files
committed
Search: Strip file path and extension when filtering by name
1 parent 7423380 commit 39dc5cb

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

internal/search/like.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ func OrLike(col, s string) (where string, values []interface{}) {
249249
values = make([]interface{}, len(terms))
250250

251251
for i := range terms {
252-
values[i] = terms[i]
252+
values[i] = strings.TrimSpace(terms[i])
253253
}
254254

255255
like := fmt.Sprintf("%s LIKE ?", col)

internal/search/photos.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@ package search
22

33
import (
44
"fmt"
5+
"path"
56
"strings"
67
"time"
78

89
"github.com/dustin/go-humanize/english"
9-
1010
"github.com/jinzhu/gorm"
1111

1212
"github.com/photoprism/photoprism/internal/entity"
1313
"github.com/photoprism/photoprism/internal/form"
14+
"github.com/photoprism/photoprism/pkg/fs"
1415
"github.com/photoprism/photoprism/pkg/rnd"
1516
"github.com/photoprism/photoprism/pkg/txt"
1617
)
@@ -370,13 +371,19 @@ func Photos(f form.PhotoSearch) (results PhotoResults, count int, err error) {
370371
}
371372
}
372373

373-
// Filter by main file name.
374+
// Filter by primary file name without path and extension.
374375
if f.Name != "" {
375-
where, values := OrLike("photos.photo_name", f.Name)
376-
s = s.Where(where, values...)
376+
where, names := OrLike("photos.photo_name", f.Name)
377+
378+
// Omit file path and known extensions.
379+
for i := range names {
380+
names[i] = fs.StripKnownExt(path.Base(names[i].(string)))
381+
}
382+
383+
s = s.Where(where, names...)
377384
}
378385

379-
// Filter by actual file name.
386+
// Filter by complete file names.
380387
if f.Filename != "" {
381388
where, values := OrLike("files.file_name", f.Filename)
382389
s = s.Where(where, values...)

internal/search/photos_geo.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@ package search
22

33
import (
44
"fmt"
5+
"path"
56
"strings"
67
"time"
78

89
"github.com/dustin/go-humanize/english"
9-
1010
"github.com/jinzhu/gorm"
1111

1212
"github.com/photoprism/photoprism/internal/entity"
1313
"github.com/photoprism/photoprism/internal/form"
14+
"github.com/photoprism/photoprism/pkg/fs"
1415
"github.com/photoprism/photoprism/pkg/pluscode"
1516
"github.com/photoprism/photoprism/pkg/rnd"
1617
"github.com/photoprism/photoprism/pkg/s2"
@@ -225,10 +226,16 @@ func PhotosGeo(f form.PhotoSearchGeo) (results GeoResults, err error) {
225226
}
226227
}
227228

228-
// Filter by main file name.
229+
// Filter by primary file name without path and extension.
229230
if f.Name != "" {
230-
where, values := OrLike("photos.photo_name", f.Name)
231-
s = s.Where(where, values...)
231+
where, names := OrLike("photos.photo_name", f.Name)
232+
233+
// Omit file path and known extensions.
234+
for i := range names {
235+
names[i] = fs.StripKnownExt(path.Base(names[i].(string)))
236+
}
237+
238+
s = s.Where(where, names...)
232239
}
233240

234241
// Filter by photo title.

0 commit comments

Comments
 (0)