fix(search): restore unquoted multi-word date keywords via pre-parse quoting

"added:previous month" returned HTTP 400 after the whoosh-compat
migration. The unquoted spelling was never parser-native anywhere: v2
rewrote it to explicit bracket ranges app-side before whoosh saw the
string, and the deleted translation layer consumed it itself, so users
and saved views have relied on it continuously while whoosh-compat
deliberately scopes it out of its parser (its DIVERGENCES.md entry 19)
and understands the phrases natively only as quoted values.

parse_user_query now quotes the closed six-phrase vocabulary (previous
week/month/quarter/year, this month/year) when it directly follows a
date field's colon, before parsing. Only quoting happens app-side; every
date computation stays in whoosh-compat's grammar, unlike v2's rewrite,
which computed the ranges itself. Date field names derive from
PUBLIC_FIELDS, the field name matches case-sensitively (the parser's own
field tagging is case-sensitive), the phrase case-insensitively (the
grammar accepts any case in the quoted form), and already-quoted
spellings, TEXT fields, unfielded words and bracketed ranges are
untouched.

The previously xfailed end-to-end regression test now passes as a plain
test, and a new acceptance class pins unquoted == quoted == mixed-case
result sets on a boundary fixture, no-error parsing for the whole
vocabulary across all three date fields, and that "title:previous month"
stays an ordinary text search. docs/usage.md now states the two
spellings are equivalent after a date field.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WMsn6DgzbvSqh1pwy66VVF
This commit is contained in:
Trenton Holmes
2026-08-18 11:05:04 -07:00
co-authored by Claude Fable 5
parent a717684a60
commit 7bab9622c8
4 changed files with 154 additions and 16 deletions
-13
View File
@@ -720,19 +720,6 @@ class TestDocumentSearchApi(DirectoriesMixin, APITestCase):
self.assertEqual(results[0]["id"], 3)
self.assertEqual(results[0]["title"], "bank statement 3")
@pytest.mark.xfail(
reason=(
"whoosh-compat's DateParserPlugin intentionally drops whoosh's "
"'free' undelimited-date tagging mode (see "
"whoosh_compat.parser.dateparse.DateParserPlugin docstring), so "
"an unquoted multi-word date keyword like 'added:previous month' "
"no longer parses -- it now needs quoting ('added:\"previous "
"month\"'), unlike 'added:\"previous quarter\"' a few tests down "
"which already quotes. CONFIRMED REGRESSION vs whoosh-compat "
"migration; see task-10-report.md."
),
raises=AssertionError,
)
def test_search_added_previous_month_excludes_next_period_start(self) -> None:
"""
GIVEN: