Skip to content

Commit 307909a

Browse files
committed
feature: add term group to lucene
1 parent bca952d commit 307909a

9 files changed

+597
-60
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
.idea/
1+
.idea/
2+
.vscode/

lucene_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ func TestLucene(t *testing.T) {
255255
LogicTermGroup: &term.LogicTermGroup{
256256
OrTermGroup: &term.OrTermGroup{
257257
AndTermGroup: &term.AndTermGroup{
258-
TermGroupElem: &term.TermGroupElem{
258+
FieldTermGroup: &term.FieldTermGroup{
259259
SingleTerm: &term.SingleTerm{Begin: "txt"},
260260
},
261261
},
@@ -265,7 +265,7 @@ func TestLucene(t *testing.T) {
265265
OrSymbol: &operator.OrSymbol{Symbol: "OR"},
266266
OrTermGroup: &term.OrTermGroup{
267267
AndTermGroup: &term.AndTermGroup{
268-
TermGroupElem: &term.TermGroupElem{
268+
FieldTermGroup: &term.FieldTermGroup{
269269
SingleTerm: &term.SingleTerm{Begin: "foo"},
270270
},
271271
},
@@ -275,7 +275,7 @@ func TestLucene(t *testing.T) {
275275
OrSymbol: &operator.OrSymbol{Symbol: "OR"},
276276
OrTermGroup: &term.OrTermGroup{
277277
AndTermGroup: &term.AndTermGroup{
278-
TermGroupElem: &term.TermGroupElem{
278+
FieldTermGroup: &term.FieldTermGroup{
279279
SingleTerm: &term.SingleTerm{Begin: "bar"},
280280
},
281281
},
@@ -337,12 +337,12 @@ func TestLucene(t *testing.T) {
337337
Term: &term.Term{
338338
TermGroup: &term.TermGroup{
339339
LogicTermGroup: &term.LogicTermGroup{
340-
OrTermGroup: &term.OrTermGroup{AndTermGroup: &term.AndTermGroup{TermGroupElem: &term.TermGroupElem{SingleTerm: &term.SingleTerm{Begin: "foo"}}}},
340+
OrTermGroup: &term.OrTermGroup{AndTermGroup: &term.AndTermGroup{FieldTermGroup: &term.FieldTermGroup{SingleTerm: &term.SingleTerm{Begin: "foo"}}}},
341341
OSTermGroup: []*term.OSTermGroup{
342342
{
343343
OrSymbol: &operator.OrSymbol{Symbol: "or"},
344344
OrTermGroup: &term.OrTermGroup{
345-
AndTermGroup: &term.AndTermGroup{TermGroupElem: &term.TermGroupElem{SingleTerm: &term.SingleTerm{Begin: "bar"}}},
345+
AndTermGroup: &term.AndTermGroup{FieldTermGroup: &term.FieldTermGroup{SingleTerm: &term.SingleTerm{Begin: "bar"}}},
346346
},
347347
},
348348
},

term/compund_term.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,14 @@ func (t *FuzzyTerm) Value(f func(string) (interface{}, error)) (interface{}, err
138138
}
139139

140140
// term group element
141-
type TermGroupElem struct {
141+
type FieldTermGroup struct {
142142
SingleTerm *SingleTerm `parser:" @@" json:"single_term"`
143143
PhraseTerm *PhraseTerm `parser:"| @@" json:"phrase_term"`
144144
SRangeTerm *SRangeTerm `parser:"| @@" json:"single_range_term"`
145145
DRangeTerm *DRangeTerm `parser:"| @@" json:"double_range_term"`
146146
}
147147

148-
func (t *TermGroupElem) String() string {
148+
func (t *FieldTermGroup) String() string {
149149
if t == nil {
150150
return ""
151151
} else if t.SingleTerm != nil {
@@ -161,7 +161,7 @@ func (t *TermGroupElem) String() string {
161161
}
162162
}
163163

164-
func (t *TermGroupElem) GetTermType() TermType {
164+
func (t *FieldTermGroup) GetTermType() TermType {
165165
if t == nil {
166166
return UNKNOWN_TERM_TYPE
167167
} else if t.SingleTerm != nil {
@@ -177,7 +177,7 @@ func (t *TermGroupElem) GetTermType() TermType {
177177
}
178178
}
179179

180-
func (t *TermGroupElem) Value(f func(string) (interface{}, error)) (interface{}, error) {
180+
func (t *FieldTermGroup) Value(f func(string) (interface{}, error)) (interface{}, error) {
181181
if t == nil {
182182
return nil, ErrEmptyTermGroupElem
183183
} else if t.SingleTerm != nil {

term/compund_term_test.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ func TestFuzzyTerm(t *testing.T) {
439439
func TestTermGroupElem(t *testing.T) {
440440
type test struct {
441441
name string
442-
input *TermGroupElem
442+
input *FieldTermGroup
443443
tType TermType
444444
valueS interface{}
445445
wantErr error
@@ -455,14 +455,14 @@ func TestTermGroupElem(t *testing.T) {
455455
},
456456
{
457457
name: "test_empty_case02",
458-
input: &TermGroupElem{},
458+
input: &FieldTermGroup{},
459459
tType: UNKNOWN_TERM_TYPE,
460460
valueS: "",
461461
wantErr: nil,
462462
},
463463
{
464464
name: "test_single",
465-
input: &TermGroupElem{
465+
input: &FieldTermGroup{
466466
SingleTerm: &SingleTerm{Begin: "123"},
467467
},
468468
tType: SINGLE_TERM_TYPE,
@@ -471,7 +471,7 @@ func TestTermGroupElem(t *testing.T) {
471471
},
472472
{
473473
name: "test_phrase",
474-
input: &TermGroupElem{
474+
input: &FieldTermGroup{
475475
PhraseTerm: &PhraseTerm{Chars: []string{"123"}},
476476
},
477477
tType: PHRASE_TERM_TYPE,
@@ -480,7 +480,7 @@ func TestTermGroupElem(t *testing.T) {
480480
},
481481
{
482482
name: "test_s_range",
483-
input: &TermGroupElem{
483+
input: &FieldTermGroup{
484484
SRangeTerm: &SRangeTerm{
485485
Symbol: ">",
486486
Value: &RangeValue{SingleValue: []string{"123"}},
@@ -497,7 +497,7 @@ func TestTermGroupElem(t *testing.T) {
497497
},
498498
{
499499
name: "test_d_range",
500-
input: &TermGroupElem{
500+
input: &FieldTermGroup{
501501
DRangeTerm: &DRangeTerm{
502502
LBRACKET: "{",
503503
RBRACKET: "}",
@@ -522,8 +522,8 @@ func TestTermGroupElem(t *testing.T) {
522522
assert.Equal(t, tt.valueS, v)
523523
})
524524
}
525-
var out *TermGroupElem
525+
var out *FieldTermGroup
526526
assert.Empty(t, out.String())
527-
out = &TermGroupElem{}
527+
out = &FieldTermGroup{}
528528
assert.Empty(t, out.String())
529529
}

term/term_group_logic.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,16 @@ func (t *OSTermGroup) String() string {
5858
type AndTermGroup struct {
5959
NotSymbol *op.NotSymbol `parser:"@@?" json:"not_symbol"`
6060
ParenTermGroup *ParenTermGroup `parser:"( @@ " json:"paren_term_group"`
61-
TermGroupElem *TermGroupElem `parser:"| @@)" json:"term_group_elem"`
61+
FieldTermGroup *FieldTermGroup `parser:"| @@)" json:"field_term_group"`
6262
}
6363

6464
func (t *AndTermGroup) String() string {
6565
if t == nil {
6666
return ""
6767
} else if t.ParenTermGroup != nil {
6868
return t.NotSymbol.String() + t.ParenTermGroup.String()
69-
} else if t.TermGroupElem != nil {
70-
return t.NotSymbol.String() + t.TermGroupElem.String()
69+
} else if t.FieldTermGroup != nil {
70+
return t.NotSymbol.String() + t.FieldTermGroup.String()
7171
} else {
7272
return ""
7373
}

0 commit comments

Comments
 (0)