diff --git a/public/home/search.js b/public/home/search.js index 07e8df762..d57ff20bc 100644 --- a/public/home/search.js +++ b/public/home/search.js @@ -1,5 +1,177 @@ +var html =document.documentElement; +var lang = html.attributes["lang"] +var isZh = true; +if(lang != null && lang.nodeValue =="en-US" ){ + console.log("the language is " + lang.nodeValue); + isZh=false; +}else{ + console.log("default lang=zh"); +} +function isEmpty(str){ + if(typeof str == "undefined" || str == null || str == ""){ + return true; + } + return false; +} + + + function search(){ var keyword = document.getElementById("keyword_input").value; + var page =1; + var pageSize=15; + if(!isEmpty(keyword)){ + doSearch("repository",keyword,page,pageSize,false); + doSearch("issue",keyword,page,pageSize,true); + doSearch("user",keyword,page,pageSize,true); + doSearch("org",keyword,page,pageSize,true); + doSearch("dataset",keyword,page,pageSize,true); + doSearch("pr",keyword,page,pageSize,true); + } +} + +function doSearch(tableName,keyword,page,pageSize=15,onlyReturnNum=true){ + $.ajax({ + type:"GET", + url:"/all/dosearch/", + headers: { + authorization:token, + }, + dataType:"json", + dataType:"json", + data:{ + 'TableName': tableName, + 'Key': keyword, + 'Page': page, + 'PageSize': pageSize, + 'OnlyReturnNum':onlyReturnNum + }, + async:true, + success:function(json){ + console.log(json); + displayResult(tableName,page,json,onlyReturnNum,keyword); + }, + error:function(response) { + console.log(response); + } + }); +} + +function displayResult(tableName,page,jsonResult,onlyReturnNum,keyword){ + if(tableName == "repository") { + displayRepoResult(page,jsonResult,onlyReturnNum,keyword); + } else if (tableName == "issue") { + + } else if (tableName == "user") { + + } else if (tableName == "org") { + + } else if (tableName == "dataset") { + + } else if (tableName == "pr") { + + } +} + +function displayRepoResult(page,jsonResult,onlyReturnNum,keyword){ + var data = jsonResult.Result; + var total = jsonResult.Total; + $('#repo_total').text(total); + $('#keyword_desc').text(keyword); + $('#obj_desc').text("项目"); + $('#child_total').text(total); + + if(!onlyReturnNum){ + var html = ""; + var currentTime = new Date().getTime(); + for(var i = 0; i < data.length;i++){ + var recordMap = data[i]; + html += "
"; + if(!isEmpty(recordMap['avatar'])){ + html += ""; + } + html += "
"; + html += "
"; + html += " " + record["owner_name"] +" / " + record["name"] + ""; + html +=" "; + html +="
"; + html += "
"; + html += "

" + record["description"] + "

"; + html += "
"; + if(!isEmpty(record["topics"])){ + for(var j = 0; j < record["topics"].length;j++){ + html +="
"+ record["topics"][j] + "
"; + } + } + html +="
"; + html +="

"; + html +=" " + record["NumStars"] + "" + record["NumForks"]; + html +=" 最后更新于 " + getTime(record["updated_unix"],currentTime) +""; + html +=" " + record["lang"] + ""; + html +="

"; + html +="
"; + html +="
"; + html +="
"; + } + } +} + +function getTime(UpdatedUnix,currentTime){ + UpdatedUnix = UpdatedUnix; + currentTime = currentTime / 1000; + var timeEscSecond = currentTime - UpdatedUnix; + if( timeEscSecond < 0){ + timeEscSecond = 1; + } + console.log("currentTime=" + currentTime + " updateUnix=" + UpdatedUnix); + + var hours= Math.floor(timeEscSecond / 3600); + //计算相差分钟数 + var leave2 = Math.floor(timeEscSecond % (3600)); //计算小时数后剩余的秒数 + var minutes= Math.floor(leave2 / 60);//计算相差分钟数 + + var leave3=Math.floor(leave2 % 60); //计算分钟数后剩余的秒数 + var seconds= leave3; + + if(hours == 0 && minutes == 0){ + return seconds + getRepoOrOrg(6,isZh); + }else{ + if(hours > 0){ + if(hours >= 24){ + return Math.ceil(hours/24) + getRepoOrOrg(7,isZh); + }else{ + return hours + getRepoOrOrg(4,isZh); + } + }else{ + return minutes + getRepoOrOrg(5,isZh); + } + } +} + +function getRepoOrOrg(key,isZhLang){ + if(isZhLang){ + return repoAndOrgZH[key]; + }else{ + return repoAndOrgEN[key]; + } +} +var repoAndOrgZH={ + "1":"项目", + "2":"成员", + "3":"团队", + "4":"小时前", + "5":"分钟前", + "6":"秒前", + "7":"天前" +}; -} \ No newline at end of file +var repoAndOrgEN={ + "1":"repository", + "2":"Members ", + "3":"Teams", + "4":" hours ago", + "5":" minutes ago", + "6":" seconds ago", + "7":" days ago" +}; \ No newline at end of file diff --git a/routers/routes/routes.go b/routers/routes/routes.go index 83ba4dd5c..49dee0b79 100755 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -320,6 +320,7 @@ func RegisterRoutes(m *macaron.Macaron) { m.Get("/recommend/org", routers.RecommendOrgFromPromote) m.Get("/recommend/repo", routers.RecommendRepoFromPromote) m.Get("/all/search/", routers.Search) + m.Get("/all/dosearch/", routers.SearchApi) m.Group("/explore", func() { m.Get("", func(ctx *context.Context) { ctx.Redirect(setting.AppSubURL + "/explore/repos") diff --git a/routers/search.go b/routers/search.go index 5a04c682f..1fbca2d5d 100644 --- a/routers/search.go +++ b/routers/search.go @@ -43,6 +43,7 @@ func SearchApi(ctx *context.Context) { Key := ctx.Query("Key") Page := ctx.QueryInt("Page") PageSize := ctx.QueryInt("PageSize") + OnlyReturnNum := ctx.QueryBool("OnlyReturnNum") if Page <= 0 { Page = 1 } @@ -51,27 +52,27 @@ func SearchApi(ctx *context.Context) { } if TableName == "repository" { - searchRepo(ctx, "repository-es-index", Key, Page, PageSize) + searchRepo(ctx, "repository-es-index", Key, Page, PageSize, OnlyReturnNum) return } else if TableName == "issue" { - searchIssue(ctx, "issue-es-index", Key, Page, PageSize) + searchIssue(ctx, "issue-es-index", Key, Page, PageSize, OnlyReturnNum) return } else if TableName == "user" { - searchUserOrOrg(ctx, "user-es-index", Key, Page, PageSize, true) + searchUserOrOrg(ctx, "user-es-index", Key, Page, PageSize, true, OnlyReturnNum) return } else if TableName == "org" { - searchUserOrOrg(ctx, "user-es-index", Key, Page, PageSize, false) + searchUserOrOrg(ctx, "user-es-index", Key, Page, PageSize, false, OnlyReturnNum) return } else if TableName == "dataset" { - searchDataSet(ctx, "dataset-es-index", Key, Page, PageSize) + searchDataSet(ctx, "dataset-es-index", Key, Page, PageSize, OnlyReturnNum) return } else if TableName == "pr" { - searchPR(ctx, "issue-es-index", Key, Page, PageSize) + searchPR(ctx, "issue-es-index", Key, Page, PageSize, OnlyReturnNum) return } } -func searchRepoByLabel(ctx *context.Context, TableName string, Key string, Page int, PageSize int) { +func searchRepoByLabel(ctx *context.Context, TableName string, Key string, Page int, PageSize int, OnlyReturnNum bool) { /* 项目, ES名称: repository-es-index 搜索: @@ -96,7 +97,7 @@ func searchRepoByLabel(ctx *context.Context, TableName string, Key string, Page boolQ.Should(topicsQuery) res, err := client.Search(TableName).Query(boolQ).Sort(SortBy, ascending).From((Page - 1) * PageSize).Size(PageSize).Do(ctx.Req.Context()) if err == nil { - result := makeRepoResult(res, "") + result := makeRepoResult(res, "", OnlyReturnNum) ctx.JSON(200, result) return } else { @@ -106,7 +107,7 @@ func searchRepoByLabel(ctx *context.Context, TableName string, Key string, Page ctx.JSON(200, "") } -func searchRepo(ctx *context.Context, TableName string, Key string, Page int, PageSize int) { +func searchRepo(ctx *context.Context, TableName string, Key string, Page int, PageSize int, OnlyReturnNum bool) { /* 项目, ES名称: repository-es-index 搜索: @@ -136,7 +137,7 @@ func searchRepo(ctx *context.Context, TableName string, Key string, Page int, Pa if err == nil { searchJson, _ := json.Marshal(res) log.Info("searchJson=" + string(searchJson)) - result := makeRepoResult(res, Key) + result := makeRepoResult(res, Key, OnlyReturnNum) ctx.JSON(200, result) } else { log.Info("query es error," + err.Error()) @@ -149,7 +150,7 @@ func searchRepo(ctx *context.Context, TableName string, Key string, Page int, Pa if err == nil { searchJson, _ := json.Marshal(res) log.Info("searchJson=" + string(searchJson)) - result := makeRepoResult(res, "") + result := makeRepoResult(res, "", OnlyReturnNum) ctx.JSON(200, result) } else { log.Info("query es error," + err.Error()) @@ -158,47 +159,47 @@ func searchRepo(ctx *context.Context, TableName string, Key string, Page int, Pa } } -func makeRepoResult(sRes *elastic.SearchResult, Key string) *SearchRes { +func makeRepoResult(sRes *elastic.SearchResult, Key string, OnlyReturnNum bool) *SearchRes { total := sRes.Hits.TotalHits.Value result := make([]map[string]interface{}, 0) + if !OnlyReturnNum { + for i, hit := range sRes.Hits.Hits { + log.Info("this is repo query " + fmt.Sprint(i) + " result.") + recordSource := make(map[string]interface{}) + source, err := hit.Source.MarshalJSON() - for i, hit := range sRes.Hits.Hits { - log.Info("this is repo query " + fmt.Sprint(i) + " result.") - recordSource := make(map[string]interface{}) - source, err := hit.Source.MarshalJSON() - - if err == nil { - err = json.Unmarshal(source, &recordSource) if err == nil { - record := make(map[string]interface{}) - record["id"] = hit.Id - record["name"] = getLabelValue("name", recordSource, hit.Highlight) - record["owner_name"] = recordSource["owner_name"] - if recordSource["description"] != nil { - desc := getLabelValue("description", recordSource, hit.Highlight) - record["description"] = dealLongText(desc, Key, hit.MatchedQueries) - } else { - record["description"] = "" - } + err = json.Unmarshal(source, &recordSource) + if err == nil { + record := make(map[string]interface{}) + record["id"] = hit.Id + record["name"] = getLabelValue("name", recordSource, hit.Highlight) + record["owner_name"] = recordSource["owner_name"] + if recordSource["description"] != nil { + desc := getLabelValue("description", recordSource, hit.Highlight) + record["description"] = dealLongText(desc, Key, hit.MatchedQueries) + } else { + record["description"] = "" + } - record["num_watches"] = recordSource["num_watches"] - record["num_stars"] = recordSource["num_stars"] - record["num_forks"] = recordSource["num_forks"] - record["topics"] = recordSource["topics"] - if recordSource["avatar"] != nil { - record["avatar"] = setting.AppSubURL + "/repo-avatars/" + recordSource["avatar"].(string) + record["num_watches"] = recordSource["num_watches"] + record["num_stars"] = recordSource["num_stars"] + record["num_forks"] = recordSource["num_forks"] + record["topics"] = recordSource["topics"] + if recordSource["avatar"] != nil { + record["avatar"] = setting.AppSubURL + "/repo-avatars/" + recordSource["avatar"].(string) + } + record["updated_unix"] = recordSource["updated_unix"] + record["lang"] = recordSource["lang"] + result = append(result, record) + } else { + log.Info("deal repo source error," + err.Error()) } - record["updated_unix"] = recordSource["updated_unix"] - record["lang"] = recordSource["lang"] - result = append(result, record) } else { log.Info("deal repo source error," + err.Error()) } - } else { - log.Info("deal repo source error," + err.Error()) } } - returnObj := &SearchRes{ Total: total, Result: result, @@ -241,7 +242,7 @@ func dealLongText(text string, Key string, MatchedQueries []string) string { } -func searchUserOrOrg(ctx *context.Context, TableName string, Key string, Page int, PageSize int, IsQueryUser bool) { +func searchUserOrOrg(ctx *context.Context, TableName string, Key string, Page int, PageSize int, IsQueryUser bool, OnlyReturnNum bool) { /* 用户或者组织 ES名称: user-es-index 搜索: @@ -280,7 +281,7 @@ func searchUserOrOrg(ctx *context.Context, TableName string, Key string, Page in if err == nil { searchJson, _ := json.Marshal(res) log.Info("searchJson=" + string(searchJson)) - result := makeUserOrOrgResult(res, Key, ctx) + result := makeUserOrOrgResult(res, Key, ctx, OnlyReturnNum) ctx.JSON(200, result) } else { log.Info("query es error," + err.Error()) @@ -300,61 +301,60 @@ func getLabelValue(key string, recordSource map[string]interface{}, searchHighli } } -func makeUserOrOrgResult(sRes *elastic.SearchResult, Key string, ctx *context.Context) *SearchRes { +func makeUserOrOrgResult(sRes *elastic.SearchResult, Key string, ctx *context.Context, OnlyReturnNum bool) *SearchRes { total := sRes.Hits.TotalHits.Value result := make([]map[string]interface{}, 0) + if !OnlyReturnNum { + for i, hit := range sRes.Hits.Hits { + log.Info("this is user query " + fmt.Sprint(i) + " result.") + recordSource := make(map[string]interface{}) + source, err := hit.Source.MarshalJSON() - for i, hit := range sRes.Hits.Hits { - log.Info("this is user query " + fmt.Sprint(i) + " result.") - recordSource := make(map[string]interface{}) - source, err := hit.Source.MarshalJSON() - - if err == nil { - err = json.Unmarshal(source, &recordSource) if err == nil { - record := make(map[string]interface{}) - record["id"] = hit.Id - record["name"] = getLabelValue("name", recordSource, hit.Highlight) - record["full_name"] = getLabelValue("full_name", recordSource, hit.Highlight) - if recordSource["description"] != nil { - desc := getLabelValue("description", recordSource, hit.Highlight) - record["description"] = dealLongText(desc, Key, hit.MatchedQueries) - } else { - record["description"] = "" - } - if ctx.User != nil { - record["email"] = recordSource["email"] - } else { - record["email"] = "" - } + err = json.Unmarshal(source, &recordSource) + if err == nil { + record := make(map[string]interface{}) + record["id"] = hit.Id + record["name"] = getLabelValue("name", recordSource, hit.Highlight) + record["full_name"] = getLabelValue("full_name", recordSource, hit.Highlight) + if recordSource["description"] != nil { + desc := getLabelValue("description", recordSource, hit.Highlight) + record["description"] = dealLongText(desc, Key, hit.MatchedQueries) + } else { + record["description"] = "" + } + if ctx.User != nil { + record["email"] = recordSource["email"] + } else { + record["email"] = "" + } - record["location"] = recordSource["location"] - record["website"] = recordSource["website"] - record["num_repos"] = recordSource["num_repos"] - record["num_teams"] = recordSource["num_teams"] - record["num_members"] = recordSource["num_members"] + record["location"] = recordSource["location"] + record["website"] = recordSource["website"] + record["num_repos"] = recordSource["num_repos"] + record["num_teams"] = recordSource["num_teams"] + record["num_members"] = recordSource["num_members"] - record["avatar"] = strings.TrimRight(setting.AppSubURL, "/") + "/user/avatar/" + recordSource["name"].(string) + "/" + strconv.Itoa(-1) - record["updated_unix"] = recordSource["updated_unix"] - record["created_unix"] = recordSource["created_unix"] - result = append(result, record) + record["avatar"] = strings.TrimRight(setting.AppSubURL, "/") + "/user/avatar/" + recordSource["name"].(string) + "/" + strconv.Itoa(-1) + record["updated_unix"] = recordSource["updated_unix"] + record["created_unix"] = recordSource["created_unix"] + result = append(result, record) + } else { + log.Info("deal user source error," + err.Error()) + } } else { log.Info("deal user source error," + err.Error()) } - } else { - log.Info("deal user source error," + err.Error()) } } - returnObj := &SearchRes{ Total: total, Result: result, } - return returnObj } -func searchDataSet(ctx *context.Context, TableName string, Key string, Page int, PageSize int) { +func searchDataSet(ctx *context.Context, TableName string, Key string, Page int, PageSize int, OnlyReturnNum bool) { /* 数据集,ES名称:dataset-es-index 搜索: @@ -381,7 +381,7 @@ func searchDataSet(ctx *context.Context, TableName string, Key string, Page int, boolQ.Should(nameQuery, descQuery, categoryQuery, fileNameQuery) res, err := client.Search(TableName).Query(boolQ).Sort(SortBy, ascending).From((Page - 1) * PageSize).Size(PageSize).Highlight(queryHighlight("title", "description", "file_name", "category")).Do(ctx.Req.Context()) if err == nil { - result := makeDatasetResult(res, Key) + result := makeDatasetResult(res, Key, OnlyReturnNum) ctx.JSON(200, result) } else { log.Info("query es error," + err.Error()) @@ -391,7 +391,7 @@ func searchDataSet(ctx *context.Context, TableName string, Key string, Page int, //搜索的属性要指定{"timestamp":{"unmapped_type":"date"}} res, err := client.Search(TableName).Sort(SortBy, ascending).From((Page - 1) * PageSize).Size(PageSize).Do(ctx.Req.Context()) if err == nil { - result := makeRepoResult(res, "") + result := makeDatasetResult(res, "", OnlyReturnNum) ctx.JSON(200, result) } else { log.Info("query es error," + err.Error()) @@ -401,49 +401,49 @@ func searchDataSet(ctx *context.Context, TableName string, Key string, Page int, } -func makeDatasetResult(sRes *elastic.SearchResult, Key string) *SearchRes { +func makeDatasetResult(sRes *elastic.SearchResult, Key string, OnlyReturnNum bool) *SearchRes { total := sRes.Hits.TotalHits.Value result := make([]map[string]interface{}, 0) + if !OnlyReturnNum { + for i, hit := range sRes.Hits.Hits { + log.Info("this is dataset query " + fmt.Sprint(i) + " result.") + recordSource := make(map[string]interface{}) + source, err := hit.Source.MarshalJSON() - for i, hit := range sRes.Hits.Hits { - log.Info("this is dataset query " + fmt.Sprint(i) + " result.") - recordSource := make(map[string]interface{}) - source, err := hit.Source.MarshalJSON() - - if err == nil { - err = json.Unmarshal(source, &recordSource) if err == nil { - record := make(map[string]interface{}) - record["id"] = hit.Id - userIdStr := recordSource["user_id"].(string) - userId, cerr := strconv.ParseInt(userIdStr, 10, 64) - if cerr == nil { - user, errUser := models.GetUserByID(userId) - if errUser == nil { - record["owerName"] = user.GetDisplayName() - record["avatar"] = user.RelAvatarLink() + err = json.Unmarshal(source, &recordSource) + if err == nil { + record := make(map[string]interface{}) + record["id"] = hit.Id + userIdStr := recordSource["user_id"].(string) + userId, cerr := strconv.ParseInt(userIdStr, 10, 64) + if cerr == nil { + user, errUser := models.GetUserByID(userId) + if errUser == nil { + record["owerName"] = user.GetDisplayName() + record["avatar"] = user.RelAvatarLink() + } } - } - record["title"] = getLabelValue("title", recordSource, hit.Highlight) - record["category"] = getLabelValue("category", recordSource, hit.Highlight) - if recordSource["description"] != nil { - desc := getLabelValue("description", recordSource, hit.Highlight) - record["description"] = dealLongText(desc, Key, hit.MatchedQueries) + record["title"] = getLabelValue("title", recordSource, hit.Highlight) + record["category"] = getLabelValue("category", recordSource, hit.Highlight) + if recordSource["description"] != nil { + desc := getLabelValue("description", recordSource, hit.Highlight) + record["description"] = dealLongText(desc, Key, hit.MatchedQueries) + } else { + record["description"] = "" + } + record["file_name"] = recordSource["file_name"] + record["download_times"] = recordSource["download_times"] + record["created_unix"] = recordSource["created_unix"] + result = append(result, record) } else { - record["description"] = "" + log.Info("deal dataset source error," + err.Error()) } - record["file_name"] = recordSource["file_name"] - record["download_times"] = recordSource["download_times"] - record["created_unix"] = recordSource["created_unix"] - result = append(result, record) } else { log.Info("deal dataset source error," + err.Error()) } - } else { - log.Info("deal dataset source error," + err.Error()) } } - returnObj := &SearchRes{ Total: total, Result: result, @@ -452,7 +452,7 @@ func makeDatasetResult(sRes *elastic.SearchResult, Key string) *SearchRes { return returnObj } -func searchIssue(ctx *context.Context, TableName string, Key string, Page int, PageSize int) { +func searchIssue(ctx *context.Context, TableName string, Key string, Page int, PageSize int, OnlyReturnNum bool) { /* 任务,合并请求 ES名称:issue-es-index @@ -487,7 +487,7 @@ func searchIssue(ctx *context.Context, TableName string, Key string, Page int, P if err == nil { searchJson, _ := json.Marshal(res) log.Info("searchJson=" + string(searchJson)) - result := makeIssueResult(res, Key) + result := makeIssueResult(res, Key, OnlyReturnNum) ctx.JSON(200, result) } else { log.Info("query es error," + err.Error()) @@ -507,58 +507,58 @@ func queryHighlight(names ...string) *elastic.Highlight { return re } -func makeIssueResult(sRes *elastic.SearchResult, Key string) *SearchRes { +func makeIssueResult(sRes *elastic.SearchResult, Key string, OnlyReturnNum bool) *SearchRes { total := sRes.Hits.TotalHits.Value result := make([]map[string]interface{}, 0) + if !OnlyReturnNum { + for i, hit := range sRes.Hits.Hits { + log.Info("this is issue query " + fmt.Sprint(i) + " result.") + recordSource := make(map[string]interface{}) + source, err := hit.Source.MarshalJSON() - for i, hit := range sRes.Hits.Hits { - log.Info("this is issue query " + fmt.Sprint(i) + " result.") - recordSource := make(map[string]interface{}) - source, err := hit.Source.MarshalJSON() - - if err == nil { - err = json.Unmarshal(source, &recordSource) if err == nil { - record := make(map[string]interface{}) - record["id"] = hit.Id - record["repo_id"] = recordSource["repo_id"] - log.Info("recordSource[\"repo_id\"]=" + fmt.Sprint(recordSource["repo_id"])) - repoIdstr := recordSource["repo_id"].(string) - repoId, cerr := strconv.ParseInt(repoIdstr, 10, 64) - if cerr == nil { - repo, errRepo := models.GetRepositoryByID(repoId) - if errRepo == nil { - record["repoUrl"] = repo.FullName() - record["avatar"] = repo.RelAvatarLink() + err = json.Unmarshal(source, &recordSource) + if err == nil { + record := make(map[string]interface{}) + record["id"] = hit.Id + record["repo_id"] = recordSource["repo_id"] + log.Info("recordSource[\"repo_id\"]=" + fmt.Sprint(recordSource["repo_id"])) + repoIdstr := recordSource["repo_id"].(string) + repoId, cerr := strconv.ParseInt(repoIdstr, 10, 64) + if cerr == nil { + repo, errRepo := models.GetRepositoryByID(repoId) + if errRepo == nil { + record["repoUrl"] = repo.FullName() + record["avatar"] = repo.RelAvatarLink() + } } - } - record["name"] = getLabelValue("name", recordSource, hit.Highlight) - if recordSource["content"] != nil { - desc := getLabelValue("content", recordSource, hit.Highlight) - record["content"] = dealLongText(desc, Key, hit.MatchedQueries) - } else { - record["content"] = "" - } - if recordSource["pr_id"] != nil { - record["pr_id"] = recordSource["pr_id"] - } - if recordSource["comment"] != nil { - desc := getLabelValue("comment", recordSource, hit.Highlight) - record["comment"] = dealLongText(desc, Key, hit.MatchedQueries) + record["name"] = getLabelValue("name", recordSource, hit.Highlight) + if recordSource["content"] != nil { + desc := getLabelValue("content", recordSource, hit.Highlight) + record["content"] = dealLongText(desc, Key, hit.MatchedQueries) + } else { + record["content"] = "" + } + if recordSource["pr_id"] != nil { + record["pr_id"] = recordSource["pr_id"] + } + if recordSource["comment"] != nil { + desc := getLabelValue("comment", recordSource, hit.Highlight) + record["comment"] = dealLongText(desc, Key, hit.MatchedQueries) + } else { + record["comment"] = "" + } + record["num_comments"] = recordSource["num_comments"] + record["updated_unix"] = recordSource["updated_unix"] + result = append(result, record) } else { - record["comment"] = "" + log.Info("deal issue source error," + err.Error()) } - record["num_comments"] = recordSource["num_comments"] - record["updated_unix"] = recordSource["updated_unix"] - result = append(result, record) } else { log.Info("deal issue source error," + err.Error()) } - } else { - log.Info("deal issue source error," + err.Error()) } } - returnObj := &SearchRes{ Total: total, Result: result, @@ -567,7 +567,7 @@ func makeIssueResult(sRes *elastic.SearchResult, Key string) *SearchRes { return returnObj } -func searchPR(ctx *context.Context, TableName string, Key string, Page int, PageSize int) { +func searchPR(ctx *context.Context, TableName string, Key string, Page int, PageSize int, OnlyReturnNum bool) { /* 任务,合并请求 ES名称:issue-es-index @@ -599,7 +599,7 @@ func searchPR(ctx *context.Context, TableName string, Key string, Page int, Page } res, err := client.Search(TableName).Query(boolQ).Sort(SortBy, ascending).From((Page - 1) * PageSize).Size(PageSize).Highlight(queryHighlight("name", "content", "comment")).Do(ctx.Req.Context()) if err == nil { - result := makeIssueResult(res, Key) + result := makeIssueResult(res, Key, OnlyReturnNum) ctx.JSON(200, result) } else { log.Info("query es error," + err.Error()) diff --git a/templates/explore/search_new.tmpl b/templates/explore/search_new.tmpl index 9237bf703..54191f458 100644 --- a/templates/explore/search_new.tmpl +++ b/templates/explore/search_new.tmpl @@ -67,12 +67,9 @@
-
- -
- - -
+
+ +