MCPcopy Index your code
hub / github.com/TruthHun/DocHub / Get

Method Get

controllers/HomeControllers/SearchController.go:18–152  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

16}
17
18func (this *SearchController) Get() {
19
20 var (
21 p int = 1 //默认页码
22 listRows int = models.NewSys().GetByField("ListRows").ListRows //默认每页显示记录数
23 res models.Result
24 start = time.Now().UnixNano()
25 )
26
27 if listRows <= 0 {
28 listRows = 10
29 }
30
31 //path中的参数
32 params := conv.Path2Map(this.GetString(":splat"))
33 if _, ok := params["wd"]; !ok { //搜索关键字
34 params["wd"] = this.GetString("wd")
35 }
36
37 //缺少搜索关键字,直接返回首页
38 if len(params["wd"]) == 0 {
39 this.Redirect("/", 302)
40 return
41 }
42
43 if _, ok := params["type"]; !ok { //搜索类型
44 params["type"] = this.GetString("type")
45 }
46 params["type"] = helper.Default(params["type"], "all") //默认全部搜索
47 if _, ok := params["sort"]; !ok { //排序
48 params["sort"] = this.GetString("sort")
49 }
50 params["sort"] = helper.Default(params["sort"], "default") //默认排序
51
52 if _, ok := params["p"]; ok {
53 p = helper.Interface2Int(params["p"])
54 } else {
55 p, _ = this.GetInt("p")
56 }
57
58 //页码处理
59 p = helper.NumberRange(p, 1, 100)
60 //res := models.Search(params["wd"], params["type"], params["sort"], p, listRows, 1)
61 client := models.NewElasticSearchClient()
62 if client.On {
63 if result, err := client.Search(params["wd"], params["type"], params["sort"], p, listRows); err != nil {
64 helper.Logger.Error(err.Error())
65 } else {
66 res.TotalFound = int64(result.Hits.Total)
67 res.Status = 1
68 res.Word = []string{}
69 res.Msg = "搜索成功"
70 res.Time = float64(result.Took) / 1000 //耗时
71 var data []orm.Params
72 modelDoc := models.NewDocument()
73 for _, item := range result.Hits.Hits {
74 desc := ""
75 if len(item.Highlight.Description) > 0 {

Callers

nothing calls this directly

Calls 5

SearchMethod · 0.95
GetOneDocStoreByDsIdMethod · 0.95
GetByFieldMethod · 0.80
GetByPageMethod · 0.80
ListMethod · 0.45

Tested by

no test coverage detected