@@ -20,6 +20,7 @@ import (
20
20
21
21
"github.com/blugelabs/bluge/analysis"
22
22
"github.com/go-ego/gse"
23
+ "github.com/rs/zerolog/log"
23
24
24
25
"github.com/zincsearch/zincsearch/pkg/bluge/analysis/lang/chs/analyzer"
25
26
"github.com/zincsearch/zincsearch/pkg/bluge/analysis/lang/chs/token"
@@ -51,36 +52,46 @@ var seg *gse.Segmenter
51
52
52
53
func init () {
53
54
seg = new (gse.Segmenter )
54
- enable := config .Global .Plugin .GSE .Enable // true / false
55
- embed := config .Global .Plugin .GSE .DictEmbed // small / big
55
+ enable := config .Global .Plugin .GSE .Enable // true / false
56
+ enableStop := config .Global .Plugin .GSE .EnableStop // true / false
57
+ embed := config .Global .Plugin .GSE .DictEmbed // small / big
56
58
embed = strings .ToUpper (embed )
57
- loadDict (enable , embed )
59
+ loadDict (enable , enableStop , embed )
58
60
}
59
61
60
- func loadDict (enable bool , embed string ) {
62
+ func loadDict (enable , enableStop bool , embed string ) {
61
63
if enable {
64
+ // load default dict
62
65
if embed == "BIG" {
63
66
_ = seg .LoadDictEmbed ("zh_s" )
64
- _ = seg .LoadStopEmbed ()
67
+ if enableStop {
68
+ _ = seg .LoadStopEmbed ()
69
+ }
65
70
} else {
66
71
_ = seg .LoadDictStr (_dictCHS )
67
- _ = seg .LoadStopStr (_dictStop )
72
+ if enableStop {
73
+ _ = seg .LoadStopStr (_dictStop )
74
+ }
75
+ }
76
+ // load user dict
77
+ dataPath := config .Global .Plugin .GSE .DictPath
78
+ userDict := dataPath + "/user.txt"
79
+ log .Info ().Msgf ("Loading Gse user dict... %s" , userDict )
80
+ if ok , _ := zutils .IsExist (userDict ); ok {
81
+ _ = seg .LoadDict (userDict )
82
+ }
83
+ stopDict := dataPath + "/stop.txt"
84
+ log .Info ().Msgf ("Loading Gse user stop... %s" , stopDict )
85
+ if ok , _ := zutils .IsExist (stopDict ); ok {
86
+ _ = seg .LoadStop (stopDict )
68
87
}
69
88
} else {
89
+ // load empty dict
70
90
_ = seg .LoadDictStr (`zinc` )
71
- _ = seg .LoadStopStr (_dictStop )
91
+ if enableStop {
92
+ _ = seg .LoadStopStr (_dictStop )
93
+ }
72
94
}
73
95
seg .Load = true
74
96
seg .SkipLog = true
75
-
76
- // load user dict
77
- dataPath := config .Global .Plugin .GSE .DictPath
78
- userDict := dataPath + "/user.txt"
79
- if ok , _ := zutils .IsExist (userDict ); ok {
80
- _ = seg .LoadDict (userDict )
81
- }
82
- stopDict := dataPath + "/stop.txt"
83
- if ok , _ := zutils .IsExist (stopDict ); ok {
84
- _ = seg .LoadStop (stopDict )
85
- }
86
97
}
0 commit comments