Skip to content

Commit

Permalink
Search: Strip file path and extension when filtering by name
Browse files Browse the repository at this point in the history
  • Loading branch information
lastzero committed Oct 1, 2021
1 parent 7423380 commit 39dc5cb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
2 changes: 1 addition & 1 deletion internal/search/like.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 12 additions & 5 deletions internal/search/photos.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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...)
Expand Down
15 changes: 11 additions & 4 deletions internal/search/photos_geo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 39dc5cb

Please sign in to comment.