package controllers
import (
"github.com/lifei6671/godoc/models"
"github.com/lifei6671/godoc/conf"
"github.com/lifei6671/godoc/utils"
"github.com/astaxie/beego"
"strings"
"regexp"
"strconv"
)
type SearchController struct {
BaseController
}
func (c *SearchController) Index() {
c.Prepare()
c.TplName = "search/index.tpl"
keyword := c.GetString("keyword")
pageIndex,_ := c.GetInt("page",1)
c.Data["BaseUrl"] = c.BaseUrl()
if keyword != "" {
c.Data["Keyword"] = keyword
member_id := 0
if c.Member != nil {
member_id = c.Member.MemberId
}
search_result,totalCount,err := models.NewDocumentSearchResult().FindToPager(keyword,pageIndex,conf.PageSize,member_id)
if err != nil {
beego.Error(err)
return
}
if totalCount > 0 {
html := utils.GetPagerHtml(c.Ctx.Request.RequestURI, pageIndex, conf.PageSize, totalCount)
c.Data["PageHtml"] = html
}else {
c.Data["PageHtml"] = ""
}
if len(search_result) > 0 {
for _,item := range search_result {
item.DocumentName = strings.Replace(item.DocumentName,keyword,"" + keyword + "",-1)
if item.Description != "" {
src := item.Description
//将HTML标签全转换成小写
re, _ := regexp.Compile("\\<[\\S\\s]+?\\>")
src = re.ReplaceAllStringFunc(src, strings.ToLower)
//去除STYLE
re, _ = regexp.Compile("\\