From db359d35b2fd9ee5e0df741a1b86c5b027c72648 Mon Sep 17 00:00:00 2001 From: pyr0ball Date: Wed, 17 Jun 2026 11:27:38 -0700 Subject: [PATCH] fix(search): qualify ambiguous column names with table alias in FTS JOIN Both log_fts and log_entries have timestamp_iso, severity, source_id, and matched_patterns columns. After the JOIN, unqualified references to any of these caused SQLite to raise 'ambiguous column name', silently falling back to the non-FTS scan path on every time-filtered or severity-filtered query. Prefix all filter conditions that touch FTS-mirror columns with f. to resolve the ambiguity. The e. prefix on tenant_id was already correct since tenant_id is not present in the FTS virtual table. --- app/services/search.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/services/search.py b/app/services/search.py index 90ad4d7..cc0f75c 100644 --- a/app/services/search.py +++ b/app/services/search.py @@ -244,19 +244,19 @@ def _sqlite_fts_search( params: list = [fts_query, tid] if severity: - conditions.append("severity = ?") + conditions.append("f.severity = ?") params.append(severity.upper()) if source_filter: - conditions.append("source_id LIKE ?") + conditions.append("f.source_id LIKE ?") params.append(f"%{source_filter}%") if pattern_filter: - conditions.append("matched_patterns LIKE ?") + conditions.append("f.matched_patterns LIKE ?") params.append(f'%"{pattern_filter}"%') if since: - conditions.append("timestamp_iso >= ?") + conditions.append("f.timestamp_iso >= ?") params.append(since) if until: - conditions.append("timestamp_iso <= ?") + conditions.append("f.timestamp_iso <= ?") params.append(until) if not include_repeats: conditions.append("f.repeat_count = 1")