From a9d7253f9c8382b94280bd1ac2fb00fdc9470197 Mon Sep 17 00:00:00 2001 From: zouap Date: Wed, 23 Feb 2022 15:28:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=BB=E5=8A=A1=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E7=9A=84=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 | 81 +++++++++++++++++++++++++++++-- routers/search.go | 3 +- templates/explore/search_new.tmpl | 12 ++--- 3 files changed, 85 insertions(+), 11 deletions(-) diff --git a/public/home/search.js b/public/home/search.js index 73a39cf49..205afcddb 100644 --- a/public/home/search.js +++ b/public/home/search.js @@ -23,7 +23,39 @@ function isEmpty(str){ return false; } +var itemType={ + "1":"repository", + "2":"issue", + "3":"user", + "4":"org", + "5":"dataset", + "6":"pr" +}; + +var sortBy={ + "11":"updated_unix", + "12":"num_watches", + "13":"num_stars", + "14":"num_forks", + "21":"updated_unix", + "31":"created_unix", + "32":"name", + "41":"created_unix", + "42":"name", + "51":"download_times", + "61":"updated_unix" +}; + +function searchItem(type,sortType){ + console.log("enter here."); + var keyword = document.getElementById("keyword_input").value; + var page =1; + var pageSize=15; + if(!isEmpty(keyword)){ + doSearch(itemType[type],keyword,page,pageSize,false,sortBy[sortType]); + } +} function search(){ console.log("enter here."); @@ -31,7 +63,7 @@ function search(){ var page =1; var pageSize=15; if(!isEmpty(keyword)){ - doSearch("repository",keyword,page,pageSize,false); + doSearch("repository",keyword,page,pageSize,false,sortBy[11]); //doSearch("issue",keyword,page,pageSize,true); //doSearch("user",keyword,page,pageSize,true); //doSearch("org",keyword,page,pageSize,true); @@ -40,7 +72,7 @@ function search(){ } } -function doSearch(tableName,keyword,page,pageSize=15,onlyReturnNum=true){ +function doSearch(tableName,keyword,page,pageSize=15,onlyReturnNum=true,sortBy){ $.ajax({ type:"GET", url:"/all/dosearch/", @@ -54,7 +86,8 @@ function doSearch(tableName,keyword,page,pageSize=15,onlyReturnNum=true){ 'Key': keyword, 'Page': page, 'PageSize': pageSize, - 'OnlyReturnNum':onlyReturnNum + 'OnlyReturnNum':onlyReturnNum, + 'SortBy':sortBy }, async:true, success:function(json){ @@ -62,7 +95,7 @@ function doSearch(tableName,keyword,page,pageSize=15,onlyReturnNum=true){ displayResult(tableName,page,json,onlyReturnNum,keyword); }, error:function(response) { - console.log(response); + console.log(response); } }); } @@ -135,6 +168,37 @@ function displayIssueResult(page,jsonResult,onlyReturnNum,keyword){ $('#keyword_desc').text(keyword); $('#obj_desc').text("任务"); $('#child_total').text(total); + + var sortHtml = ""; + sortHtml +="最近更新" + var html = ""; + var currentTime = new Date().getTime(); + for(var i = 0; i < data.length;i++){ + var recordMap = data[i]; + html += "
"; + html += "
"; + html += "
"; + html += " " + record["name"] + ""; + html +="
"; + html += "
"; + html += "

" + recordMap["description"] + "

"; + html +="

"; + html +=" "; + html +=" " + record["repoUrl"] +"#" + record["id"] + ""; + html +=" "; + if(isEmpty(record["is_closed"]) || record["is_closed"]=="false"){ + html += "关闭"; + }else{ + html += "开启中"; + } + html +=" 最后更新于 " + getTime(recordMap["updated_unix"],currentTime) +""; + + html +="

"; + html +="
"; + html +="
"; + html +="
"; + } + } } @@ -147,6 +211,15 @@ function displayRepoResult(page,jsonResult,onlyReturnNum,keyword){ $('#keyword_desc').text(keyword); $('#obj_desc').text("项目"); $('#child_total').text(total); + + var sortHtml = ""; + sortHtml +="最近更新" + sortHtml +="关注数" + sortHtml +="点赞数" + sortHtml +="Fork数" + + document.getElementById("sort_type").innerHTML=sortHtml; + var html = ""; var currentTime = new Date().getTime(); for(var i = 0; i < data.length;i++){ diff --git a/routers/search.go b/routers/search.go index c5b0a50bf..ab39f6055 100644 --- a/routers/search.go +++ b/routers/search.go @@ -267,7 +267,7 @@ func searchUserOrOrg(ctx *context.Context, TableName string, Key string, Page in */ SortBy := ctx.Query("SortBy") if SortBy == "" { - SortBy = "updated_unix.keyword" + SortBy = "created_unix.keyword" } ascending := ctx.QueryBool("Ascending") boolQ := elastic.NewBoolQuery() @@ -561,6 +561,7 @@ func makeIssueResult(sRes *elastic.SearchResult, Key string, OnlyReturnNum bool) record["comment"] = "" } record["num_comments"] = recordSource["num_comments"] + record["is_closed"] = recordSource["is_closed"] record["updated_unix"] = recordSource["updated_unix"] result = append(result, record) } else { diff --git a/templates/explore/search_new.tmpl b/templates/explore/search_new.tmpl index ca6258471..371083803 100644 --- a/templates/explore/search_new.tmpl +++ b/templates/explore/search_new.tmpl @@ -20,27 +20,27 @@