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

Method Count

models/elasticsearch.go:528–550  ·  view source on GitHub ↗

查询索引量 @return count 统计数据 @return err 错误

()

Source from the content-addressed store, hash-verified

526//@return count 统计数据
527//@return err 错误
528func (this *ElasticSearchClient) Count() (count int, err error) {
529 if !this.On {
530 err = errors.New("未启用ElasticSearch")
531 return
532 }
533 api := this.Host + this.Index + "/" + this.Type + "/_count"
534 if resp, errResp := this.get(api).Response(); errResp != nil {
535 err = errResp
536 } else {
537 defer resp.Body.Close()
538 b, _ := ioutil.ReadAll(resp.Body)
539 body := string(b)
540 if resp.StatusCode >= http.StatusMultipleChoices || resp.StatusCode < http.StatusOK {
541 err = errors.New(resp.Status + ";" + body)
542 } else {
543 var cnt ElasticSearchCount
544 if err = json.Unmarshal(b, &cnt); err == nil {
545 count = cnt.Count
546 }
547 }
548 }
549 return
550}
551
552// 删除书籍索引
553func (this *ElasticSearchClient) DeleteIndex(id int, isBook bool) (err error) {

Callers

nothing calls this directly

Calls 3

getMethod · 0.95
stringFunction · 0.85
ResponseMethod · 0.80

Tested by

no test coverage detected