MCPcopy Index your code
hub / github.com/TruthHun/DocHub / Init

Method Init

models/ElasticSearchModel.go:127–199  ·  view source on GitHub ↗

初始化全文搜索客户端,包括检查索引是否存在,mapping设置等

()

Source from the content-addressed store, hash-verified

125
126//初始化全文搜索客户端,包括检查索引是否存在,mapping设置等
127func (this *ElasticSearchClient) Init() (err error) {
128 if !this.On { //未开启ElasticSearch,则不初始化
129 return
130 }
131 //检测是否能ping同
132 if err = this.ping(); err == nil {
133 //检测索引是否存在;索引不存在,则创建索引;如果索引存在,则直接跳过初始化
134 if err = this.existIndex(); err != nil {
135 //创建索引成功
136 if err = this.createIndex(); err == nil {
137 //创建mapping
138 js := `{
139 "properties": {
140 "Title": {
141 "type": "text",
142 "analyzer": "ik_max_word",
143 "search_analyzer": "ik_smart"
144 },
145 "Keywords": {
146 "type": "text",
147 "analyzer": "ik_max_word",
148 "search_analyzer": "ik_smart"
149 },
150 "Description": {
151 "type": "text",
152 "analyzer": "ik_max_word",
153 "search_analyzer": "ik_smart"
154 },
155 "Vcnt": {
156 "type": "integer"
157 },
158 "Ccnt": {
159 "type": "integer"
160 },
161 "Dcnt": {
162 "type": "integer"
163 },
164 "Score": {
165 "type": "integer"
166 },
167 "Size": {
168 "type": "integer"
169 },
170 "Page": {
171 "type": "integer"
172 },
173 "DocType": {
174 "type": "integer"
175 },
176 "DsId": {
177 "type": "integer"
178 }
179 }
180}`
181 if helper.Debug {
182 beego.Debug(" ==== ElasticSearch初始化mapping ==== ")
183 beego.Info(js)
184 beego.Debug(" ==== ElasticSearch初始化mapping ==== ")

Callers 3

RebuildAllIndexMethod · 0.95
InstallMethod · 0.80
GetMethod · 0.80

Calls 5

pingMethod · 0.95
existIndexMethod · 0.95
createIndexMethod · 0.95
postMethod · 0.95
ResponseMethod · 0.80

Tested by

no test coverage detected