创建索引
(es ElasticSearchData)
| 464 | |
| 465 | //创建索引 |
| 466 | func (this *ElasticSearchClient) BuildIndex(es ElasticSearchData) (err error) { |
| 467 | if !this.On { |
| 468 | return |
| 469 | } |
| 470 | |
| 471 | var ( |
| 472 | js []byte |
| 473 | _id string |
| 474 | ) |
| 475 | |
| 476 | if orm.Debug { |
| 477 | beego.Info("创建索引--------start--------") |
| 478 | fmt.Printf("内容:%+v\n", es) |
| 479 | beego.Info("创建索引-------- end --------") |
| 480 | } |
| 481 | |
| 482 | es.Content = this.html2Text(es.Content) |
| 483 | |
| 484 | if es.BookId > 0 { |
| 485 | _id = fmt.Sprintf("doc_%v", es.Id) |
| 486 | } else { |
| 487 | _id = fmt.Sprintf("book_%v", es.Id) |
| 488 | } |
| 489 | api := this.Host + this.Index + "/" + this.Type + "/" + _id |
| 490 | if js, err = json.Marshal(es); err == nil { |
| 491 | err = utils.HandleResponse(this.post(api).Body(js).Response()) |
| 492 | } |
| 493 | return |
| 494 | } |
| 495 | |
| 496 | // 查询分词 |
| 497 | func (this *ElasticSearchClient) SegWords(keyword string) string { |