fix(176): compile date values to index yyyyMMdd format; guard Advanced toggle
Build ErsatzTV Image / CI image pin matches docker/ci (pull_request) Successful in 6s
Build ErsatzTV Image / Docs update reminder (pull_request) Successful in 16s
Build ErsatzTV Image / decisions.md append-only (pull_request) Successful in 11s
Build ErsatzTV Image / Build & test (.NET) (pull_request) Successful in 7m22s
Build ErsatzTV Image / API docs in sync (OpenAPI + endpoint index) (pull_request) Successful in 17m57s
Build ErsatzTV Image / Functional E2E (curl contracts) (pull_request) Successful in 20m20s
Build ErsatzTV Image / EF migration integrity (SQLite + MySql) (pull_request) Successful in 25m57s
Build ErsatzTV Image / Build & push image (amd64) (pull_request) Has been skipped
Build ErsatzTV Image / Formatting (changed .cs conform to .editorconfig) (pull_request) Successful in 44m33s

This commit is contained in:
2026-07-18 02:43:54 +02:00
parent c91c34f113
commit 3b5a78a08f
5 changed files with 40 additions and 11 deletions
+7 -2
View File
@@ -31,8 +31,13 @@ describe('compile', () => {
});
it('emits date ranges', () => {
expect(compile({ match: 'all', children: [{ field: 'release_date', operator: 'after', value: '2000-01-01' }] })).toBe('release_date:{2000-01-01 TO *}');
expect(compile({ match: 'all', children: [{ field: 'release_date', operator: 'before', value: '2010-01-01' }] })).toBe('release_date:{* TO 2010-01-01}');
expect(compile({ match: 'all', children: [{ field: 'release_date', operator: 'after', value: '2000-01-01' }] })).toBe('release_date:{20000101 TO *}');
expect(compile({ match: 'all', children: [{ field: 'release_date', operator: 'before', value: '2010-01-01' }] })).toBe('release_date:{* TO 20100101}');
});
it('compiles date values to the index yyyyMMdd format', () => {
expect(compile({ match: 'all', children: [{ field: 'release_date', operator: 'after', value: '2000-01-01' }] })).toBe('release_date:{20000101 TO *}');
expect(compile({ match: 'all', children: [{ field: 'release_date', operator: 'between', value: '2000-01-01', value2: '2010-12-31' }] })).toBe('release_date:[20000101 TO 20101231]');
});
it('joins by AND / OR and parenthesizes nested groups', () => {
+11 -4
View File
@@ -13,6 +13,13 @@ function escapeWild(value: string): string {
return value.replace(WILD_SPECIAL, '\\$1');
}
// Date inputs arrive as yyyy-MM-dd, but the index stores dates as yyyyMMdd with lexicographic range
// matching — a dashed bound sorts before same-year terms. Normalize date-shaped values to yyyyMMdd.
// Numbers never match this shape, so this is a no-op for numeric ranges.
function normalizeDate(value: string): string {
return /^\d{4}-\d{2}-\d{2}$/.test(value) ? value.replace(/-/g, '') : value;
}
function compileRule(rule: Rule): string {
const f = rule.field;
const v = rule.value;
@@ -28,15 +35,15 @@ function compileRule(rule: Rule): string {
case 'startsWith':
return `${f}:${escapeWild(v)}*`;
case 'eq':
return `${f}:${v}`;
return `${f}:${normalizeDate(v)}`;
case 'gt':
case 'after':
return `${f}:{${v} TO *}`;
return `${f}:{${normalizeDate(v)} TO *}`;
case 'lt':
case 'before':
return `${f}:{* TO ${v}}`;
return `${f}:{* TO ${normalizeDate(v)}}`;
case 'between':
return `${f}:[${v} TO ${rule.value2 ?? ''}]`;
return `${f}:[${normalizeDate(v)} TO ${normalizeDate(rule.value2 ?? '')}]`;
default:
return '';
}
+9
View File
@@ -33,6 +33,15 @@ describe('parse', () => {
expect(parse('minutes:42', FIELDS)).toEqual({ match: 'all', children: [{ field: 'minutes', operator: 'eq', value: '42' }] });
});
it('round-trips date ranges (yyyy-MM-dd <-> yyyyMMdd)', () => {
for (const g of [
{ match: 'all' as const, children: [{ field: 'release_date', operator: 'after' as const, value: '2005-06-15' }] },
{ match: 'all' as const, children: [{ field: 'release_date', operator: 'between' as const, value: '2000-01-01', value2: '2010-12-31' }] }
]) {
expect(parse(compile(g), FIELDS)).toEqual(g);
}
});
it('parses a nested group', () => {
expect(parse('type:"movie" AND (genre:"Horror" OR genre:"Thriller")', FIELDS)).toEqual({
match: 'all',
+9 -3
View File
@@ -31,6 +31,11 @@ function splitTopLevel(input: string): { parts: string[]; match: 'all' | 'any' }
return { parts, match: allAnd ? 'all' : 'any' };
}
// Reverse of compile's date normalization: the index format yyyyMMdd back to the input's yyyy-MM-dd.
function fromIndexDate(value: string): string {
return /^\d{8}$/.test(value) ? `${value.slice(0, 4)}-${value.slice(4, 6)}-${value.slice(6, 8)}` : value;
}
function unquote(value: string): string {
return value.replace(/\\(["\\])/g, '$1');
}
@@ -61,9 +66,10 @@ function parseAtom(atom: string, fieldTypes: Record<string, FieldType>): Rule |
if (range) {
const [, , lo, hi, close] = range;
if (type !== 'number' && type !== 'date') return null;
if (close === ']') return mk(field, 'between', lo, hi);
if (lo === '*') return mk(field, type === 'date' ? 'before' : 'lt', hi);
if (hi === '*') return mk(field, type === 'date' ? 'after' : 'gt', lo);
const fmt = (x: string) => (type === 'date' ? fromIndexDate(x) : x);
if (close === ']') return mk(field, 'between', fmt(lo), fmt(hi));
if (lo === '*') return mk(field, type === 'date' ? 'before' : 'lt', fmt(hi));
if (hi === '*') return mk(field, type === 'date' ? 'after' : 'gt', fmt(lo));
return null;
}
+4 -2
View File
@@ -330,8 +330,10 @@ function SmartDialog({
</Button>
<Button
onClick={() => {
setQuery(compile(group));
setMode('advanced');
if (mode !== 'advanced') {
setQuery(compile(group));
setMode('advanced');
}
}}
size="sm"
variant={mode === 'advanced' ? 'primary' : 'secondary'}