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

Skip to content

Commit 0aa1efb

Browse files
committed
bugfix
1 parent 4032b85 commit 0aa1efb

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,14 @@ func FindArticlesById(idstr string) (curArticle *model.Article, prevNext []*mode
241241
return
242242
}
243243

244+
if len(articles) == 0 {
245+
return
246+
}
247+
244248
prevNext = make([]*model.Article, 2)
245-
prevId, nextId := id, id
249+
prevId, nextId := articles[0], id
246250
for _, article := range articles {
247-
if article.Id < id {
251+
if article.Id < id && article.Id > prevId {
248252
prevId = article.Id
249253
prevNext[0] = article
250254
} else if article.Id > id {

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,12 @@ func DoSearch(q, field string, start, rows int) (*model.ResponseBody, error) {
279279
}
280280
}
281281

282-
if field == "text" {
282+
isTag := false
283+
// TODO: 目前大部分都没有tag,因此,对tag特殊处理
284+
if field == "text" || field == "tag" {
285+
if field == "tag" {
286+
isTag = true
287+
}
283288
field = ""
284289
}
285290

@@ -291,7 +296,11 @@ func DoSearch(q, field string, start, rows int) (*model.ResponseBody, error) {
291296
} else {
292297
// 全文检索
293298
if q != "" {
294-
values.Add("q", "title:"+q+"^2"+" OR content:"+q+"^0.2")
299+
if isTag {
300+
values.Add("q", "title:"+q+"^2"+" OR tags:"+q+"^4 OR content:"+q+"^0.2")
301+
} else {
302+
values.Add("q", "title:"+q+"^2"+" OR content:"+q+"^0.2")
303+
}
295304
}
296305
}
297306

0 commit comments

Comments
 (0)