2021-09-18 15:32:39 +02:00
package search
2020-01-15 04:04:33 +01:00
import (
"fmt"
2021-10-01 17:26:29 +02:00
"path"
2020-01-15 04:04:33 +01:00
"strings"
"time"
2021-10-01 00:05:49 +02:00
"github.com/dustin/go-humanize/english"
2020-05-23 20:58:58 +02:00
"github.com/jinzhu/gorm"
2021-09-29 22:57:26 +02:00
2020-05-23 20:58:58 +02:00
"github.com/photoprism/photoprism/internal/entity"
2020-01-15 04:04:33 +01:00
"github.com/photoprism/photoprism/internal/form"
2022-03-30 20:36:25 +02:00
2021-10-01 17:26:29 +02:00
"github.com/photoprism/photoprism/pkg/fs"
2020-01-15 04:04:33 +01:00
"github.com/photoprism/photoprism/pkg/pluscode"
2021-09-29 22:57:26 +02:00
"github.com/photoprism/photoprism/pkg/rnd"
2020-01-15 04:04:33 +01:00
"github.com/photoprism/photoprism/pkg/s2"
2020-04-26 14:31:33 +02:00
"github.com/photoprism/photoprism/pkg/txt"
2020-01-15 04:04:33 +01:00
)
2022-03-30 20:36:25 +02:00
// GeoCols contains the geo query column names.
var GeoCols = SelectString ( GeoResult { } , [ ] string { "*" } )
2022-04-14 14:13:54 +02:00
// PhotosGeo searches for photos based on Form values and returns GeoResults ([]GeoResult).
func PhotosGeo ( f form . SearchPhotosGeo ) ( results GeoResults , err error ) {
2020-05-23 20:58:58 +02:00
start := time . Now ( )
2021-11-26 22:32:13 +01:00
S2Levels := 7
2021-11-26 21:10:52 +01:00
// Search for nearby photos?
if f . Near != "" {
photo := Photo { }
if err := Db ( ) . First ( & photo , "photo_uid = ?" , f . Near ) . Error ; err != nil {
return GeoResults { } , err
}
f . S2 = photo . CellID
2021-11-27 00:16:19 +01:00
f . Lat = photo . PhotoLat
f . Lng = photo . PhotoLng
2021-11-26 22:32:13 +01:00
S2Levels = 12
2021-11-26 21:10:52 +01:00
}
2020-05-08 15:41:01 +02:00
s := UnscopedDb ( )
2020-01-15 04:04:33 +01:00
2020-06-05 16:49:32 +02:00
// s.LogMode(true)
2022-03-30 20:36:25 +02:00
s = s . Table ( "photos" ) . Select ( GeoCols ) .
Joins ( ` JOIN files ON files.photo_id = photos.id AND files.file_primary = 1 AND files.media_id IS NOT NULL ` ) .
2022-09-05 15:35:02 +02:00
Joins ( "LEFT JOIN places ON photos.place_id = places.id" ) .
2020-01-21 13:23:24 +01:00
Where ( "photos.deleted_at IS NULL" ) .
2020-05-29 18:04:30 +02:00
Where ( "photos.photo_lat <> 0" )
2020-01-15 04:04:33 +01:00
2021-09-03 20:14:11 +02:00
// Set search filters based on search terms.
2021-09-17 15:52:25 +02:00
if terms := txt . SearchTerms ( f . Query ) ; f . Query != "" && len ( terms ) == 0 {
2021-09-29 22:57:26 +02:00
if f . Title == "" {
f . Title = fmt . Sprintf ( "%s*" , strings . Trim ( f . Query , "%*" ) )
2021-09-29 20:09:34 +02:00
f . Query = ""
}
2021-09-17 15:52:25 +02:00
} else if len ( terms ) > 0 {
2021-09-03 20:14:11 +02:00
switch {
case terms [ "faces" ] :
f . Query = strings . ReplaceAll ( f . Query , "faces" , "" )
f . Faces = "true"
2021-09-06 15:42:30 +02:00
case terms [ "people" ] :
f . Query = strings . ReplaceAll ( f . Query , "people" , "" )
f . Faces = "true"
2021-09-03 20:14:11 +02:00
case terms [ "videos" ] :
f . Query = strings . ReplaceAll ( f . Query , "videos" , "" )
f . Video = true
2021-10-12 14:31:27 +02:00
case terms [ "video" ] :
f . Query = strings . ReplaceAll ( f . Query , "video" , "" )
f . Video = true
2022-04-14 08:39:52 +02:00
case terms [ "svg" ] :
f . Query = strings . ReplaceAll ( f . Query , "svg" , "" )
f . Vector = true
2022-04-15 09:42:07 +02:00
case terms [ "animated" ] :
f . Query = strings . ReplaceAll ( f . Query , "animated" , "" )
f . Animated = true
2022-04-14 08:39:52 +02:00
case terms [ "gifs" ] :
f . Query = strings . ReplaceAll ( f . Query , "gifs" , "" )
f . Animated = true
case terms [ "gif" ] :
f . Query = strings . ReplaceAll ( f . Query , "gif" , "" )
f . Animated = true
2021-10-13 16:12:56 +02:00
case terms [ "live" ] :
f . Query = strings . ReplaceAll ( f . Query , "live" , "" )
f . Live = true
case terms [ "raws" ] :
f . Query = strings . ReplaceAll ( f . Query , "raws" , "" )
f . Raw = true
2022-04-14 14:13:54 +02:00
case terms [ "raw" ] :
f . Query = strings . ReplaceAll ( f . Query , "raw" , "" )
f . Raw = true
2021-09-03 20:14:11 +02:00
case terms [ "favorites" ] :
f . Query = strings . ReplaceAll ( f . Query , "favorites" , "" )
f . Favorite = true
2021-10-13 16:12:56 +02:00
case terms [ "panoramas" ] :
f . Query = strings . ReplaceAll ( f . Query , "panoramas" , "" )
f . Panorama = true
case terms [ "scans" ] :
f . Query = strings . ReplaceAll ( f . Query , "scans" , "" )
f . Scan = true
2021-09-03 20:14:11 +02:00
}
}
2021-10-13 16:12:56 +02:00
// Filter by label, label category, and keywords?
2020-01-15 04:04:33 +01:00
if f . Query != "" {
2020-05-23 20:58:58 +02:00
var categories [ ] entity . Category
var labels [ ] entity . Label
var labelIds [ ] uint
2020-05-29 18:04:30 +02:00
if err := Db ( ) . Where ( AnySlug ( "custom_slug" , f . Query , " " ) ) . Find ( & labels ) . Error ; len ( labels ) == 0 || err != nil {
2021-12-14 17:07:38 +01:00
log . Debugf ( "search: label %s not found, using fuzzy search" , txt . LogParamLower ( f . Query ) )
2020-05-23 20:58:58 +02:00
2021-08-29 19:19:54 +02:00
for _ , where := range LikeAnyKeyword ( "k.keyword" , f . Query ) {
2021-08-29 16:16:49 +02:00
s = s . Where ( "photos.id IN (SELECT pk.photo_id FROM keywords k JOIN photos_keywords pk ON k.id = pk.keyword_id WHERE (?))" , gorm . Expr ( where ) )
2020-05-23 20:58:58 +02:00
}
} else {
for _ , l := range labels {
labelIds = append ( labelIds , l . ID )
2022-03-30 20:36:25 +02:00
Log ( "find categories" , Db ( ) . Where ( "category_id = ?" , l . ID ) . Find ( & categories ) . Error )
2021-12-14 17:07:38 +01:00
log . Debugf ( "search: label %s includes %d categories" , txt . LogParamLower ( l . LabelName ) , len ( categories ) )
2020-05-23 20:58:58 +02:00
for _ , category := range categories {
labelIds = append ( labelIds , category . LabelID )
}
}
2021-08-29 19:19:54 +02:00
if wheres := LikeAnyKeyword ( "k.keyword" , f . Query ) ; len ( wheres ) > 0 {
2021-08-29 16:16:49 +02:00
for _ , where := range wheres {
s = s . Where ( "photos.id IN (SELECT pk.photo_id FROM keywords k JOIN photos_keywords pk ON k.id = pk.keyword_id WHERE (?)) OR " +
"photos.id IN (SELECT pl.photo_id FROM photos_labels pl WHERE pl.uncertainty < 100 AND pl.label_id IN (?))" , gorm . Expr ( where ) , labelIds )
}
2020-05-23 20:58:58 +02:00
} else {
s = s . Where ( "photos.id IN (SELECT pl.photo_id FROM photos_labels pl WHERE pl.uncertainty < 100 AND pl.label_id IN (?))" , labelIds )
}
}
}
2021-08-29 16:16:49 +02:00
// Search for one or more keywords?
if f . Keywords != "" {
2022-01-05 18:51:18 +01:00
for _ , where := range LikeAnyWord ( "k.keyword" , f . Keywords ) {
2021-08-29 16:16:49 +02:00
s = s . Where ( "photos.id IN (SELECT pk.photo_id FROM keywords k JOIN photos_keywords pk ON k.id = pk.keyword_id WHERE (?))" , gorm . Expr ( where ) )
}
}
2021-10-13 16:12:56 +02:00
// Filter by number of faces?
2021-10-12 14:31:27 +02:00
if txt . IsUInt ( f . Faces ) {
s = s . Where ( "photos.photo_faces >= ?" , txt . Int ( f . Faces ) )
2021-10-13 16:12:56 +02:00
} else if txt . New ( f . Faces ) && f . Face == "" {
f . Face = f . Faces
f . Faces = ""
2021-10-12 14:31:27 +02:00
} else if txt . Yes ( f . Faces ) {
s = s . Where ( "photos.photo_faces > 0" )
} else if txt . No ( f . Faces ) {
s = s . Where ( "photos.photo_faces = 0" )
}
2021-09-23 14:23:00 +02:00
// Filter for specific face clusters? Example: PLJ7A3G4MBGZJRMVDIUCBLC46IAP4N7O
if len ( f . Face ) >= 32 {
2022-04-02 22:23:38 +02:00
for _ , f := range SplitAnd ( strings . ToUpper ( f . Face ) ) {
2021-09-18 15:32:39 +02:00
s = s . Where ( fmt . Sprintf ( "photos.id IN (SELECT photo_id FROM files f JOIN %s m ON f.file_uid = m.file_uid AND m.marker_invalid = 0 WHERE face_id IN (?))" ,
2022-04-02 22:23:38 +02:00
entity . Marker { } . TableName ( ) ) , SplitOr ( f ) )
2021-09-18 15:32:39 +02:00
}
2021-10-13 16:12:56 +02:00
} else if txt . New ( f . Face ) {
s = s . Where ( fmt . Sprintf ( "photos.id IN (SELECT photo_id FROM files f JOIN %s m ON f.file_uid = m.file_uid AND m.marker_invalid = 0 AND m.marker_type = ? WHERE subj_uid IS NULL OR subj_uid = '')" ,
entity . Marker { } . TableName ( ) ) , entity . MarkerFace )
2021-09-23 14:23:00 +02:00
} else if txt . No ( f . Face ) {
s = s . Where ( fmt . Sprintf ( "photos.id IN (SELECT photo_id FROM files f JOIN %s m ON f.file_uid = m.file_uid AND m.marker_invalid = 0 AND m.marker_type = ? WHERE face_id IS NULL OR face_id = '')" ,
entity . Marker { } . TableName ( ) ) , entity . MarkerFace )
} else if txt . Yes ( f . Face ) {
s = s . Where ( fmt . Sprintf ( "photos.id IN (SELECT photo_id FROM files f JOIN %s m ON f.file_uid = m.file_uid AND m.marker_invalid = 0 AND m.marker_type = ? WHERE face_id IS NOT NULL AND face_id <> '')" ,
entity . Marker { } . TableName ( ) ) , entity . MarkerFace )
2021-09-18 15:32:39 +02:00
}
2021-08-29 16:16:49 +02:00
// Filter for one or more subjects?
if f . Subject != "" {
2022-04-02 22:23:38 +02:00
for _ , subj := range SplitAnd ( strings . ToLower ( f . Subject ) ) {
2022-04-15 09:42:07 +02:00
if subjects := SplitOr ( subj ) ; rnd . ValidIDs ( subjects , 'j' ) {
2021-09-20 12:36:59 +02:00
s = s . Where ( fmt . Sprintf ( "photos.id IN (SELECT photo_id FROM files f JOIN %s m ON f.file_uid = m.file_uid AND m.marker_invalid = 0 WHERE subj_uid IN (?))" ,
entity . Marker { } . TableName ( ) ) , subjects )
} else {
s = s . Where ( fmt . Sprintf ( "photos.id IN (SELECT photo_id FROM files f JOIN %s m ON f.file_uid = m.file_uid AND m.marker_invalid = 0 JOIN %s s ON s.subj_uid = m.subj_uid WHERE (?))" ,
entity . Marker { } . TableName ( ) , entity . Subject { } . TableName ( ) ) , gorm . Expr ( AnySlug ( "s.subj_slug" , subj , txt . Or ) ) )
}
2021-08-30 11:56:34 +02:00
}
2021-08-29 16:16:49 +02:00
} else if f . Subjects != "" {
2021-09-20 12:36:59 +02:00
for _ , where := range LikeAllNames ( Cols { "subj_name" , "subj_alias" } , f . Subjects ) {
2021-09-17 14:26:12 +02:00
s = s . Where ( fmt . Sprintf ( "photos.id IN (SELECT photo_id FROM files f JOIN %s m ON f.file_uid = m.file_uid AND m.marker_invalid = 0 JOIN %s s ON s.subj_uid = m.subj_uid WHERE (?))" ,
2021-08-29 16:16:49 +02:00
entity . Marker { } . TableName ( ) , entity . Subject { } . TableName ( ) ) , gorm . Expr ( where ) )
}
}
// Filter by album?
2022-04-15 09:42:07 +02:00
if rnd . EntityUID ( f . Album , 'a' ) {
2022-01-03 12:51:59 +01:00
if f . Filter != "" {
s = s . Where ( "photos.photo_uid NOT IN (SELECT photo_uid FROM photos_albums pa WHERE pa.hidden = 1 AND pa.album_uid = ?)" , f . Album )
} else {
s = s . Joins ( "JOIN photos_albums ON photos_albums.photo_uid = photos.photo_uid" ) .
Where ( "photos_albums.hidden = 0 AND photos_albums.album_uid = ?" , f . Album )
}
} else if f . Unsorted && f . Filter == "" {
s = s . Where ( "photos.photo_uid NOT IN (SELECT photo_uid FROM photos_albums pa WHERE pa.hidden = 0)" )
2022-03-24 18:30:59 +01:00
} else if txt . NotEmpty ( f . Album ) {
v := strings . Trim ( f . Album , "*%" ) + "%"
s = s . Where ( "photos.photo_uid IN (SELECT pa.photo_uid FROM photos_albums pa JOIN albums a ON a.album_uid = pa.album_uid AND pa.hidden = 0 WHERE (a.album_title LIKE ? OR a.album_slug LIKE ?))" , v , v )
} else if txt . NotEmpty ( f . Albums ) {
2021-08-29 19:19:54 +02:00
for _ , where := range LikeAnyWord ( "a.album_title" , f . Albums ) {
2022-03-24 18:30:59 +01:00
s = s . Where ( "photos.photo_uid IN (SELECT pa.photo_uid FROM photos_albums pa JOIN albums a ON a.album_uid = pa.album_uid AND pa.hidden = 0 WHERE (?))" , gorm . Expr ( where ) )
2021-08-29 16:16:49 +02:00
}
2020-05-23 20:58:58 +02:00
}
2021-08-29 16:16:49 +02:00
// Filter by camera?
2020-05-23 20:58:58 +02:00
if f . Camera > 0 {
s = s . Where ( "photos.camera_id = ?" , f . Camera )
}
2021-08-29 16:16:49 +02:00
// Filter by camera lens?
2020-05-23 20:58:58 +02:00
if f . Lens > 0 {
s = s . Where ( "photos.lens_id = ?" , f . Lens )
}
2021-08-29 16:16:49 +02:00
// Filter by year?
2021-09-20 23:32:35 +02:00
if f . Year != "" {
s = s . Where ( AnyInt ( "photos.photo_year" , f . Year , txt . Or , entity . UnknownYear , txt . YearMax ) )
2020-05-23 20:58:58 +02:00
}
2021-08-29 16:16:49 +02:00
// Filter by month?
2021-09-20 23:32:35 +02:00
if f . Month != "" {
s = s . Where ( AnyInt ( "photos.photo_month" , f . Month , txt . Or , entity . UnknownMonth , txt . MonthMax ) )
2020-05-23 20:58:58 +02:00
}
2021-08-29 16:16:49 +02:00
// Filter by day?
2021-09-20 23:32:35 +02:00
if f . Day != "" {
s = s . Where ( AnyInt ( "photos.photo_day" , f . Day , txt . Or , entity . UnknownDay , txt . DayMax ) )
2021-05-26 09:51:00 +02:00
}
2021-10-13 16:12:56 +02:00
// Filter by main color?
2020-05-23 20:58:58 +02:00
if f . Color != "" {
2022-04-02 22:23:38 +02:00
s = s . Where ( "files.file_main_color IN (?)" , SplitOr ( strings . ToLower ( f . Color ) ) )
2020-05-23 20:58:58 +02:00
}
2021-10-13 16:12:56 +02:00
// Find favorites only?
2020-05-23 20:58:58 +02:00
if f . Favorite {
s = s . Where ( "photos.photo_favorite = 1" )
}
2021-10-13 16:12:56 +02:00
// Find scans only?
if f . Scan {
s = s . Where ( "photos.photo_scan = 1" )
}
// Find panoramas only?
if f . Panorama {
s = s . Where ( "photos.photo_panorama = 1" )
}
2022-04-13 09:48:51 +02:00
// Find portrait/landscape/square pictures only?
if f . Portrait {
s = s . Where ( "files.file_portrait = 1" )
} else if f . Landscape {
s = s . Where ( "files.file_aspect_ratio > 1.25" )
} else if f . Square {
s = s . Where ( "files.file_aspect_ratio = 1" )
}
2021-10-13 16:12:56 +02:00
// Filter by location country?
2020-05-23 20:58:58 +02:00
if f . Country != "" {
2022-04-02 22:23:38 +02:00
s = s . Where ( "photos.photo_country IN (?)" , SplitOr ( strings . ToLower ( f . Country ) ) )
2020-05-23 20:58:58 +02:00
}
2022-09-05 15:35:02 +02:00
// Filter by location state?
if txt . NotEmpty ( f . State ) {
s = s . Where ( "places.place_state IN (?)" , SplitOr ( f . State ) )
}
// Filter by location city?
if txt . NotEmpty ( f . City ) {
s = s . Where ( "places.place_city IN (?)" , SplitOr ( f . City ) )
}
2021-10-13 16:12:56 +02:00
// Filter by media type?
2022-04-14 08:39:52 +02:00
if txt . NotEmpty ( f . Type ) {
2022-04-02 22:23:38 +02:00
s = s . Where ( "photos.photo_type IN (?)" , SplitOr ( strings . ToLower ( f . Type ) ) )
2021-10-13 16:12:56 +02:00
} else if f . Video {
2022-04-14 08:39:52 +02:00
s = s . Where ( "photos.photo_type = ?" , entity . MediaVideo )
} else if f . Vector {
s = s . Where ( "photos.photo_type = ?" , entity . MediaVector )
} else if f . Animated {
s = s . Where ( "photos.photo_type = ?" , entity . MediaAnimated )
2021-10-13 16:12:56 +02:00
} else if f . Raw {
2022-04-14 08:39:52 +02:00
s = s . Where ( "photos.photo_type = ?" , entity . MediaRaw )
2021-10-13 16:12:56 +02:00
} else if f . Live {
2022-04-14 08:39:52 +02:00
s = s . Where ( "photos.photo_type = ?" , entity . MediaLive )
} else if f . Photo {
s = s . Where ( "photos.photo_type IN ('image','raw','live','animated')" )
2020-05-23 20:58:58 +02:00
}
2021-10-13 16:12:56 +02:00
// Filter by storage path?
2020-05-23 20:58:58 +02:00
if f . Path != "" {
p := f . Path
if strings . HasPrefix ( p , "/" ) {
p = p [ 1 : ]
}
if strings . HasSuffix ( p , "/" ) {
s = s . Where ( "photos.photo_path = ?" , p [ : len ( p ) - 1 ] )
} else {
2021-09-29 20:09:34 +02:00
where , values := OrLike ( "photos.photo_path" , p )
s = s . Where ( where , values ... )
2020-05-23 20:58:58 +02:00
}
}
2021-10-13 16:12:56 +02:00
// Filter by primary file name without path and extension?
2021-09-29 20:09:34 +02:00
if f . Name != "" {
2021-10-01 17:26:29 +02:00
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 ... )
2020-01-15 04:04:33 +01:00
}
2021-10-13 16:12:56 +02:00
// Filter by photo title?
2021-09-29 22:57:26 +02:00
if f . Title != "" {
where , values := OrLike ( "photos.photo_title" , f . Title )
s = s . Where ( where , values ... )
}
2021-10-13 16:12:56 +02:00
// Filter by status?
2020-06-04 14:56:27 +02:00
if f . Archived {
2020-12-15 20:14:06 +01:00
s = s . Where ( "photos.photo_quality > -1" )
2020-06-04 14:56:27 +02:00
s = s . Where ( "photos.deleted_at IS NOT NULL" )
} else {
s = s . Where ( "photos.deleted_at IS NULL" )
if f . Private {
s = s . Where ( "photos.photo_private = 1" )
} else if f . Public {
s = s . Where ( "photos.photo_private = 0" )
}
if f . Review {
s = s . Where ( "photos.photo_quality < 3" )
} else if f . Quality != 0 && f . Private == false {
s = s . Where ( "photos.photo_quality >= ?" , f . Quality )
}
2020-04-24 13:25:04 +02:00
}
2020-01-15 04:04:33 +01:00
if f . S2 != "" {
2021-11-26 22:32:13 +01:00
s2Min , s2Max := s2 . PrefixedRange ( f . S2 , S2Levels )
2020-07-12 08:27:05 +02:00
s = s . Where ( "photos.cell_id BETWEEN ? AND ?" , s2Min , s2Max )
2020-01-15 04:04:33 +01:00
} else if f . Olc != "" {
2021-11-26 22:32:13 +01:00
s2Min , s2Max := s2 . PrefixedRange ( pluscode . S2 ( f . Olc ) , S2Levels )
2020-07-12 08:27:05 +02:00
s = s . Where ( "photos.cell_id BETWEEN ? AND ?" , s2Min , s2Max )
2020-01-15 04:04:33 +01:00
} else {
2021-11-26 21:10:52 +01:00
// Filter by approx distance to coordinate:
2021-02-11 20:06:23 +01:00
if f . Lat != 0 {
2021-09-18 15:32:39 +02:00
latMin := f . Lat - Radius * float32 ( f . Dist )
latMax := f . Lat + Radius * float32 ( f . Dist )
2020-03-28 17:17:41 +01:00
s = s . Where ( "photos.photo_lat BETWEEN ? AND ?" , latMin , latMax )
2020-01-15 04:04:33 +01:00
}
2021-02-11 20:06:23 +01:00
if f . Lng != 0 {
2021-09-18 15:32:39 +02:00
lngMin := f . Lng - Radius * float32 ( f . Dist )
lngMax := f . Lng + Radius * float32 ( f . Dist )
2020-03-28 17:17:41 +01:00
s = s . Where ( "photos.photo_lng BETWEEN ? AND ?" , lngMin , lngMax )
2020-01-15 04:04:33 +01:00
}
}
2021-11-26 21:10:52 +01:00
// Find photos taken before date?
2020-01-15 04:04:33 +01:00
if ! f . Before . IsZero ( ) {
2020-03-28 17:17:41 +01:00
s = s . Where ( "photos.taken_at <= ?" , f . Before . Format ( "2006-01-02" ) )
2020-01-15 04:04:33 +01:00
}
2021-11-26 21:10:52 +01:00
// Find photos taken after date?
2020-01-15 04:04:33 +01:00
if ! f . After . IsZero ( ) {
2020-03-28 17:17:41 +01:00
s = s . Where ( "photos.taken_at >= ?" , f . After . Format ( "2006-01-02" ) )
2020-01-15 04:04:33 +01:00
}
2021-11-27 00:16:19 +01:00
if f . Near == "" {
// Default sort order.
s = s . Order ( "taken_at, photos.photo_uid" )
} else {
2021-11-26 21:10:52 +01:00
// Sort by distance to UID.
2021-11-26 21:24:12 +01:00
s = s . Order ( gorm . Expr ( "(photos.photo_uid = ?) DESC, ABS(? - photos.photo_lat)+ABS(? - photos.photo_lng)" , f . Near , f . Lat , f . Lng ) )
2021-11-26 21:10:52 +01:00
}
// Limit result count?
if f . Count > 0 {
s = s . Limit ( f . Count ) . Offset ( f . Offset )
}
2020-01-15 04:04:33 +01:00
2021-11-26 21:10:52 +01:00
// Fetch results.
2020-03-28 17:17:41 +01:00
if result := s . Scan ( & results ) ; result . Error != nil {
2020-01-15 04:04:33 +01:00
return results , result . Error
}
2022-07-19 16:58:43 +02:00
log . Debugf ( "places: found %s for %s [%s]" , english . Plural ( len ( results ) , "result" , "results" ) , f . SerializeAll ( ) , time . Since ( start ) )
2020-05-23 20:58:58 +02:00
2020-01-15 04:04:33 +01:00
return results , nil
}