2019-12-05 19:21:35 +01:00
package form
2018-08-15 09:59:51 +02:00
import (
"time"
2022-08-31 16:22:28 +02:00
"github.com/photoprism/photoprism/pkg/fs"
2018-08-15 09:59:51 +02:00
)
2021-11-26 13:59:10 +01:00
// SearchPhotos represents search form fields for "/api/v1/photos".
type SearchPhotos struct {
2020-12-19 19:15:32 +01: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:"-" `
2022-12-28 17:50:08 +01:00
ID string ` form:"id" example:"id:123e4567-e89b-..." notes:"Finds pictures by Exif UID, XMP Document ID or Instance ID" `
UID string ` form:"uid" example:"uid:pqbcf5j446s0futy" notes:"Limits results to the specified internal unique IDs" `
2023-09-20 22:07:24 +02:00
Type string ` form:"type" example:"type:raw" notes:"Media Type (image, video, raw, live, animated); separate with |" `
Path string ` form:"path" example:"path:2020/Holiday" notes:"Path Name (separate with |), supports * wildcards" `
Folder string ` form:"folder" example:"folder:\"*/2020\"" notes:"Path Name (separate with |), supports * wildcards" ` // Alias for Path
Name string ` form:"name" example:"name:\"IMG_9831-112*\"" notes:"File Name without path and extension (separate with |)" `
Filename string ` form:"filename" example:"filename:\"2021/07/12345.jpg\"" notes:"File Name with path and extension (separate with |)" `
Original string ` form:"original" example:"original:\"IMG_9831-112*\"" notes:"Original file name of imported files (separate with |)" `
Title string ` form:"title" example:"title:\"Lake*\"" notes:"Title (separate with |)" `
Hash string ` form:"hash" example:"hash:2fd4e1c67a2d" notes:"SHA1 File Hash (separate with |)" `
2022-04-18 12:24:15 +02:00
Primary bool ` form:"primary" notes:"Finds primary JPEG files only" `
Stack bool ` form:"stack" notes:"Finds pictures with more than one media file" `
Unstacked bool ` form:"unstacked" notes:"Finds pictures with a file that has been removed from a stack" `
Stackable bool ` form:"stackable" notes:"Finds pictures that can be stacked with additional media files" `
Video bool ` form:"video" notes:"Finds video files only" `
Vector bool ` form:"vector" notes:"Finds vector graphics only" `
Animated bool ` form:"animated" notes:"Finds animated GIFs" `
Photo bool ` form:"photo" notes:"Finds only photos, no videos" `
Raw bool ` form:"raw" notes:"Finds pictures with RAW image file" `
Live bool ` form:"live" notes:"Finds Live Photos and short videos" `
2023-08-16 10:34:55 +02:00
Scan string ` form:"scan" example:"scan:true scan:false" notes:"Finds scanned photos and documents" `
2022-04-18 12:24:15 +02:00
Panorama bool ` form:"panorama" notes:"Finds pictures with an aspect ratio > 1.9:1" `
Portrait bool ` form:"portrait" notes:"Finds pictures in portrait format" `
Landscape bool ` form:"landscape" notes:"Finds pictures in landscape format" `
Square bool ` form:"square" notes:"Finds images with an aspect ratio of 1:1" `
Error bool ` form:"error" notes:"Finds pictures with errors" `
Hidden bool ` form:"hidden" notes:"Finds hidden pictures (broken or unsupported)" `
Archived bool ` form:"archived" notes:"Finds archived pictures" `
Public bool ` form:"public" notes:"Excludes private pictures" `
Private bool ` form:"private" notes:"Finds private pictures" `
2023-09-21 18:37:33 +02:00
Favorite string ` form:"favorite" example:"favorite:true favorite:false" notes:"Finds images by favorite status" `
2022-04-18 12:24:15 +02:00
Unsorted bool ` form:"unsorted" notes:"Finds pictures not in an album" `
2023-09-20 12:10:49 +02:00
Near string ` form:"near" example:"near:pqbcf5j446s0futy" notes:"Finds nearby pictures (UID)" `
S2 string ` form:"s2" example:"s2:4799e370ca54c8b9" notes:"S2 Position (Cell ID)" `
Olc string ` form:"olc" example:"olc:8FWCHX7W+" notes:"OLC Position (Open Location Code)" `
2023-09-20 16:56:38 +02:00
Lat float64 ` form:"lat" example:"lat:41.894043" notes:"GPS Position (Latitude)" `
Lng float64 ` form:"lng" example:"lng:-87.62448" notes:"GPS Position (Longitude)" `
2023-09-20 18:37:41 +02:00
Dist float64 ` form:"dist" example:"dist:50" notes:"Distance to Position (km)" `
2023-09-20 03:18:30 +02:00
Latlng string ` form:"latlng" notes:"GPS Bounding Box (Lat N, Lng E, Lat S, Lng W)" `
2022-04-18 12:24:15 +02:00
Fmin float32 ` form:"fmin" notes:"F-number (min)" `
Fmax float32 ` form:"fmax" notes:"F-number (max)" `
2022-06-16 06:30:59 +02:00
Chroma int16 ` form:"chroma" example:"chroma:70" notes:"Chroma (0-100)" `
2022-04-18 12:24:15 +02:00
Diff uint32 ` form:"diff" notes:"Differential Perceptual Hash (000000-FFFFFF)" `
Mono bool ` form:"mono" notes:"Finds pictures with few or no colors" `
2023-06-29 18:40:24 +02:00
Geo string ` form:"geo" example:"geo:yes" notes:"Finds pictures with or without coordinates" `
2023-09-20 22:07:24 +02:00
Keywords string ` form:"keywords" example:"keywords:\"sand&water\"" notes:"Keywords (combinable with & and |)" `
Label string ` form:"label" example:"label:cat|dog" notes:"Label Names (separate with |)" `
Category string ` form:"category" example:"category:airport" notes:"Location Category" `
Country string ` form:"country" example:"country:\"de|us\"" notes:"Location Country Code (separate with |)" ` // Moments
State string ` form:"state" example:"state:\"Baden-Württemberg\"" notes:"Location State (separate with |)" ` // Moments
City string ` form:"city" example:"city:\"Berlin\"" notes:"Location City (separate with |)" ` // Moments
Year string ` form:"year" example:"year:1990|2003" notes:"Year (separate with |)" ` // Moments
Month string ` form:"month" example:"month:7|10" notes:"Month (1-12, separate with |)" ` // Moments
Day string ` form:"day" example:"day:3|13" notes:"Day of Month (1-31, separate with |)" ` // Moments
2023-02-21 10:47:15 +01:00
Face string ` form:"face" example:"face:PN6QO5INYTUSAATOFL43LL2ABAV5ACZG" notes:"Face ID, yes, no, new, or kind" ` // UIDs
Faces string ` form:"faces" example:"faces:yes faces:3" notes:"Minimum number of Faces (yes = 1)" ` // Find or exclude faces if detected.
2022-04-18 12:24:15 +02:00
Subject string ` form:"subject" example:"subject:\"Jane Doe & John Doe\"" notes:"Alias for person" ` // UIDs
2023-09-20 22:07:24 +02:00
Person string ` form:"person" example:"person:\"Jane Doe & John Doe\"" notes:"Subject Names, exact matches (combinable with & and |)" ` // Alias for Subject
2022-04-18 12:24:15 +02:00
Subjects string ` form:"subjects" example:"subjects:\"Jane & John\"" notes:"Alias for people" ` // People names
2023-09-20 22:07:24 +02:00
People string ` form:"people" example:"people:\"Jane & John\"" notes:"Subject Names (combinable with & and |)" ` // Alias for Subjects
2022-04-18 12:24:15 +02:00
Album string ` form:"album" example:"album:berlin" notes:"Album UID or Name, supports * wildcards" ` // Album UIDs or name
2023-09-20 22:07:24 +02:00
Albums string ` form:"albums" example:"albums:\"South Africa & Birds\"" notes:"Album Names (combinable with & and |)" ` // Multi search with and/or
Color string ` form:"color" example:"color:\"red|blue\"" notes:"Color Name (purple, magenta, pink, red, orange, gold, yellow, lime, green, teal, cyan, blue, brown, white, grey, black) (separate with |)" ` // Main color
2023-08-18 09:26:10 +02:00
Quality int ` form:"quality" notes:"Minimum quality score (1-7)" ` // Photo quality score
2022-04-18 12:24:15 +02:00
Review bool ` form:"review" notes:"Finds pictures in review" ` // Find photos in review
Camera string ` form:"camera" example:"camera:canon" notes:"Camera Make/Model Name" ` // Camera UID or name
Lens string ` form:"lens" example:"lens:ef24" notes:"Lens Make/Model Name" ` // Lens UID or name
2023-10-12 14:53:40 +02:00
Iso string ` form:"iso" example:"iso:200-400" notes:"ISO Range" `
F string ` form:"f" example:"f:2.8-4.5" notes:"F-Number Range" `
Mm string ` form:"mm" example:"mm:28-35" notes:"Focal Length Range" `
Before time . Time ` form:"before" time_format:"2006-01-02" notes:"Finds pictures taken before this date" ` // Finds images taken before date
After time . Time ` form:"after" time_format:"2006-01-02" notes:"Finds pictures taken after this date" ` // Finds images taken after date
Count int ` form:"count" binding:"required" serialize:"-" ` // Result FILE limit
Offset int ` form:"offset" serialize:"-" ` // Result FILE offset
Order string ` form:"order" serialize:"-" ` // Sort order
Merged bool ` form:"merged" serialize:"-" ` // Merge FILES in response
2019-05-15 21:51:00 +02:00
}
2021-11-26 13:59:10 +01:00
func ( f * SearchPhotos ) GetQuery ( ) string {
2020-01-15 04:04:33 +01:00
return f . Query
}
2019-05-15 21:51:00 +02:00
2021-11-26 13:59:10 +01:00
func ( f * SearchPhotos ) SetQuery ( q string ) {
2020-01-15 04:04:33 +01:00
f . Query = q
}
2019-05-15 23:07:25 +02:00
2021-11-26 13:59:10 +01:00
func ( f * SearchPhotos ) ParseQueryString ( ) error {
2020-05-30 01:41:47 +02:00
if err := ParseQueryString ( f ) ; err != nil {
return err
}
2020-05-21 16:46:22 +02:00
2022-08-01 15:57:19 +02:00
if f . Path != "" {
f . Folder = ""
} else if f . Folder != "" {
2020-05-21 16:46:22 +02:00
f . Path = f . Folder
2021-09-20 12:36:59 +02:00
f . Folder = ""
2020-05-21 16:46:22 +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
}
2020-05-30 01:41:47 +02: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-30 01:41:47 +02:00
return nil
2018-08-15 09:59:51 +02:00
}
2020-02-02 13:01:26 +01:00
2020-05-23 20:58:58 +02:00
// Serialize returns a string containing non-empty fields and values of a struct.
2021-11-26 13:59:10 +01:00
func ( f * SearchPhotos ) 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.
2021-11-26 13:59:10 +01:00
func ( f * SearchPhotos ) SerializeAll ( ) string {
2020-05-23 20:58:58 +02:00
return Serialize ( f , true )
}
2022-09-30 00:42:19 +02:00
// FindUidOnly checks if search filters other than UID may be skipped to improve performance.
func ( f * SearchPhotos ) 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 NewSearchPhotos ( query string ) SearchPhotos {
2021-11-26 13:59:10 +01:00
return SearchPhotos { Query : query }
2020-02-02 13:01:26 +01:00
}