From 8e8cc990c4251973f980ebfbb112f52992be9b03 Mon Sep 17 00:00:00 2001 From: Anton Vakhrushev Date: Thu, 6 Aug 2026 12:21:53 +0300 Subject: [PATCH] =?UTF-8?q?search:=20=D1=84=D0=B8=D0=BB=D1=8C=D1=82=D1=80?= =?UTF-8?q?=D1=8B=20created=5Fts=20=D0=BF=D0=B5=D1=80=D0=B5=D0=B2=D0=B5?= =?UTF-8?q?=D0=B4=D0=B5=D0=BD=D1=8B=20=D0=BD=D0=B0=20timestamp=20=D0=B4?= =?UTF-8?q?=D0=BB=D1=8F=20memos=200.30?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit В memos 0.30.0 поле created_ts в CEL стало типом timestamp, и сравнение с Unix-числом перестало компилироваться. Границы диапазона теперь формируются как timestamp("") в UTC. Co-Authored-By: Claude Opus 5 (1M context) --- internal/search/tiers.go | 11 +++++++++-- spec/SEARCH.md | 7 +++++-- 2 files changed, 14 insertions(+), 4 deletions(-) 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).