@@ -3,6 +3,8 @@ package HomeControllers
33import (
44 "strings"
55
6+ "time"
7+
68 "github.com/TruthHun/DocHub/helper"
79 "github.com/TruthHun/DocHub/helper/conv"
810 "github.com/TruthHun/DocHub/models"
@@ -17,6 +19,8 @@ func (this *SearchController) Get() {
1719 var (
1820 p int = 1 //默认页码
1921 listRows int = 10 //默认每页显示记录数
22+ res models.Result
23+ start = time .Now ().UnixNano ()
2024 )
2125 //path中的参数
2226 params := conv .Path2Map (this .GetString (":splat" ))
@@ -47,32 +51,31 @@ func (this *SearchController) Get() {
4751
4852 //页码处理
4953 p = helper .NumberRange (p , 1 , 100 )
50- res := models .Search (params ["wd" ], params ["type" ], params ["sort" ], p , listRows , 1 )
51- if res .Total > 0 && len (res .Ids ) > 0 {
52- data := models .ModelDoc .GetDocsByIds (res .Ids )
53- if len (data ) > 0 {
54- for index , val := range data {
55- if len (strings .TrimSpace (val ["Description" ].(string ))) == 0 {
56- if desc := models .ModelDocText .GetDescByMd5 (val ["Md5" ], 120 ); len (desc ) == 0 {
57- data [index ]["Description" ] = val ["Title" ]
58- } else {
59- data [index ]["Description" ] = desc + "..."
60- }
61- }
62- }
63- }
64- this .Data ["Data" ] = data
54+ //res := models.Search(params["wd"], params["type"], params["sort"], p, listRows, 1)
55+ this .Data ["Data" ], res .TotalFound = models .SearchByMysql (params ["wd" ], params ["type" ], params ["sort" ], p , listRows )
56+ res .Word = []string {params ["wd" ]}
57+ if res .TotalFound > 1000 {
58+ res .Total = 1000
59+ } else {
60+ res .Total = res .TotalFound
6561 }
66-
6762 if p == 1 {
6863 wdSlice := strings .Split (this .Sys .DirtyWord , " " )
64+ insert := true
6965 for _ , wd := range wdSlice {
70- if ! strings .Contains (params ["wd" ], wd ) {
71- models .ReplaceInto (models .TableSearchLog , map [string ]interface {}{"Wd" : params ["wd" ]})
66+ //如果含有非法关键字,则不录入搜索词库
67+ if wd != "" && strings .Contains (params ["wd" ], wd ) {
68+ insert = false
7269 break
7370 }
7471 }
72+ if insert {
73+ models .ReplaceInto (models .TableSearchLog , map [string ]interface {}{"Wd" : params ["wd" ]})
74+ }
7575 }
76+ end := time .Now ().UnixNano ()
77+ res .Time = float64 (end - start ) / 1000000000
78+
7679 this .Data ["Seo" ] = models .ModelSeo .GetByPage ("PC-Search" , params ["wd" ], "文档搜索," + params ["wd" ], "文档搜索," + params ["wd" ], this .Sys .Site )
7780 this .Data ["Page" ] = helper .Paginations (6 , int (res .Total ), listRows , p , "/search/" , "type" , params ["type" ], "sort" , params ["sort" ], "p" , p , "wd" , params ["wd" ])
7881 this .Data ["Params" ] = params
0 commit comments