Search: Improve inline comments and annotations

This commit is contained in:
graciousgrey
2025-11-07 16:42:55 +01:00
parent d5b0b18411
commit 7cc9d4147e
5 changed files with 54 additions and 4 deletions

View File

@@ -803,7 +803,7 @@ func searchPhotos(frm form.SearchPhotos, sess *entity.Session, resultCols string
s = s.Where("DATE(photos.taken_at) = DATE(?)", frm.Taken.UTC().Format("2006-01-02")) s = s.Where("DATE(photos.taken_at) = DATE(?)", frm.Taken.UTC().Format("2006-01-02"))
} }
// Finds pictures taken on or before this date. // Finds pictures taken before this date.
if !frm.Before.IsZero() { if !frm.Before.IsZero() {
s = s.Where("photos.taken_at <= ?", frm.Before.UTC().Format("2006-01-02")) s = s.Where("photos.taken_at <= ?", frm.Before.UTC().Format("2006-01-02"))
} }

View File

@@ -691,7 +691,7 @@ func UserPhotosGeo(frm form.SearchPhotosGeo, sess *entity.Session) (results GeoR
s = s.Where("DATE(photos.taken_at) = DATE(?)", frm.Taken.UTC().Format("2006-01-02")) s = s.Where("DATE(photos.taken_at) = DATE(?)", frm.Taken.UTC().Format("2006-01-02"))
} }
// Finds pictures taken on or before this date. // Finds pictures taken before this date.
if !frm.Before.IsZero() { if !frm.Before.IsZero() {
s = s.Where("photos.taken_at <= ?", frm.Before.UTC().Format("2006-01-02")) s = s.Where("photos.taken_at <= ?", frm.Before.UTC().Format("2006-01-02"))
} }

View File

@@ -3,6 +3,7 @@ package search
import ( import (
"strconv" "strconv"
"testing" "testing"
"time"
"github.com/photoprism/photoprism/internal/entity/sortby" "github.com/photoprism/photoprism/internal/entity/sortby"
@@ -737,6 +738,55 @@ func TestPhotos(t *testing.T) {
} }
assert.LessOrEqual(t, 2, len(photos)) assert.LessOrEqual(t, 2, len(photos))
}) })
t.Run("FindContentCreatedBefore", func(t *testing.T) {
var f form.SearchPhotos
f.Query = "Before:1990-04-18"
f.Count = 5000
f.Offset = 0
f.Merged = true
f.Order = "newest"
photos, _, err := Photos(f)
if err != nil {
t.Fatal(err)
}
assert.LessOrEqual(t, 1, len(photos))
assert.Equal(t, time.Date(1990, 3, 2, 0, 0, 0, 0, time.UTC), photos[0].TakenAt)
})
t.Run("FindContentCreatedBefore", func(t *testing.T) {
var f form.SearchPhotos
f.Query = "Before:1990-04-19"
f.Count = 5000
f.Offset = 0
f.Merged = true
f.Order = "newest"
photos, _, err := Photos(f)
if err != nil {
t.Fatal(err)
}
assert.LessOrEqual(t, 2, len(photos))
assert.Equal(t, time.Date(1990, 4, 18, 1, 0, 0, 0, time.UTC), photos[0].TakenAt)
})
t.Run("FindContentCreatedOnORAfter", func(t *testing.T) {
var f form.SearchPhotos
f.Query = "After:1990-04-18"
f.Count = 5000
f.Offset = 0
f.Merged = true
f.Order = "oldest"
photos, _, err := Photos(f)
if err != nil {
t.Fatal(err)
}
assert.LessOrEqual(t, 45, len(photos))
assert.Equal(t, time.Date(1990, 4, 18, 1, 0, 0, 0, time.UTC), photos[0].TakenAt)
})
t.Run("SearchForDiff", func(t *testing.T) { t.Run("SearchForDiff", func(t *testing.T) {
var f form.SearchPhotos var f form.SearchPhotos
f.Query = "Diff:800" f.Query = "Diff:800"

View File

@@ -93,7 +93,7 @@ type SearchPhotos struct {
Updated time.Time `form:"updated" example:"updated:\"2006-01-02T15:04:05Z\"" time_format:"2006-01-02T15:04:05Z07:00" notes:"Finds content updated at or after this time"` // Pictures updated at or after this time Updated time.Time `form:"updated" example:"updated:\"2006-01-02T15:04:05Z\"" time_format:"2006-01-02T15:04:05Z07:00" notes:"Finds content updated at or after this time"` // Pictures updated at or after this time
Edited time.Time `form:"edited" example:"edited:\"2006-01-02T15:04:05Z\"" time_format:"2006-01-02T15:04:05Z07:00" notes:"Finds content edited at or after this time"` // Pictures edited at or after this time Edited time.Time `form:"edited" example:"edited:\"2006-01-02T15:04:05Z\"" time_format:"2006-01-02T15:04:05Z07:00" notes:"Finds content edited at or after this time"` // Pictures edited at or after this time
Taken time.Time `form:"taken" time_format:"2006-01-02" notes:"Finds content created on the specified date"` // Pictures taken on the specified date Taken time.Time `form:"taken" time_format:"2006-01-02" notes:"Finds content created on the specified date"` // Pictures taken on the specified date
Before time.Time `form:"before" time_format:"2006-01-02" notes:"Finds content created on or before this date"` // Pictures taken on or before this date" Before time.Time `form:"before" time_format:"2006-01-02" notes:"Finds content created before this date"` // Pictures taken on or before this date"
After time.Time `form:"after" time_format:"2006-01-02" notes:"Finds content created on or after this date"` // Pictures taken on or after this date After time.Time `form:"after" time_format:"2006-01-02" notes:"Finds content created on or after this date"` // Pictures taken on or after this date
Count int `form:"count" binding:"required" serialize:"-"` // Result FILE limit Count int `form:"count" binding:"required" serialize:"-"` // Result FILE limit
Offset int `form:"offset" serialize:"-"` // Result FILE offset Offset int `form:"offset" serialize:"-"` // Result FILE offset

View File

@@ -25,7 +25,7 @@ type SearchPhotosGeo struct {
Updated time.Time `form:"updated" example:"updated:\"2006-01-02T15:04:05Z\"" time_format:"2006-01-02T15:04:05Z07:00" notes:"Finds content updated at or after this time"` Updated time.Time `form:"updated" example:"updated:\"2006-01-02T15:04:05Z\"" time_format:"2006-01-02T15:04:05Z07:00" notes:"Finds content updated at or after this time"`
Edited time.Time `form:"edited" example:"edited:\"2006-01-02T15:04:05Z\"" time_format:"2006-01-02T15:04:05Z07:00" notes:"Finds content edited at or after this time"` Edited time.Time `form:"edited" example:"edited:\"2006-01-02T15:04:05Z\"" time_format:"2006-01-02T15:04:05Z07:00" notes:"Finds content edited at or after this time"`
Taken time.Time `form:"taken" time_format:"2006-01-02" notes:"Finds content created on the specified date"` Taken time.Time `form:"taken" time_format:"2006-01-02" notes:"Finds content created on the specified date"`
Before time.Time `form:"before" time_format:"2006-01-02" notes:"Finds content created on or before this date"` Before time.Time `form:"before" time_format:"2006-01-02" notes:"Finds content created before this date"`
After time.Time `form:"after" time_format:"2006-01-02" notes:"Finds content created on or after this date"` After time.Time `form:"after" time_format:"2006-01-02" notes:"Finds content created on or after this date"`
Favorite string `form:"favorite" example:"favorite:yes" notes:"Finds favorites only"` Favorite string `form:"favorite" example:"favorite:yes" notes:"Finds favorites only"`
Unsorted bool `form:"unsorted" notes:"Finds content that is not in an album"` Unsorted bool `form:"unsorted" notes:"Finds content that is not in an album"`