feat:支持搜索中使用空格

pull/425/head v2.0-beta.2
lifei6671 2018-11-29 15:11:34 +08:00
parent 8681d8fa3e
commit f3b03249b4
2 changed files with 16 additions and 12 deletions

View File

@ -48,22 +48,24 @@ func (c *SearchController) Index() {
c.Data["PageHtml"] = ""
}
if len(searchResult) > 0 {
keywords := strings.Split(keyword," ")
for _, item := range searchResult {
item.DocumentName = strings.Replace(item.DocumentName, keyword, "<em>"+keyword+"</em>", -1)
for _,word := range keywords {
item.DocumentName = strings.Replace(item.DocumentName, word, "<em>"+word+"</em>", -1)
if item.Description != "" {
src := item.Description
if item.Description != "" {
src := item.Description
r := []rune(utils.StripTags(item.Description))
r := []rune(utils.StripTags(item.Description))
if len(r) > 100 {
src = string(r[:100])
} else {
src = string(r)
if len(r) > 100 {
src = string(r[:100])
} else {
src = string(r)
}
item.Description = strings.Replace(src, word, "<em>"+word+"</em>", -1)
}
item.Description = strings.Replace(src, keyword, "<em>"+keyword+"</em>", -1)
}
if item.Identify == "" {
item.Identify = strconv.Itoa(item.DocumentId)
}

View File

@ -5,6 +5,7 @@ import (
"github.com/astaxie/beego/orm"
"github.com/astaxie/beego"
"strings"
)
type DocumentSearchResult struct {
@ -31,7 +32,8 @@ func (m *DocumentSearchResult) FindToPager(keyword string, pageIndex, pageSize,
o := orm.NewOrm()
offset := (pageIndex - 1) * pageSize
keyword = "%" + keyword + "%"
keyword = "%" + strings.Replace(keyword," ","%",-1) + "%"
if memberId <= 0 {
sql1 := `SELECT count(doc.document_id) as total_count FROM md_documents AS doc