Skip to content

Commit

Permalink
相关书籍优化
Browse files Browse the repository at this point in the history
  • Loading branch information
TruthHun88 committed Dec 2, 2019
1 parent 8d8ca7a commit 7e7438c
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions models/releate_book.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (r *RelateBook) Lists(bookId int, limit ...int) (books []Book) {
return
}

length := 6
length := 12
if len(limit) > 0 && limit[0] > 0 {
length = limit[0]
}
Expand Down Expand Up @@ -89,12 +89,14 @@ func (r *RelateBook) Lists(bookId int, limit ...int) (books []Book) {
func listByES(book *Book, length int) (ids []int) {
client := NewElasticSearchClient()
client.IsRelateSearch = true
client.Timeout = 1 * time.Second
client.Timeout = 3 * time.Second
listRows := 13 // 这里要填 13,因为有可能返回的id恰好是本书的id
keyWord := book.Label
if len(keyWord) == 0 {
keyWord = book.BookName
}
res, err := client.Search(keyWord, 1, 12, false)

res, err := client.Search(keyWord, 1, listRows, false)
if err != nil {
beego.Error(err.Error())
return
Expand All @@ -105,7 +107,7 @@ func listByES(book *Book, length int) (ids []int) {
if len(ids) >= length {
break
}
if item.Source.Id == bookId {
if item.Source.Id == bookId || len(ids) == listRows-1 {
continue
}
ids = append(ids, item.Source.Id)
Expand Down

0 comments on commit 7e7438c

Please sign in to comment.