MCPcopy Index your code
hub / github.com/TruthHun/BookStack / SegWords

Method SegWords

models/elasticsearch.go:497–523  ·  view source on GitHub ↗

查询分词

(keyword string)

Source from the content-addressed store, hash-verified

495
496// 查询分词
497func (this *ElasticSearchClient) SegWords(keyword string) string {
498 if !this.On {
499 return keyword
500 }
501 api := this.Host + this.Index + "/_analyze"
502 req := this.post(api)
503 keyword = strings.Replace(keyword, "\\", " ", -1)
504 keyword = strings.Replace(keyword, "\"", " ", -1)
505 body := `{"text":"` + keyword + `","tokenizer": "ik_max_word"}`
506 req.Body(body)
507 if orm.Debug {
508 beego.Info(api)
509 beego.Info(body)
510 }
511 if js, err := req.String(); err == nil {
512 var tokens Tokens
513 json.Unmarshal([]byte(js), &tokens)
514 if len(tokens.Tokens) > 0 {
515 var words []string
516 for _, token := range tokens.Tokens {
517 words = append(words, token.Token)
518 }
519 return strings.Join(words, ",")
520 }
521 }
522 return keyword
523}
524
525//查询索引量
526//@return count 统计数据

Callers 3

SearchMethod · 0.95
ResultMethod · 0.95
ReadMethod · 0.80

Calls 3

postMethod · 0.95
appendFunction · 0.50
ReplaceMethod · 0.45

Tested by

no test coverage detected