You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Boolean AND/OR operators in search_notes cause SQL parsing errors instead of filtering results.
Reproduction Steps
Execute: search_notes("term1 AND term2")
Observe SQL error instead of filtered results
Expected Behavior
Boolean AND operator should return results containing both terms.
Actual Behavior
SQL error: (sqlite3.OperationalError) no such column: test
Error Details
Error searching for 'tier1-test AND unicode': (sqlite3.OperationalError) no such column: test
[SQL:
SELECT
project_id,
id,
title,
permalink,
file_path,
type,
metadata,
from_id,
to_id,
relation_type,
entity_id,
content_snippet,
category,
created_at,
updated_at,
bm25(search_index) as score
FROM search_index
WHERE (title MATCH ? OR content_stems MATCH ?) AND project_id = ?
ORDER BY score ASC
LIMIT ?
OFFSET ?
]
[parameters: ('tier1-test AND unicode', 'tier1-test AND unicode', 30, 10, 0)]
Environment
Version: v0.13.8+
Discovered during: Live testing session 2025-06-26
Impact
Severity: Critical
Affects: All users attempting Boolean search queries
Workaround: Use simple keyword searches without Boolean operators
Potential Solution
The issue appears to be in FTS query parsing where hyphenated terms like "tier1-test" are being split incorrectly. The SQL parser treats the hyphen as a column separator rather than part of the search term.
Analysis and Fix for Boolean Search SQL Parsing Error ✅
I've analyzed the Boolean search parsing issue and implemented a comprehensive fix.
Todo List:
Read repository setup and guidelines
Analyze current search implementation
Identify the FTS query construction logic
Implement fix for Boolean operator parsing
Test the fix with various search scenarios
Run linting and type checking
Commit changes to branch
Root Cause Analysis:
The issue occurred in search_repository.py:248-252 where Boolean queries were passed unchanged to FTS5. When a query like "tier1-test AND unicode" was processed:
The method detected Boolean operators and passed the raw query to FTS5
FTS5 interpreted tier1-test as a column reference (column:term syntax)
Since test is not a valid column, it threw "no such column: test" error
The Fix:
I implemented a comprehensive solution with three new methods:
_prepare_boolean_query() - Parses Boolean queries to identify operators and terms
_prepare_single_term() - Handles individual term preparation with proper quoting
Updated _prepare_search_term() - Routes to appropriate handler based on query type
Key Features:
✅ Preserves Boolean operators (AND, OR, NOT) exactly as written
✅ Quotes terms with special characters (hyphens, dots, etc.) to prevent FTS5 syntax errors
✅ Handles complex expressions with parentheses and nested Boolean logic
✅ Maintains backward compatibility with existing simple Boolean queries
✅ Optimized for FTS5 - simple terms remain unquoted for best performance
Examples:
Original Query
Fixed Output
"tier1-test AND unicode"
"tier1-test" AND unicode
"config.json OR test-file"
"config.json" OR "test-file"
"hello AND world"
hello AND world (unchanged)
"(C++ OR python) NOT legacy"
("C++" OR python) NOT legacy
Testing:
Added comprehensive test cases for hyphenated terms with Boolean operators
Activity
phernandez commentedon Jun 26, 2025
@claude we found this when doing regression testing. Can you analyze the issue and evaluate a fix?
claude commentedon Jun 26, 2025
Claude finished @phernandez's task —— View job •
claude/issue-178-20250626_152657• Create PR ➔Analysis and Fix for Boolean Search SQL Parsing Error ✅
I've analyzed the Boolean search parsing issue and implemented a comprehensive fix.
Todo List:
Root Cause Analysis:
The issue occurred in
search_repository.py:248-252where Boolean queries were passed unchanged to FTS5. When a query like"tier1-test AND unicode"was processed:tier1-testas a column reference (column:term syntax)testis not a valid column, it threw "no such column: test" errorThe Fix:
I implemented a comprehensive solution with three new methods:
_prepare_boolean_query()- Parses Boolean queries to identify operators and terms_prepare_single_term()- Handles individual term preparation with proper quoting_prepare_search_term()- Routes to appropriate handler based on query typeKey Features:
Examples:
"tier1-test AND unicode""tier1-test" AND unicode"config.json OR test-file""config.json" OR "test-file""hello AND world"hello AND world(unchanged)"(C++ OR python) NOT legacy"("C++" OR python) NOT legacyTesting:
Changes Made:
src/basic_memory/repository/search_repository.py- Core search logic fixtests/repository/test_search_repository.py- Test coverage for new functionalityThe fix resolves the SQL parsing error while maintaining full compatibility with existing search functionality.
Next Steps:
Please test this fix by running:
fix: handle Boolean search syntax with hyphenated terms