MCPcopy Create free account
hub / github.com/TruthHun/BookStack / SearchBook

Method SearchBook

models/book.go:698–715  ·  view source on GitHub ↗

搜索书籍,这里只返回book_id

(wd string, page, size int)

Source from the content-addressed store, hash-verified

696
697// 搜索书籍,这里只返回book_id
698func (n *Book) SearchBook(wd string, page, size int) (books []Book, cnt int, err error) {
699 sqlFmt := "select %v from md_books where privately_owned=0 and (book_name like ? or label like ? or description like ?) order by star desc"
700 sqlCount := fmt.Sprintf(sqlFmt, "count(book_id) cnt")
701 sql := fmt.Sprintf(sqlFmt, "book_id")
702
703 var count struct{ Cnt int }
704 wd = "%" + wd + "%"
705
706 o := orm.NewOrm()
707
708 err = o.Raw(sqlCount, wd, wd, wd).QueryRow(&count)
709 if count.Cnt > 0 {
710 cnt = count.Cnt
711 _, err = o.Raw(sql+" limit ? offset ?", wd, wd, wd, size, (page-1)*size).QueryRows(&books)
712 }
713
714 return
715}
716
717// search books with labels
718func (b *Book) SearchBookByLabel(labels []string, limit int, excludeIds []int) (bookIds []int, err error) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected