Skip to content

Commit 7e7438c

Browse files
committed
相关书籍优化
1 parent 8d8ca7a commit 7e7438c

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

models/releate_book.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func (r *RelateBook) Lists(bookId int, limit ...int) (books []Book) {
2929
return
3030
}
3131

32-
length := 6
32+
length := 12
3333
if len(limit) > 0 && limit[0] > 0 {
3434
length = limit[0]
3535
}
@@ -89,12 +89,14 @@ func (r *RelateBook) Lists(bookId int, limit ...int) (books []Book) {
8989
func listByES(book *Book, length int) (ids []int) {
9090
client := NewElasticSearchClient()
9191
client.IsRelateSearch = true
92-
client.Timeout = 1 * time.Second
92+
client.Timeout = 3 * time.Second
93+
listRows := 13 // 这里要填 13,因为有可能返回的id恰好是本书的id
9394
keyWord := book.Label
9495
if len(keyWord) == 0 {
9596
keyWord = book.BookName
9697
}
97-
res, err := client.Search(keyWord, 1, 12, false)
98+
99+
res, err := client.Search(keyWord, 1, listRows, false)
98100
if err != nil {
99101
beego.Error(err.Error())
100102
return
@@ -105,7 +107,7 @@ func listByES(book *Book, length int) (ids []int) {
105107
if len(ids) >= length {
106108
break
107109
}
108-
if item.Source.Id == bookId {
110+
if item.Source.Id == bookId || len(ids) == listRows-1 {
109111
continue
110112
}
111113
ids = append(ids, item.Source.Id)

0 commit comments

Comments
 (0)