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

Method SearchDoc

controllers/api/CommonController.go:469–564  ·  view source on GitHub ↗

[OK]

()

Source from the content-addressed store, hash-verified

467
468// [OK]
469func (this *CommonController) SearchDoc() {
470 wd := this.GetString("wd")
471 if wd == "" {
472 this.Response(http.StatusBadRequest, messageBadRequest)
473 }
474
475 if models.NewOption().IsResponseEmptyForAPP(this.Version, wd) {
476 this.Response(http.StatusOK, messageSuccess, map[string]interface{}{"total": 0})
477 }
478
479 var (
480 page, _ = this.GetInt("page", 1)
481 size, _ = this.GetInt("size", 10)
482 ids []int
483 total int
484 docs []APIDoc
485 doc APIDoc
486 bookId = this.getBookIdByIdentify(this.GetString("identify"))
487 )
488
489 size = utils.RangeNumber(size, 10, maxPageSize)
490
491 if bookId > 0 {
492 page = 1
493 size = 2000
494 }
495
496 client := models.NewElasticSearchClient()
497
498 if client.On { // elasticsearch 进行全文搜索
499 result, err := models.NewElasticSearchClient().Search(wd, page, size, true, bookId)
500 if err != nil {
501 beego.Error(err.Error())
502 this.Response(http.StatusInternalServerError, messageInternalServerError)
503 }
504
505 total = result.Hits.Total
506 for _, item := range result.Hits.Hits {
507 ids = append(ids, item.Source.Id)
508 }
509
510 } else { //MySQL like 查询
511 result, count, err := models.NewDocumentSearchResult().SearchDocument(wd, bookId, page, size)
512 if err != nil {
513 beego.Error(err.Error())
514 this.Response(http.StatusInternalServerError, messageInternalServerError)
515 }
516 total = count
517 for _, book := range result {
518 ids = append(ids, book.DocumentId)
519 }
520 }
521
522 data := map[string]interface{}{"total": total}
523
524 if len(ids) > 0 {
525 var (
526 result []models.DocResult

Callers

nothing calls this directly

Calls 15

NewOptionFunction · 0.92
RangeNumberFunction · 0.92
NewElasticSearchClientFunction · 0.92
NewDocumentSearchResultFunction · 0.92
CopyObjectFunction · 0.92
GetTextFromHtmlFunction · 0.92
NewBookFunction · 0.92
ResponseMethod · 0.80
IsResponseEmptyForAPPMethod · 0.80
getBookIdByIdentifyMethod · 0.80
SearchDocumentMethod · 0.80
GetDocsByIdMethod · 0.80

Tested by

no test coverage detected