search

package
v0.0.0-...-c8acfb9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 25, 2024 License: AGPL-3.0 Imports: 31 Imported by: 0

Documentation

Overview

Package search provides search queries to find photos, albums, labels, and subjects.

Copyright (c) 2018 - 2024 PhotoPrism UG. All rights reserved.

This program is free software: you can redistribute it and/or modify
it under Version 3 of the GNU Affero General Public License (the "AGPL"):
<https://docs.photoprism.app/license/agpl>

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.

The AGPL is supplemented by our Trademark and Brand Guidelines,
which describe how our Brand Assets may be used:
<https://www.photoprism.app/trademark>

Feel free to send an email to hello@photoprism.app if you have questions, want to support our work, or just want to say hello.

Additional information can be found in our Developer Guide: <https://docs.photoprism.app/developer-guide/>

Index

Constants

View Source
const MaxResults = 100000

MaxResults is max result limit for queries.

View Source
const Radius = 0.009

Radius is about 1 km.

Variables

View Source
var (
	ErrForbidden    = i18n.Error(i18n.ErrForbidden)
	ErrBadRequest   = i18n.Error(i18n.ErrBadRequest)
	ErrNotFound     = i18n.Error(i18n.ErrNotFound)
	ErrBadSortOrder = fmt.Errorf("invalid sort order")
	ErrBadFilter    = fmt.Errorf("invalid search filter")
	ErrInvalidId    = fmt.Errorf("invalid ID specified")
)
View Source
var GeoCols = SelectString(GeoResult{}, []string{"*"})

GeoCols specifies the UserPhotosGeo result column names.

View Source
var PhotosColsAll = SelectString(Photo{}, []string{"*"})

PhotosColsAll contains all supported result column names.

View Source
var PhotosColsView = SelectString(Photo{}, SelectCols(GeoResult{}, []string{"*"}))

PhotosColsView contains the result column names necessary for the photo viewer.

Functions

func Accounts

func Accounts(f form.SearchServices) (result entity.Services, err error)

Accounts returns a list of accounts.

func AnyInt

func AnyInt(col, numbers, sep string, min, max int) (where string)

AnyInt returns a where condition that matches any integer within a range.

func AnySlug

func AnySlug(col, search, sep string) (where string)

AnySlug returns a where condition that matches any slug in search.

func Db

func Db() *gorm.DB

Db returns a database connection instance.

func Like

func Like(s string) string

Like escapes a string for use in a query.

func LikeAll

func LikeAll(col, s string, keywords, exact bool) (wheres []string)

LikeAll returns a list of where conditions matching all search words.

func LikeAllKeywords

func LikeAllKeywords(col, s string) (wheres []string)

LikeAllKeywords returns a list of where conditions matching all search keywords.

func LikeAllNames

func LikeAllNames(cols Cols, s string) (wheres []string)

LikeAllNames returns a list of where conditions matching all names.

func LikeAllWords

func LikeAllWords(col, s string) (wheres []string)

LikeAllWords returns a list of where conditions matching all search words.

func LikeAny

func LikeAny(col, s string, keywords, exact bool) (wheres []string)

LikeAny returns a single where condition matching the search words.

func LikeAnyKeyword

func LikeAnyKeyword(col, s string) (wheres []string)

LikeAnyKeyword returns a single where condition matching the search keywords.

func LikeAnyWord

func LikeAnyWord(col, s string) (wheres []string)

LikeAnyWord returns a single where condition matching the search word.

func Log

func Log(action string, err error)

Log logs the error if any and keeps quiet otherwise.

func OrLike

func OrLike(col, s string) (where string, values []interface{})

OrLike returns a where condition and values for finding multiple terms combined with OR.

func PhotosViewerResults

func PhotosViewerResults(f form.SearchPhotos, contentUri, apiUri, previewToken, downloadToken string) (viewer.Results, int, error)

PhotosViewerResults finds photos based on the search form provided and returns them as viewer.Results.

func SelectString

func SelectString(f interface{}, tags []string) string

SelectString returns the columns for a search result struct as a string.

func Sessions

func Sessions(f form.SearchSessions) (result entity.Sessions, err error)

Sessions finds user sessions.

func Split

func Split(s string, sep string) (result []string)

Split splits a search string into separate values and trims whitespace.

func SplitAnd

func SplitAnd(s string) (values []string)

SplitAnd splits a search string into separate AND values.

func SplitOr

func SplitOr(s string) (values []string)

SplitOr splits a search string into separate OR values for an IN condition.

func SubjectUIDs

func SubjectUIDs(s string) (result []string, names []string, remaining string)

SubjectUIDs finds subject UIDs matching the search string, and removes names from the remaining query.

func UnscopedDb

func UnscopedDb() *gorm.DB

UnscopedDb returns an unscoped database connection instance.

func UserPhotosViewerResults

func UserPhotosViewerResults(f form.SearchPhotos, sess *entity.Session, contentUri, apiUri, previewToken, downloadToken string) (viewer.Results, int, error)

UserPhotosViewerResults finds photos based on the search form and user session and returns them as viewer.Results.

func Users

func Users(f form.SearchUsers) (result entity.Users, err error)

Users finds registered users.

Types

type Album

type Album struct {
	ID               uint      `json:"-"`
	AlbumUID         string    `json:"UID"`
	ParentUID        string    `json:"ParentUID"`
	Thumb            string    `json:"Thumb"`
	ThumbSrc         string    `json:"ThumbSrc,omitempty"`
	AlbumSlug        string    `json:"Slug"`
	AlbumType        string    `json:"Type"`
	AlbumTitle       string    `json:"Title"`
	AlbumLocation    string    `json:"Location"`
	AlbumCategory    string    `json:"Category"`
	AlbumCaption     string    `json:"Caption"`
	AlbumDescription string    `json:"Description"`
	AlbumNotes       string    `json:"Notes"`
	AlbumFilter      string    `json:"Filter"`
	AlbumOrder       string    `json:"Order"`
	AlbumTemplate    string    `json:"Template"`
	AlbumPath        string    `json:"Path"`
	AlbumState       string    `json:"State"`
	AlbumCountry     string    `json:"Country"`
	AlbumYear        int       `json:"Year"`
	AlbumMonth       int       `json:"Month"`
	AlbumDay         int       `json:"Day"`
	AlbumFavorite    bool      `json:"Favorite"`
	AlbumPrivate     bool      `json:"Private"`
	PhotoCount       int       `json:"PhotoCount"`
	LinkCount        int       `json:"LinkCount"`
	CreatedAt        time.Time `json:"CreatedAt"`
	UpdatedAt        time.Time `json:"UpdatedAt"`
	DeletedAt        time.Time `json:"DeletedAt,omitempty"`
}

Album represents an album search result.

type AlbumResults

type AlbumResults []Album

func Albums

func Albums(f form.SearchAlbums) (results AlbumResults, err error)

Albums finds AlbumResults based on the search form without checking rights or permissions.

func UserAlbums

func UserAlbums(f form.SearchAlbums, sess *entity.Session) (results AlbumResults, err error)

UserAlbums finds AlbumResults based on the search form and user session.

type Cols

type Cols []string

Cols represents a list of database columns.

func SelectCols

func SelectCols(f interface{}, tags []string) Cols

SelectCols returns the columns for a search result struct.

type Count

type Count struct {
	Total int
}

Count represents the total number of search results.

type Face

type Face struct {
	ID              string     `json:"ID"`
	FaceSrc         string     `json:"Src"`
	FaceHidden      bool       `json:"Hidden"`
	FaceDist        float64    `json:"FaceDist,omitempty"`
	SubjUID         string     `json:"SubjUID"`
	SubjSrc         string     `json:"SubjSrc,omitempty"`
	FileUID         string     `json:"FileUID,omitempty"`
	MarkerUID       string     `json:"MarkerUID,omitempty"`
	Samples         int        `json:"Samples"`
	SampleRadius    float64    `json:"SampleRadius"`
	Collisions      int        `json:"Collisions"`
	CollisionRadius float64    `json:"CollisionRadius"`
	MarkerName      string     `json:"Name"`
	Size            int        `json:"Size,omitempty"`
	Score           int        `json:"Score,omitempty"`
	MarkerReview    bool       `json:"Review"`
	MarkerInvalid   bool       `json:"Invalid"`
	Thumb           string     `json:"Thumb"`
	MatchedAt       *time.Time `json:"MatchedAt" yaml:"MatchedAt,omitempty"`
	CreatedAt       time.Time  `json:"CreatedAt" yaml:"CreatedAt,omitempty"`
	UpdatedAt       time.Time  `json:"UpdatedAt" yaml:"UpdatedAt,omitempty"`
}

Face represents a face search result.

type FaceResults

type FaceResults []Face

FaceResults represents face search results.

func Faces

func Faces(f form.SearchFaces) (results FaceResults, err error)

Faces searches faces and returns them.

type GeoResult

type GeoResult struct {
	ID               string    `json:"-" select:"photos.id"`
	PhotoUID         string    `json:"UID" select:"photos.photo_uid"`
	PhotoType        string    `json:"Type,omitempty" select:"photos.photo_type"`
	PhotoLat         float32   `json:"Lat" select:"photos.photo_lat"`
	PhotoLng         float32   `json:"Lng" select:"photos.photo_lng"`
	PhotoTitle       string    `json:"Title" select:"photos.photo_title"`
	PhotoDescription string    `json:"Description,omitempty" select:"photos.photo_description"`
	PhotoFavorite    bool      `json:"Favorite,omitempty" select:"photos.photo_favorite"`
	FileHash         string    `json:"Hash" select:"files.file_hash"`
	FileWidth        int       `json:"Width" select:"files.file_width"`
	FileHeight       int       `json:"Height" select:"files.file_height"`
	TakenAt          time.Time `json:"TakenAt" select:"photos.taken_at"`
	TakenAtLocal     time.Time `json:"TakenAtLocal" select:"photos.taken_at_local"`
}

GeoResult represents a photo geo search result.

func (GeoResult) IsPlayable

func (photo GeoResult) IsPlayable() bool

IsPlayable returns true if the photo has a related video/animation that is playable.

func (GeoResult) Lat

func (photo GeoResult) Lat() float64

Lat returns the position latitude.

func (GeoResult) Lng

func (photo GeoResult) Lng() float64

Lng returns the position longitude.

func (GeoResult) ViewerResult

func (photo GeoResult) ViewerResult(contentUri, apiUri, previewToken, downloadToken string) viewer.Result

ViewerResult creates a new photo viewer result.

type GeoResults

type GeoResults []GeoResult

GeoResults represents a list of geo search results.

func PhotosGeo

func PhotosGeo(f form.SearchPhotosGeo) (results GeoResults, err error)

PhotosGeo finds GeoResults based on the search form without checking rights or permissions.

func UserPhotosGeo

func UserPhotosGeo(f form.SearchPhotosGeo, sess *entity.Session) (results GeoResults, err error)

UserPhotosGeo finds photos based on the search form and user session then returns them as GeoResults.

func (GeoResults) GeoJSON

func (photos GeoResults) GeoJSON() ([]byte, error)

GeoJSON returns results as specified on https://geojson.org/.

func (GeoResults) ViewerJSON

func (photos GeoResults) ViewerJSON(contentUri, apiUri, previewToken, downloadToken string) ([]byte, error)

ViewerJSON returns the results as photo viewer JSON.

type Label

type Label struct {
	ID               uint      `json:"ID"`
	LabelUID         string    `json:"UID"`
	Thumb            string    `json:"Thumb"`
	ThumbSrc         string    `json:"ThumbSrc,omitempty"`
	LabelSlug        string    `json:"Slug"`
	CustomSlug       string    `json:"CustomSlug"`
	LabelName        string    `json:"Name"`
	LabelPriority    int       `json:"Priority"`
	LabelFavorite    bool      `json:"Favorite"`
	LabelDescription string    `json:"Description"`
	LabelNotes       string    `json:"Notes"`
	PhotoCount       int       `json:"PhotoCount"`
	CreatedAt        time.Time `json:"CreatedAt"`
	UpdatedAt        time.Time `json:"UpdatedAt"`
	DeletedAt        time.Time `json:"DeletedAt,omitempty"`
}

Label represents a label search result.

func Labels

func Labels(f form.SearchLabels) (results []Label, err error)

Labels searches labels based on their name.

type Photo

type Photo struct {
	ID               uint          `json:"-" select:"photos.id"`
	CompositeID      string        `json:"ID" select:"files.photo_id AS composite_id"`
	UUID             string        `json:"DocumentID,omitempty" select:"photos.uuid"`
	PhotoUID         string        `json:"UID" select:"photos.photo_uid"`
	PhotoType        string        `json:"Type" select:"photos.photo_type"`
	TypeSrc          string        `json:"TypeSrc" select:"photos.taken_src"`
	TakenAt          time.Time     `json:"TakenAt" select:"photos.taken_at"`
	TakenAtLocal     time.Time     `json:"TakenAtLocal" select:"photos.taken_at_local"`
	TakenSrc         string        `json:"TakenSrc" select:"photos.taken_src"`
	TimeZone         string        `json:"TimeZone" select:"photos.time_zone"`
	PhotoPath        string        `json:"Path" select:"photos.photo_path"`
	PhotoName        string        `json:"Name" select:"photos.photo_name"`
	OriginalName     string        `json:"OriginalName" select:"photos.original_name"`
	PhotoTitle       string        `json:"Title" select:"photos.photo_title"`
	PhotoDescription string        `json:"Description" select:"photos.photo_description"`
	PhotoYear        int           `json:"Year" select:"photos.photo_year"`
	PhotoMonth       int           `json:"Month" select:"photos.photo_month"`
	PhotoDay         int           `json:"Day" select:"photos.photo_day"`
	PhotoCountry     string        `json:"Country" select:"photos.photo_country"`
	PhotoStack       int8          `json:"Stack" select:"photos.photo_stack"`
	PhotoFavorite    bool          `json:"Favorite" select:"photos.photo_favorite"`
	PhotoPrivate     bool          `json:"Private" select:"photos.photo_private"`
	PhotoIso         int           `json:"Iso" select:"photos.photo_iso"`
	PhotoFocalLength int           `json:"FocalLength" select:"photos.photo_focal_length"`
	PhotoFNumber     float32       `json:"FNumber" select:"photos.photo_f_number"`
	PhotoExposure    string        `json:"Exposure" select:"photos.photo_exposure"`
	PhotoFaces       int           `json:"Faces,omitempty" select:"photos.photo_faces"`
	PhotoQuality     int           `json:"Quality" select:"photos.photo_quality"`
	PhotoResolution  int           `json:"Resolution" select:"photos.photo_resolution"`
	PhotoDuration    time.Duration `json:"Duration,omitempty" yaml:"photos.photo_duration"`
	PhotoColor       int16         `json:"Color" select:"photos.photo_color"`
	PhotoScan        bool          `json:"Scan" select:"photos.photo_scan"`
	PhotoPanorama    bool          `json:"Panorama" select:"photos.photo_panorama"`
	CameraID         uint          `json:"CameraID" select:"photos.camera_id"` // Camera
	CameraSrc        string        `json:"CameraSrc,omitempty" select:"photos.camera_src"`
	CameraSerial     string        `json:"CameraSerial,omitempty" select:"photos.camera_serial"`
	CameraMake       string        `json:"CameraMake,omitempty" select:"cameras.camera_make"`
	CameraModel      string        `json:"CameraModel,omitempty" select:"cameras.camera_model"`
	LensID           uint          `json:"LensID" select:"photos.lens_id"` // Lens
	LensMake         string        `json:"LensMake,omitempty" select:"lenses.lens_model"`
	LensModel        string        `json:"LensModel,omitempty" select:"lenses.lens_make"`
	PhotoAltitude    int           `json:"Altitude,omitempty" select:"photos.photo_altitude"`
	PhotoLat         float32       `json:"Lat" select:"photos.photo_lat"`
	PhotoLng         float32       `json:"Lng" select:"photos.photo_lng"`
	CellID           string        `json:"CellID" select:"photos.cell_id"` // Cell
	CellAccuracy     int           `json:"CellAccuracy,omitempty" select:"photos.cell_accuracy"`
	PlaceID          string        `json:"PlaceID" select:"photos.place_id"`
	PlaceSrc         string        `json:"PlaceSrc" select:"photos.place_src"`
	PlaceLabel       string        `json:"PlaceLabel" select:"places.place_label"`
	PlaceCity        string        `json:"PlaceCity" select:"places.place_city"`
	PlaceState       string        `json:"PlaceState" select:"places.place_state"`
	PlaceCountry     string        `json:"PlaceCountry" select:"places.place_country"`
	InstanceID       string        `json:"InstanceID" select:"files.instance_id"`
	FileID           uint          `json:"-" select:"files.id AS file_id"` // File
	FileUID          string        `json:"FileUID" select:"files.file_uid"`
	FileRoot         string        `json:"FileRoot" select:"files.file_root"`
	FileName         string        `json:"FileName" select:"files.file_name"`
	FileHash         string        `json:"Hash" select:"files.file_hash"`
	FileWidth        int           `json:"Width" select:"files.file_width"`
	FileHeight       int           `json:"Height" select:"files.file_height"`
	FilePortrait     bool          `json:"Portrait" select:"files.file_portrait"`
	FilePrimary      bool          `json:"-" select:"files.file_primary"`
	FileSidecar      bool          `json:"-" select:"files.file_sidecar"`
	FileMissing      bool          `json:"-" select:"files.file_missing"`
	FileVideo        bool          `json:"-" select:"files.file_video"`
	FileDuration     time.Duration `json:"-" select:"files.file_duration"`
	FileFPS          float64       `json:"-" select:"files.file_fps"`
	FileFrames       int           `json:"-" select:"files.file_frames"`
	FileCodec        string        `json:"-" select:"files.file_codec"`
	FileType         string        `json:"-" select:"files.file_type"`
	MediaType        string        `json:"-" select:"files.media_type"`
	FileMime         string        `json:"-" select:"files.file_mime"`
	FileSize         int64         `json:"-" select:"files.file_size"`
	FileOrientation  int           `json:"-" select:"files.file_orientation"`
	FileProjection   string        `json:"-" select:"files.file_projection"`
	FileAspectRatio  float32       `json:"-" select:"files.file_aspect_ratio"`
	FileColors       string        `json:"-" select:"files.file_colors"`
	FileDiff         int           `json:"-" select:"files.file_diff"`
	FileChroma       int16         `json:"-" select:"files.file_chroma"`
	FileLuminance    string        `json:"-" select:"files.file_luminance"`
	Merged           bool          `json:"Merged" select:"-"`
	CreatedAt        time.Time     `json:"CreatedAt" select:"photos.created_at"`
	UpdatedAt        time.Time     `json:"UpdatedAt" select:"photos.updated_at"`
	EditedAt         time.Time     `json:"EditedAt,omitempty" select:"photos.edited_at"`
	CheckedAt        time.Time     `json:"CheckedAt,omitempty" select:"photos.checked_at"`
	DeletedAt        time.Time     `json:"DeletedAt,omitempty" select:"photos.deleted_at"`

	Files []entity.File `json:"Files"`
}

Photo represents a photo search result.

func (*Photo) IsPlayable

func (photo *Photo) IsPlayable() bool

IsPlayable returns true if the photo has a related video/animation that is playable.

func (*Photo) ShareBase

func (photo *Photo) ShareBase(seq int) string

ShareBase returns a meaningful file name for sharing.

func (Photo) ViewerResult

func (photo Photo) ViewerResult(contentUri, apiUri, previewToken, downloadToken string) viewer.Result

ViewerResult returns a new photo viewer result.

type PhotoResults

type PhotoResults []Photo

func AlbumPhotos

func AlbumPhotos(a entity.Album, count int, shared bool) (results PhotoResults, err error)

AlbumPhotos returns up to count photos from an album.

func PhotoIds

func PhotoIds(f form.SearchPhotos) (files PhotoResults, count int, err error)

PhotoIds finds photo and file ids based on the search form provided and returns them as PhotoResults.

func Photos

func Photos(f form.SearchPhotos) (results PhotoResults, count int, err error)

Photos finds PhotoResults based on the search form without checking rights or permissions.

func UserPhotos

func UserPhotos(f form.SearchPhotos, sess *entity.Session) (results PhotoResults, count int, err error)

UserPhotos finds PhotoResults based on the search form and user session.

func (PhotoResults) Merge

func (photos PhotoResults) Merge() (merged PhotoResults, count int, err error)

Merge consecutive file results that belong to the same photo.

func (PhotoResults) UIDs

func (photos PhotoResults) UIDs() []string

UIDs returns a slice of photo UIDs.

func (PhotoResults) ViewerJSON

func (photos PhotoResults) ViewerJSON(contentUri, apiUri, previewToken, downloadToken string) ([]byte, error)

ViewerJSON returns the results as photo viewer JSON.

func (PhotoResults) ViewerResults

func (photos PhotoResults) ViewerResults(contentUri, apiUri, previewToken, downloadToken string) (results viewer.Results)

ViewerResults returns the results photo viewer formatted.

type Query

type Query struct {
	// contains filtered or unexported fields
}

Query searches given an originals path and a db instance.

type Subject

type Subject struct {
	SubjUID      string `json:"UID"`
	MarkerUID    string `json:"MarkerUID"`
	MarkerSrc    string `json:"MarkerSrc,omitempty"`
	SubjType     string `json:"Type"`
	SubjSlug     string `json:"Slug"`
	SubjName     string `json:"Name"`
	SubjAlias    string `json:"Alias"`
	SubjFavorite bool   `json:"Favorite"`
	SubjHidden   bool   `json:"Hidden"`
	SubjPrivate  bool   `json:"Private"`
	SubjExcluded bool   `json:"Excluded"`
	FileCount    int    `json:"FileCount"`
	PhotoCount   int    `json:"PhotoCount"`
	Thumb        string `json:"Thumb"`
	ThumbSrc     string `json:"ThumbSrc,omitempty"`
}

Subject represents a subject search result.

type SubjectResults

type SubjectResults []Subject

SubjectResults represents subject search results.

func Subjects

func Subjects(f form.SearchSubjects) (results SubjectResults, err error)

Subjects searches subjects and returns them.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL