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

Method SetBookPublic

models/elasticsearch.go:437–463  ·  view source on GitHub ↗

设置书籍的公有和私有,需要根据文档同时更新文档的公有和私有

(bookId int, public bool)

Source from the content-addressed store, hash-verified

435
436// 设置书籍的公有和私有,需要根据文档同时更新文档的公有和私有
437func (this *ElasticSearchClient) SetBookPublic(bookId int, public bool) (err error) {
438 if !this.On {
439 return
440 }
441
442 if bookId <= 0 {
443 return
444 }
445
446 private := 1
447 if public {
448 private = 0
449 }
450
451 apiDoc := this.Host + this.Index + "/" + this.Type + "/_update_by_query"
452 bodyDoc := fmt.Sprintf(`{"query":{"term":{"book_id":%v}},"script":{"inline":"ctx._source.private = %v"}}`, bookId, private)
453
454 err = utils.HandleResponse(this.post(apiDoc).Body(bodyDoc).Response())
455 if err != nil {
456 return
457 }
458
459 apiBook := this.Host + this.Index + "/" + this.Type + "/book_" + strconv.Itoa(bookId) + "/_update"
460 bodyBook := fmt.Sprintf(`{"script" : "ctx._source.private=%v"}`, private)
461 err = utils.HandleResponse(this.post(apiBook).Body(bodyBook).Response())
462 return
463}
464
465//创建索引
466func (this *ElasticSearchClient) BuildIndex(es ElasticSearchData) (err error) {

Callers 2

PrivatelyOwnedMethod · 0.95
PrivatelyOwnedMethod · 0.95

Calls 3

postMethod · 0.95
HandleResponseFunction · 0.92
ResponseMethod · 0.80

Tested by

no test coverage detected