// 加载更多的搜索link func link_search_loadMore(ctx *goku.HttpContext) goku.ActionResulter { term, _ := url.QueryUnescape(ctx.Get("term")) page, err := strconv.Atoi(ctx.Get("page")) success, hasmore := false, false errorMsgs, html := "", "" if err == nil && page > 1 { ls := utils.LinkSearch{} searchResult, err := ls.SearchLink(term, page, golink.PAGE_SIZE) if err == nil && searchResult.TimedOut == false && searchResult.HitResult.HitArray != nil { if len(searchResult.HitResult.HitArray) > 0 { links, _ := models.Link_GetByIdList(searchResult.HitResult.HitArray) if links != nil && len(links) > 0 { ctx.ViewData["Links"] = models.Link_ToVLink(links, ctx) vr := ctx.RenderPartial("loadmorelink", nil) vr.Render(ctx, vr.Body) html = vr.Body.String() hasmore = len(links) >= golink.PAGE_SIZE } } success = true } } else { errorMsgs = "参数错误" } r := map[string]interface{}{ "success": success, "errors": errorMsgs, "html": html, "hasmore": hasmore, } return ctx.Json(r) }
//添加link到es搜索; contextType:0: url, 1:文本 func addLinkForSearch(contextType int, m map[string]interface{}, linkId int64, userName string) { m["id"] = linkId m["username"] = userName if contextType == 0 { m["host"] = utils.GetUrlHost(m["context"].(string)) m["context"] = "" } else { m["host"] = "" } ls := utils.LinkSearch{} ls.AddLink(m) }
//link搜索界面 func link_search(ctx *goku.HttpContext) goku.ActionResulter { ls := utils.LinkSearch{} searchResult, err := ls.SearchLink(ctx.Get("term"), 1, golink.PAGE_SIZE) if err == nil && searchResult.TimedOut == false && searchResult.HitResult.HitArray != nil && len(searchResult.HitResult.HitArray) > 0 { links, _ := models.Link_GetByIdList(searchResult.HitResult.HitArray) ctx.ViewData["Links"] = models.Link_ToVLink(links, ctx) ctx.ViewData["HasMoreLink"] = len(links) >= golink.PAGE_SIZE } else { ctx.ViewData["Links"] = nil ctx.ViewData["HasMoreLink"] = false } ctx.ViewData["Term"] = ctx.Get("term") return ctx.Render("/link/search", nil) }
//添加link到es搜索; contextType:0: url, 1:文本 func addLinkForSearch(contextType int, linkId int64, title string, context string, topics string, userName string) { m := make(map[string]interface{}) m["id"] = linkId m["title"] = title m["context"] = context m["topics"] = topics m["username"] = userName if contextType == 0 { m["host"] = utils.GetUrlHost(m["context"].(string)) m["context"] = "" } else { m["host"] = "" } ls := utils.LinkSearch{} _, err := ls.AddLink(m) if err != nil { fmt.Println("失败: ", m) } else { fmt.Println("成功: ", m) } }