From 4f929a1c4d94c46920d910aab50475d199221b2a Mon Sep 17 00:00:00 2001 From: zouap Date: Thu, 3 Mar 2022 15:35:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- public/home/search.js | 30 +++++++++++++++++++++++------- routers/search.go | 11 +++-------- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/public/home/search.js b/public/home/search.js index 1953c7204..cf785d81d 100644 --- a/public/home/search.js +++ b/public/home/search.js @@ -188,7 +188,7 @@ function displayPrResult(page,jsonResult,onlyReturnNum,keyword){ $('#obj_desc').text("合并请求"); $('#child_total').text(total); - setIssueOrPrInnerHtml(data); + setIssueOrPrInnerHtml(data,"pulls"); } } @@ -235,6 +235,22 @@ var taskDesc={ "speech_synthesis":"语音合成" }; +function getCategoryDesc(key){ + var re = categoryDesc[key]; + if(isEmpty(re)){ + return key; + } + return re; +} + +function getTaskDesc(key){ + var re = categoryDesc[key]; + if(isEmpty(re)){ + return key; + } + return re; +} + function displayDataSetResult(page,jsonResult,onlyReturnNum,keyword){ var data = jsonResult.Result; var total = jsonResult.Total; @@ -257,10 +273,10 @@ function displayDataSetResult(page,jsonResult,onlyReturnNum,keyword){ html += "
"; html += "
" ; if(!isEmpty(recordMap["category"])){ - html += " " +recordMap["category"]+ ""; + html += " " + getCategoryDesc(recordMap["category"]) + ""; } if(!isEmpty(recordMap["task"])){ - html += " " +recordMap["task"]+ ""; + html += " " + getTaskDesc(recordMap["task"]) + ""; } html += " " +recordMap["download_times"] + " "; html +="
"; @@ -370,7 +386,7 @@ function displayUserResult(page,jsonResult,onlyReturnNum,keyword){ } } -function setIssueOrPrInnerHtml(data){ +function setIssueOrPrInnerHtml(data,path){ var sortHtml = ""; sortHtml +="最近更新"; document.getElementById("sort_type").innerHTML=sortHtml; @@ -388,7 +404,7 @@ function setIssueOrPrInnerHtml(data){ html += "

" + recordMap["content"] + "

"; html +="

"; html +=" "; - html +=" " + recordMap["repoUrl"] +"#" + recordMap["id"] + ""; + html +=" " + recordMap["repoUrl"] +"#" + recordMap["id"] + ""; html +=" "; if(isEmpty(recordMap["is_closed"]) || recordMap["is_closed"]=="f"){ html += "关闭"; @@ -415,7 +431,7 @@ function displayIssueResult(page,jsonResult,onlyReturnNum,keyword){ $('#obj_desc').text("任务"); $('#child_total').text(total); - setIssueOrPrInnerHtml(data); + setIssueOrPrInnerHtml(data,"issues"); } } @@ -473,7 +489,7 @@ function displayRepoResult(page,jsonResult,onlyReturnNum,keyword){ } html +="

"; html +="

"; - html +=" " +recordMap["num_watches"] + "  " + recordMap["num_stars"] + "  " + recordMap["num_forks"] +"  "; + html +=" " +recordMap["num_watches"] + "  " + recordMap["num_stars"] + "  " + recordMap["num_forks"] +"  "; html +="    最后更新于 " + getTime(recordMap["updated_unix"],currentTime) +""; if(!isEmpty(recordMap["lang"])){ html +=" " + recordMap["lang"] + ""; diff --git a/routers/search.go b/routers/search.go index 88a14f588..3d38a6053 100644 --- a/routers/search.go +++ b/routers/search.go @@ -194,8 +194,6 @@ func makeRepoResult(sRes *elastic.SearchResult, Key string, OnlyReturnNum bool) } record["hightTopics"] = jsonStrToArray(getLabelValue("topics", recordSource, hit.Highlight)) - //log.Info("hight[\"topics\"]=" + getLabelValue("topics", recordSource, hit.Highlight)) - record["num_watches"] = recordSource["num_watches"] record["num_stars"] = recordSource["num_stars"] record["num_forks"] = recordSource["num_forks"] @@ -205,11 +203,6 @@ func makeRepoResult(sRes *elastic.SearchResult, Key string, OnlyReturnNum bool) log.Info("topicsStr=" + topicsStr) if topicsStr != "null" { record["topics"] = jsonStrToArray(topicsStr) - // topicsStr = strings.Replace(topicsStr, "\"", "", -1) - // topicsStr = topicsStr[1 : len(topicsStr)-1] - // log.Info("record[\"topics\"]=" + topicsStr) - // topicstmp := strings.Split(topicsStr, ",") - // record["topics"] = topicstmp } } if recordSource["avatar"] != nil { @@ -478,7 +471,7 @@ func makeDatasetResult(sRes *elastic.SearchResult, Key string, OnlyReturnNum boo } else { record["description"] = "" } - record["file_name"] = recordSource["file_name"] + record["file_name"] = getLabelValue("file_name", recordSource, hit.Highlight) record["task"] = recordSource["task"] record["download_times"] = recordSource["download_times"] record["created_unix"] = recordSource["created_unix"] @@ -660,6 +653,8 @@ 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 { + searchJson, _ := json.Marshal(res) + log.Info("searchJson=" + string(searchJson)) result := makeIssueResult(res, Key, OnlyReturnNum) ctx.JSON(200, result) } else {