From dea7b2c77be0f5d5df1fbf816fed9e8a9428dbf9 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Sun, 19 Apr 2026 13:32:10 -0700 Subject: [PATCH] Normalize --- src/documents/search/_query.py | 4 ++-- src/documents/tests/search/test_query.py | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/documents/search/_query.py b/src/documents/search/_query.py index b68c2d050..dbedc2973 100644 --- a/src/documents/search/_query.py +++ b/src/documents/search/_query.py @@ -336,7 +336,7 @@ def rewrite_natural_date_keywords(query: str, tz: tzinfo) -> str: - Compact 14-digit dates (YYYYMMDDHHmmss) - Whoosh relative ranges ([-7 days to now], [now-1h TO now+2h]) - 8-digit dates with field awareness (created:20240115) - - Natural keywords (field:today, field:last_week, etc.) + - Natural keywords (field:today, field:"previous quarter", etc.) Args: query: Raw user query string @@ -355,7 +355,7 @@ def rewrite_natural_date_keywords(query: str, tz: tzinfo) -> str: def _replace(m: regex.Match[str]) -> str: field = m.group("field") - keyword = m.group("quoted") or m.group("bare") + keyword = (m.group("quoted") or m.group("bare")).lower() if field in _DATE_ONLY_FIELDS: return f"{field}:{_date_only_range(keyword, tz)}" return f"{field}:{_datetime_range(keyword, tz)}" diff --git a/src/documents/tests/search/test_query.py b/src/documents/tests/search/test_query.py index fac1a9cee..05213bad6 100644 --- a/src/documents/tests/search/test_query.py +++ b/src/documents/tests/search/test_query.py @@ -110,7 +110,6 @@ class TestCreatedDateField: pytest.param( "created", "previous year", - "2026-03-23T00:00:00Z", "2025-01-01T00:00:00Z", "2026-01-01T00:00:00Z", id="previous_year", @@ -135,7 +134,7 @@ class TestCreatedDateField: def test_this_month_december_wraps_to_next_year(self) -> None: # December: next month must roll over to January 1 of next year lo, hi = _range( - rewrite_natural_date_keywords("created:this_month", UTC), + rewrite_natural_date_keywords("created:this month", UTC), "created", ) assert lo == "2026-12-01T00:00:00Z" @@ -145,7 +144,7 @@ class TestCreatedDateField: def test_last_month_january_wraps_to_previous_year(self) -> None: # January: last month must roll back to December 1 of previous year lo, hi = _range( - rewrite_natural_date_keywords("created:last_month", UTC), + rewrite_natural_date_keywords("created:previous month", UTC), "created", ) assert lo == "2025-12-01T00:00:00Z"