From fe93d5dfa592d59295f5c5e8ff0e6f8f1ace8cf2 Mon Sep 17 00:00:00 2001 From: zouap Date: Thu, 24 Feb 2022 15:05:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=94=A8=E6=88=B7=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E7=BB=93=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- models/dbsql/dataset_foreigntable_for_es.sql | 5 +- public/home/search.js | 63 ++++++++++++++++++++ routers/search.go | 33 +++++----- 3 files changed, 85 insertions(+), 16 deletions(-) diff --git a/models/dbsql/dataset_foreigntable_for_es.sql b/models/dbsql/dataset_foreigntable_for_es.sql index fa46a5777..11cd745a2 100644 --- a/models/dbsql/dataset_foreigntable_for_es.sql +++ b/models/dbsql/dataset_foreigntable_for_es.sql @@ -38,7 +38,7 @@ DELETE FROM public.dataset_es; user_id, repo_id, created_unix, - updated_unix,file_name) + updated_unix,file_name,file_type) SELECT b.id, b.title, @@ -128,7 +128,8 @@ $def$ title=NEW.title, category=NEW.category, download_times=NEW.download_times, - file_name=(select array_to_string(array_agg(name order by created_unix desc),',') from public.attachment where dataset_id=NEW.id) + file_name=(select array_to_string(array_agg(name order by created_unix desc),',') from public.attachment where dataset_id=NEW.id), + where id=NEW.id; return new; END diff --git a/public/home/search.js b/public/home/search.js index b62c1af47..34fb9f5b3 100644 --- a/public/home/search.js +++ b/public/home/search.js @@ -139,6 +139,36 @@ function displayDataSetResult(page,jsonResult,onlyReturnNum,keyword){ $('#keyword_desc').text(keyword); $('#obj_desc').text("数据集"); $('#child_total').text(total); + + var sortHtml = ""; + sortHtml +="最近更新"; + sortHtml +="名称自然序"; + document.getElementById("sort_type").innerHTML=sortHtml; + + var html = ""; + var currentTime = new Date().getTime(); + for(var i = 0; i < data.length;i++){ + var recordMap = data[i]; + html += "
"; + html += "
"; + html += "
" ; + html += " " +recordMap["download_times"] + " "; + html +="
"; + html += "
"; + html += " " + recordMap["repoUrl"] + ""; + html +=" "; + html +="
"; + html += "
"; + html += "

" + recordMap["description"] + "

"; + html += "

" + recordMap["file_name"] + "

"; + html +="

"; + html +=" 最后更新于 " + getTime(recordMap["updated_unix"],currentTime) +""; + html +="

"; + html +="
"; + html +="
"; + html +="
"; + } + document.getElementById("child_search_item").innerHTML=html; } } @@ -151,6 +181,39 @@ function displayOrgResult(page,jsonResult,onlyReturnNum,keyword){ $('#keyword_desc').text(keyword); $('#obj_desc').text("组织"); $('#child_total').text(total); + + var sortHtml = ""; + sortHtml +="最近更新"; + sortHtml +="名称自然序"; + document.getElementById("sort_type").innerHTML=sortHtml; + + var html = ""; + var currentTime = new Date().getTime(); + for(var i = 0; i < data.length;i++){ + var recordMap = data[i]; + html += "
"; + html += ""; + html += "
"; + html += "
"; + html += " " + recordMap["name"] + ""; + html +="
"; + html += "
"; + html += "

" + recordMap["description"] + "

"; + html +="

"; + html +=" " + recordMap["location"]; + html +=" "; + if(!isEmpty(recordMap["website"]) && recordMap["website"] != "null"){ + html +=" " + "" + recordMap["website"] + ""; + } + html +=" 加入于 "; + var userAddDate = new Date(recordMap["created_unix"]*1000); + html += monthDisplay[userAddDate.getMonth()] + " " + userAddDate.getDay() + " " + userAddDate.getFullYear(); + html +="

"; + html +="
"; + html +="
"; + html +="
"; + } + document.getElementById("child_search_item").innerHTML=html; } } var monthDisplay=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Spt","Oct","Nov","Dec"); diff --git a/routers/search.go b/routers/search.go index 798e2dff4..dfc18f38e 100644 --- a/routers/search.go +++ b/routers/search.go @@ -437,6 +437,7 @@ func makeDatasetResult(sRes *elastic.SearchResult, Key string, OnlyReturnNum boo record["avatar"] = user.RelAvatarLink() } } + setRepoInfo(recordSource, record) record["title"] = getLabelValue("title", recordSource, hit.Highlight) record["category"] = getLabelValue("category", recordSource, hit.Highlight) if recordSource["description"] != nil { @@ -520,6 +521,23 @@ func queryHighlight(names ...string) *elastic.Highlight { return re } +func setRepoInfo(recordSource map[string]interface{}, record map[string]interface{}) { + repoIdstr := recordSource["repo_id"].(string) + repoId, cerr := strconv.ParseInt(repoIdstr, 10, 64) + if cerr == nil { + repo, errRepo := models.GetRepositoryByID(repoId) + if errRepo == nil { + log.Info("repo_url=" + repo.FullName()) + record["repoUrl"] = repo.FullName() + record["avatar"] = repo.RelAvatarLink() + } else { + log.Info("repo err=" + errRepo.Error()) + } + } else { + log.Info("parse int err=" + cerr.Error()) + } +} + func makeIssueResult(sRes *elastic.SearchResult, Key string, OnlyReturnNum bool) *SearchRes { total := sRes.Hits.TotalHits.Value result := make([]map[string]interface{}, 0) @@ -536,20 +554,7 @@ func makeIssueResult(sRes *elastic.SearchResult, Key string, OnlyReturnNum bool) 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 { - log.Info("repo_url=" + repo.FullName()) - record["repoUrl"] = repo.FullName() - record["avatar"] = repo.RelAvatarLink() - } else { - log.Info("repo err=" + errRepo.Error()) - } - } else { - log.Info("parse int err=" + cerr.Error()) - } + setRepoInfo(recordSource, record) record["name"] = getLabelValue("name", recordSource, hit.Highlight) if recordSource["content"] != nil { desc := getLabelValue("content", recordSource, hit.Highlight)