forked from huichen/wukong
-
Notifications
You must be signed in to change notification settings - Fork 0
/
engine_init_options.go
126 lines (100 loc) · 3.38 KB
/
engine_init_options.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package types
import (
"log"
"runtime"
)
var (
// EngineInitOptions的默认值
defaultNumSegmenterThreads = runtime.NumCPU()
defaultNumShards = 2
defaultIndexerBufferLength = runtime.NumCPU()
defaultNumIndexerThreadsPerShard = runtime.NumCPU()
defaultRankerBufferLength = runtime.NumCPU()
defaultNumRankerThreadsPerShard = runtime.NumCPU()
defaultDefaultRankOptions = RankOptions{
ScoringCriteria: RankByBM25{},
}
defaultIndexerInitOptions = IndexerInitOptions{
IndexType: FrequenciesIndex,
BM25Parameters: &defaultBM25Parameters,
}
defaultBM25Parameters = BM25Parameters{
K1: 2.0,
B: 0.75,
}
defaultPersistentStorageShards = 8
)
type EngineInitOptions struct {
// 是否使用分词器
// 默认使用,否则在启动阶段跳过SegmenterDictionaries和StopTokenFile设置
// 如果你不需要在引擎内分词,可以将这个选项设为true
// 注意,如果你不用分词器,那么在调用IndexDocument时DocumentIndexData中的Content会被忽略
NotUsingSegmenter bool
// 半角逗号分隔的字典文件,具体用法见
// sego.Segmenter.LoadDictionary函数的注释
SegmenterDictionaries string
// 停用词文件
StopTokenFile string
// 分词器线程数
NumSegmenterThreads int
// 索引器和排序器的shard数目
// 被检索/排序的文档会被均匀分配到各个shard中
NumShards int
// 索引器的信道缓冲长度
IndexerBufferLength int
// 索引器每个shard分配的线程数
NumIndexerThreadsPerShard int
// 排序器的信道缓冲长度
RankerBufferLength int
// 排序器每个shard分配的线程数
NumRankerThreadsPerShard int
// 索引器初始化选项
IndexerInitOptions *IndexerInitOptions
// 默认的搜索选项
DefaultRankOptions *RankOptions
// 是否使用持久数据库,以及数据库文件保存的目录和裂分数目
UsePersistentStorage bool
PersistentStorageFolder string
PersistentStorageShards int
}
// 初始化EngineInitOptions,当用户未设定某个选项的值时用默认值取代
func (options *EngineInitOptions) Init() {
if !options.NotUsingSegmenter {
if options.SegmenterDictionaries == "" {
log.Fatal("字典文件不能为空")
}
}
if options.NumSegmenterThreads == 0 {
options.NumSegmenterThreads = defaultNumSegmenterThreads
}
if options.NumShards == 0 {
options.NumShards = defaultNumShards
}
if options.IndexerBufferLength == 0 {
options.IndexerBufferLength = defaultIndexerBufferLength
}
if options.NumIndexerThreadsPerShard == 0 {
options.NumIndexerThreadsPerShard = defaultNumIndexerThreadsPerShard
}
if options.RankerBufferLength == 0 {
options.RankerBufferLength = defaultRankerBufferLength
}
if options.NumRankerThreadsPerShard == 0 {
options.NumRankerThreadsPerShard = defaultNumRankerThreadsPerShard
}
if options.IndexerInitOptions == nil {
options.IndexerInitOptions = &defaultIndexerInitOptions
}
if options.IndexerInitOptions.BM25Parameters == nil {
options.IndexerInitOptions.BM25Parameters = &defaultBM25Parameters
}
if options.DefaultRankOptions == nil {
options.DefaultRankOptions = &defaultDefaultRankOptions
}
if options.DefaultRankOptions.ScoringCriteria == nil {
options.DefaultRankOptions.ScoringCriteria = defaultDefaultRankOptions.ScoringCriteria
}
if options.PersistentStorageShards == 0 {
options.PersistentStorageShards = defaultPersistentStorageShards
}
}