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

Method SearchBookByLabel

models/book.go:718–741  ·  view source on GitHub ↗

search books with labels

(labels []string, limit int, excludeIds []int)

Source from the content-addressed store, hash-verified

716
717// search books with labels
718func (b *Book) SearchBookByLabel(labels []string, limit int, excludeIds []int) (bookIds []int, err error) {
719 bookIds = []int{}
720 if len(labels) == 0 {
721 return
722 }
723
724 rawRegex := strings.Join(labels, "|")
725
726 excludeClause := ""
727 if len(excludeIds) == 1 {
728 excludeClause = fmt.Sprintf("book_id != %d AND", excludeIds[0])
729 } else if len(excludeIds) > 1 {
730 excludeVal := strings.Replace(strings.Trim(fmt.Sprint(excludeIds), "[]"), " ", ",", -1)
731 excludeClause = fmt.Sprintf("book_id NOT IN (%s) AND", excludeVal)
732 }
733
734 sql := fmt.Sprintf("SELECT book_id FROM md_books WHERE %v label REGEXP ? ORDER BY star DESC LIMIT ?", excludeClause)
735 o := orm.NewOrm()
736 _, err = o.Raw(sql, rawRegex, limit).QueryRows(&bookIds)
737 if err != nil {
738 logs.Error("failed to execute sql: %s, err: %s", sql, err.Error())
739 }
740 return
741}
742
743// Copy 拷贝书籍项目
744// 1. 创建新的书籍,设置书籍的父级id为被拷贝的项目,并同步数据信息

Callers 1

listByDBWithLabelFunction · 0.95

Calls 1

ReplaceMethod · 0.45

Tested by

no test coverage detected