2020-01-15 04:04:33 +01:00
|
|
|
package form
|
|
|
|
|
2022-08-31 16:22:28 +02:00
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/photoprism/photoprism/pkg/fs"
|
|
|
|
)
|
2020-01-15 04:04:33 +01:00
|
|
|
|
2022-04-14 08:39:52 +02:00
|
|
|
// SearchPhotosGeo represents search form fields for "/api/v1/geo".
|
|
|
|
type SearchPhotosGeo struct {
|
2022-04-13 09:48:51 +02:00
|
|
|
Query string `form:"q"`
|
2022-09-30 19:15:10 +02:00
|
|
|
Scope string `form:"s" serialize:"-" example:"s:ariqwb43p5dh9h13" notes:"Limits the results to one album or another scope, if specified"`
|
2022-09-30 00:42:19 +02:00
|
|
|
Filter string `form:"filter" serialize:"-" notes:"-"`
|
|
|
|
UID string `form:"uid" example:"uid:pqbcf5j446s0futy" notes:"Search for specific files or photos, only exact matches"`
|
2022-04-13 09:48:51 +02:00
|
|
|
Near string `form:"near"`
|
|
|
|
Type string `form:"type"`
|
|
|
|
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"`
|
|
|
|
Unsorted bool `form:"unsorted"`
|
|
|
|
Video bool `form:"video"`
|
2022-04-14 08:39:52 +02:00
|
|
|
Vector bool `form:"vector"`
|
|
|
|
Animated bool `form:"animated"`
|
2022-04-13 09:48:51 +02:00
|
|
|
Photo bool `form:"photo"`
|
|
|
|
Raw bool `form:"raw"`
|
|
|
|
Live bool `form:"live"`
|
|
|
|
Scan bool `form:"scan"`
|
|
|
|
Panorama bool `form:"panorama"`
|
|
|
|
Portrait bool `form:"portrait"`
|
|
|
|
Landscape bool `form:"landscape"`
|
|
|
|
Square bool `form:"square"`
|
|
|
|
Archived bool `form:"archived"`
|
|
|
|
Public bool `form:"public"`
|
|
|
|
Private bool `form:"private"`
|
|
|
|
Review bool `form:"review"`
|
|
|
|
Quality int `form:"quality"`
|
|
|
|
Faces string `form:"faces"` // Find or exclude faces if detected.
|
|
|
|
Lat float32 `form:"lat"`
|
|
|
|
Lng float32 `form:"lng"`
|
|
|
|
S2 string `form:"s2"`
|
|
|
|
Olc string `form:"olc"`
|
|
|
|
Dist uint `form:"dist"`
|
|
|
|
Face string `form:"face"` // UIDs
|
|
|
|
Subject string `form:"subject"` // UIDs
|
|
|
|
Person string `form:"person"` // Alias for Subject
|
|
|
|
Subjects string `form:"subjects"` // Text
|
|
|
|
People string `form:"people"` // Alias for Subjects
|
|
|
|
Keywords string `form:"keywords"`
|
2022-09-30 00:42:19 +02:00
|
|
|
Album string `form:"album" example:"album:berlin" notes:"Album UID or Name, supports * wildcards"`
|
|
|
|
Albums string `form:"albums" example:"albums:\"South Africa & Birds\"" notes:"Album Names, can be combined with & and |"`
|
2022-04-13 09:48:51 +02:00
|
|
|
Country string `form:"country"`
|
2022-09-05 15:35:02 +02:00
|
|
|
State string `form:"state"` // Moments
|
|
|
|
City string `form:"city"`
|
2022-04-13 09:48:51 +02:00
|
|
|
Year string `form:"year"` // Moments
|
|
|
|
Month string `form:"month"` // Moments
|
|
|
|
Day string `form:"day"` // Moments
|
|
|
|
Color string `form:"color"`
|
|
|
|
Camera int `form:"camera"`
|
|
|
|
Lens int `form:"lens"`
|
|
|
|
Count int `form:"count" serialize:"-"`
|
|
|
|
Offset int `form:"offset" serialize:"-"`
|
2020-01-15 04:04:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetQuery returns the query parameter as string.
|
2022-04-14 08:39:52 +02:00
|
|
|
func (f *SearchPhotosGeo) GetQuery() string {
|
2020-01-15 04:04:33 +01:00
|
|
|
return f.Query
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetQuery sets the query parameter.
|
2022-04-14 08:39:52 +02:00
|
|
|
func (f *SearchPhotosGeo) SetQuery(q string) {
|
2020-01-15 04:04:33 +01:00
|
|
|
f.Query = q
|
|
|
|
}
|
|
|
|
|
|
|
|
// ParseQueryString parses the query parameter if possible.
|
2022-04-14 08:39:52 +02:00
|
|
|
func (f *SearchPhotosGeo) ParseQueryString() error {
|
2020-05-23 20:58:58 +02:00
|
|
|
err := ParseQueryString(f)
|
|
|
|
|
2022-08-01 15:57:19 +02:00
|
|
|
if f.Path != "" {
|
|
|
|
f.Folder = ""
|
|
|
|
} else if f.Folder != "" {
|
2020-05-23 20:58:58 +02:00
|
|
|
f.Path = f.Folder
|
2021-09-20 12:36:59 +02:00
|
|
|
f.Folder = ""
|
2020-05-23 20:58:58 +02:00
|
|
|
}
|
|
|
|
|
2022-08-01 15:57:19 +02:00
|
|
|
if f.Subject != "" {
|
|
|
|
f.Person = ""
|
|
|
|
} else if f.Person != "" {
|
2021-09-20 12:36:59 +02:00
|
|
|
f.Subject = f.Person
|
|
|
|
f.Person = ""
|
|
|
|
}
|
|
|
|
|
2022-08-01 15:57:19 +02:00
|
|
|
if f.Subjects != "" {
|
|
|
|
f.People = ""
|
|
|
|
} else if f.People != "" {
|
2021-08-29 16:16:49 +02:00
|
|
|
f.Subjects = f.People
|
2021-09-20 12:36:59 +02:00
|
|
|
f.People = ""
|
2021-08-29 16:16:49 +02:00
|
|
|
}
|
|
|
|
|
2022-01-03 12:51:59 +01:00
|
|
|
if f.Filter != "" {
|
|
|
|
if err := Unserialize(f, f.Filter); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-31 16:22:28 +02:00
|
|
|
// Strip file extensions if any.
|
|
|
|
if f.Name != "" {
|
|
|
|
f.Name = fs.StripKnownExt(f.Name)
|
|
|
|
}
|
|
|
|
|
2020-05-23 20:58:58 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Serialize returns a string containing non-empty fields and values of a struct.
|
2022-04-14 08:39:52 +02:00
|
|
|
func (f *SearchPhotosGeo) Serialize() string {
|
2020-05-23 20:58:58 +02:00
|
|
|
return Serialize(f, false)
|
|
|
|
}
|
|
|
|
|
|
|
|
// SerializeAll returns a string containing all non-empty fields and values of a struct.
|
2022-04-14 08:39:52 +02:00
|
|
|
func (f *SearchPhotosGeo) SerializeAll() string {
|
2020-05-23 20:58:58 +02:00
|
|
|
return Serialize(f, true)
|
2020-01-15 04:04:33 +01:00
|
|
|
}
|
2020-01-28 22:16:59 +01:00
|
|
|
|
2022-10-02 11:38:30 +02:00
|
|
|
// FindUidOnly checks if search filters other than UID may be skipped to improve performance.
|
|
|
|
func (f *SearchPhotosGeo) FindUidOnly() bool {
|
2022-09-30 19:15:10 +02:00
|
|
|
return f.UID != "" && f.Query == "" && f.Scope == "" && f.Filter == "" && f.Album == "" && f.Albums == ""
|
2022-09-30 00:42:19 +02:00
|
|
|
}
|
|
|
|
|
2022-09-30 19:15:10 +02:00
|
|
|
func NewSearchPhotosGeo(query string) SearchPhotosGeo {
|
2022-04-14 08:39:52 +02:00
|
|
|
return SearchPhotosGeo{Query: query}
|
2020-01-28 22:16:59 +01:00
|
|
|
}
|