搜索书籍,这里只返回book_id
(wd string, page, size int)
| 696 | |
| 697 | // 搜索书籍,这里只返回book_id |
| 698 | func (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 |
| 718 | func (b *Book) SearchBookByLabel(labels []string, limit int, excludeIds []int) (bookIds []int, err error) { |
nothing calls this directly
no outgoing calls
no test coverage detected