Search: Use photo title as fallback #1517 #1560

This commit is contained in:
Michael Mayer 2021-09-29 22:57:26 +02:00
parent d4765ea947
commit a3e8457ad5
3 changed files with 15 additions and 14 deletions

View File

@ -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"`

View File

@ -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 {

View File

@ -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")