查询分词
(keyword string)
| 495 | |
| 496 | // 查询分词 |
| 497 | func (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 统计数据 |