Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 345ad1a

Browse files
committed
search stat bugfix
1 parent c55e094 commit 345ad1a

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

websites/code/studygolang/src/model/search_stat.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ func (this *SearchStat) Where(condition string, args ...interface{}) *SearchStat
7171
return this
7272
}
7373

74+
// 为了支持连写
75+
func (this *SearchStat) Increment(field string, num int) *SearchStat {
76+
this.Dao.Increment(field, num)
77+
return this
78+
}
79+
7480
// 为了支持连写
7581
func (this *SearchStat) Set(clause string, args ...interface{}) *SearchStat {
7682
this.Dao.Set(clause, args...)

websites/code/studygolang/src/service/searcher.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,17 @@ func DoSearch(q, field string, start, rows int) (*model.ResponseBody, error) {
145145
values.Add("q", "*:*")
146146
} else {
147147
searchStat := model.NewSearchStat()
148-
searchStat.Keyword = q
149-
searchStat.Insert()
148+
searchStat.Find()
149+
if searchStat.Id > 0 {
150+
searchStat.Increment("times", 1)
151+
} else {
152+
searchStat.Keyword = q
153+
searchStat.Times = 1
154+
_, err := searchStat.Insert()
155+
if err != nil {
156+
searchStat.Increment("times", 1)
157+
}
158+
}
150159
}
151160

152161
if field == "text" {

0 commit comments

Comments
 (0)