Skip to content

Commit 2941c09

Browse files
committed
fix: simplify parser API - remove NewParserFromFields
Corrections based on code review: 1. Removed NewParserFromFields helper - single NewParser(model) API only 2. Updated all tests to use actual struct models instead of field slices 3. Tests now demonstrate proper usage: NewParser(StructModel{}) 4. Clean API: NewParser(model, config...) - no field slice constructors All tests passing with simplified API.
1 parent 3fd80cb commit 2941c09

2 files changed

Lines changed: 215 additions & 309 deletions

File tree

storage/search/lucene/parser.go

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -75,18 +75,7 @@ func NewParser(model any, config ...*ParserConfig) (*Parser, error) {
7575
return nil, err
7676
}
7777

78-
// Get config or use nil
79-
var cfg *ParserConfig
80-
if len(config) > 0 && config[0] != nil {
81-
cfg = config[0]
82-
}
83-
84-
return NewParserFromFields(fields, cfg), nil
85-
}
86-
87-
// NewParserFromFields creates a parser from an explicit list of fields.
88-
// This is primarily used for testing. Production code should use NewParser().
89-
func NewParserFromFields(fields []FieldInfo, config *ParserConfig) *Parser {
78+
// Build field map
9079
fieldMap := make(map[string]FieldInfo, len(fields))
9180
for _, f := range fields {
9281
fieldMap[f.Name] = f
@@ -97,15 +86,16 @@ func NewParserFromFields(fields []FieldInfo, config *ParserConfig) *Parser {
9786
maxDepth := DefaultMaxDepth
9887
maxTerms := DefaultMaxTerms
9988

100-
if config != nil {
101-
if config.MaxQueryLength > 0 {
102-
maxQueryLength = config.MaxQueryLength
89+
if len(config) > 0 && config[0] != nil {
90+
cfg := config[0]
91+
if cfg.MaxQueryLength > 0 {
92+
maxQueryLength = cfg.MaxQueryLength
10393
}
104-
if config.MaxDepth > 0 {
105-
maxDepth = config.MaxDepth
94+
if cfg.MaxDepth > 0 {
95+
maxDepth = cfg.MaxDepth
10696
}
107-
if config.MaxTerms > 0 {
108-
maxTerms = config.MaxTerms
97+
if cfg.MaxTerms > 0 {
98+
maxTerms = cfg.MaxTerms
10999
}
110100
}
111101

@@ -115,7 +105,7 @@ func NewParserFromFields(fields []FieldInfo, config *ParserConfig) *Parser {
115105
MaxDepth: maxDepth,
116106
MaxTerms: maxTerms,
117107
fieldMap: fieldMap,
118-
}
108+
}, nil
119109
}
120110

121111
// extractFields uses reflection to extract field metadata from a struct.

0 commit comments

Comments
 (0)