diff --git a/internal/search/tiers.go b/internal/search/tiers.go index ef067de..827b598 100644 --- a/internal/search/tiers.go +++ b/internal/search/tiers.go @@ -13,9 +13,16 @@ type DateRange struct { } // BuildCELFilter creates a CEL filter string for a date range using created_ts. +// Since memos 0.30 created_ts is a CEL timestamp, so plain Unix ints are not +// comparable with it — the bounds must be wrapped in timestamp(). func BuildCELFilter(dr DateRange) string { - return fmt.Sprintf("created_ts >= %d && created_ts < %d", - dr.Start.Unix(), dr.End.Unix()) + return fmt.Sprintf("created_ts >= timestamp(%q) && created_ts < timestamp(%q)", + formatCELTimestamp(dr.Start), formatCELTimestamp(dr.End)) +} + +// formatCELTimestamp renders a time as an RFC3339 literal in UTC. +func formatCELTimestamp(t time.Time) string { + return t.UTC().Format(time.RFC3339) } func isLeapYear(year int) bool { diff --git a/spec/SEARCH.md b/spec/SEARCH.md index 0756abf..a4a0bde 100644 --- a/spec/SEARCH.md +++ b/spec/SEARCH.md @@ -16,10 +16,13 @@ GET /api/v1/memos?filter={CEL}&pageSize={N} ### Фильтрация по дате -API поддерживает CEL-фильтры по полю `created_ts` (Unix timestamp): +API поддерживает CEL-фильтры по полю `created_ts`. Начиная с memos 0.30.0 это +значение типа `timestamp`, поэтому границы диапазона задаются через +`timestamp("")` (в UTC); сравнение с голым Unix-числом больше не +компилируется: ``` -created_ts >= 1707696000 && created_ts < 1707782400 +created_ts >= timestamp("2024-02-12T00:00:00Z") && created_ts < timestamp("2024-02-13T00:00:00Z") ``` В качестве даты заметки используем `create_time` (поле `createTime` в JSON).