Commit 154dbed
committed
feat: enhance Lucene query parser to support full Apache Lucene syntax
Implements comprehensive Apache Lucene query parser syntax support as specified
in https://lucene.apache.org/core/2_9_4/queryparsersyntax.html
- **Quoted phrases**: "hello world" for exact matching
- **Alternative boolean operators**: && (AND), || (OR), ! (NOT)
- **Required operator**: +term (must match)
- **Prohibited operator**: -term (must not match)
- **Range queries**: [min TO max] (inclusive), {min TO max} (exclusive)
- **Open-ended ranges**: [18 TO *], [* TO 100]
- **Date ranges**: [2024-01-01 TO 2024-12-31]
- **Wildcard searches**: Enhanced support for *, ? patterns
- **Grouping**: Complex nested boolean expressions
- **Special character handling**: Backslash escaping support
- New lexer (lexer.go) for proper tokenization of all Lucene operators
- Enhanced parser (parser_new.go) with recursive descent parsing
- Comparison operators support (>, <, >=, <=) for range queries
- Automatic parser selection based on query syntax
- Backward compatibility with existing simple queries
- **SQL**: Generates parameterized WHERE clauses with comparison operators
- **DynamoDB PartiQL**: Converts to PartiQL with range support
- **Map format**: Preserves all query semantics for custom backends
- Comprehensive test suite (parser_test.go) with 60+ test cases
- Tests for all new operators and syntax features
- Performance benchmarks included
- Coverage for edge cases and complex nested queries
- Complete README with usage examples
- Feature matrix showing supported syntax
- Backend compatibility notes
- Performance characteristics
- Known limitations documented
```go
// Range queries
"age:[18 TO 65] AND status:active"
// Alternative operators
"(name:john || name:jane) && !status:inactive"
// Quoted phrases with wildcards
`title:"Apache Lucene" AND email:*@example.com`
// Complex nested queries
"(name:john* OR email:*@example.com) AND age:[25 TO *]"
```
- Zero breaking changes to existing API
- Enhanced parser auto-selected for advanced syntax
- Legacy parser maintained for simple queries
- Best-effort conversion for backends without native support
- Range queries converted to comparison operators in SQL
- Fuzzy/proximity searches approximated with wildcards1 parent b799c39 commit 154dbed
7 files changed
Lines changed: 2042 additions & 343 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| 39 | + | |
39 | 40 | | |
40 | 41 | | |
41 | 42 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
| 78 | + | |
| 79 | + | |
78 | 80 | | |
79 | 81 | | |
80 | 82 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
97 | | - | |
| 97 | + | |
| 98 | + | |
98 | 99 | | |
99 | 100 | | |
100 | 101 | | |
101 | 102 | | |
102 | | - | |
| 103 | + | |
103 | 104 | | |
104 | 105 | | |
105 | | - | |
| 106 | + | |
106 | 107 | | |
107 | 108 | | |
108 | 109 | | |
| |||
0 commit comments