From 82dedae8e4a5edfa6f95de09fd046ea80d390dbe Mon Sep 17 00:00:00 2001 From: zouap Date: Fri, 7 Jan 2022 10:43: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 --- routers/search.go | 43 ++++++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/routers/search.go b/routers/search.go index 1a774eec6..f2e250345 100644 --- a/routers/search.go +++ b/routers/search.go @@ -160,9 +160,12 @@ func makeRepoResult(sRes *elastic.SearchResult, Key string) *SearchRes { record := make(map[string]interface{}) record["name"] = recordSource["name"] record["owner_name"] = recordSource["owner_name"] - desc := recordSource["description"].(string) - - record["description"] = dealLongText(desc, Key, hit.MatchedQueries) + if recordSource["description"] != nil { + desc := recordSource["description"].(string) + record["description"] = dealLongText(desc, Key, hit.MatchedQueries) + } else { + record["description"] = "" + } record["num_watches"] = recordSource["num_watches"] record["num_stars"] = recordSource["num_stars"] @@ -279,9 +282,12 @@ func makeUserOrOrgResult(sRes *elastic.SearchResult, Key string, ctx *context.Co record := make(map[string]interface{}) record["name"] = recordSource["name"] record["full_name"] = recordSource["full_name"] - desc := recordSource["description"].(string) - - record["description"] = dealLongText(desc, Key, hit.MatchedQueries) + if recordSource["description"] != nil { + desc := recordSource["description"].(string) + record["description"] = dealLongText(desc, Key, hit.MatchedQueries) + } else { + record["description"] = "" + } if ctx.User != nil { record["email"] = recordSource["email"] } else { @@ -383,8 +389,12 @@ func makeDatasetResult(sRes *elastic.SearchResult, Key string) *SearchRes { } record["title"] = recordSource["title"] record["category"] = recordSource["category"] - desc := recordSource["description"].(string) - record["description"] = dealLongText(desc, Key, hit.MatchedQueries) + if recordSource["description"] != nil { + desc := recordSource["description"].(string) + record["description"] = dealLongText(desc, Key, hit.MatchedQueries) + } else { + record["description"] = "" + } record["download_times"] = recordSource["download_times"] record["created_unix"] = recordSource["created_unix"] result = append(result, record) @@ -465,14 +475,21 @@ func makeIssueResult(sRes *elastic.SearchResult, Key string) *SearchRes { } } record["name"] = recordSource["name"] - desc := recordSource["content"].(string) - record["content"] = dealLongText(desc, Key, hit.MatchedQueries) + if recordSource["content"] != nil { + desc := recordSource["content"].(string) + record["content"] = dealLongText(desc, Key, hit.MatchedQueries) + } else { + record["content"] = "" + } if recordSource["pr_id"] != nil { record["pr_id"] = recordSource["pr_id"] } - - desc = recordSource["comment"].(string) - record["comment"] = dealLongText(desc, Key, hit.MatchedQueries) + if recordSource["comment"] != nil { + desc := recordSource["comment"].(string) + 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)