Browse Source

增加高亮显示

Signed-off-by: zouap <zouap@pcl.ac.cn>
tags/v1.22.3.2^2
zouap 4 years ago
parent
commit
5af94b8774
1 changed files with 24 additions and 11 deletions
  1. +24
    -11
      routers/search.go

+ 24
- 11
routers/search.go View File

@@ -161,10 +161,10 @@ func makeRepoResult(sRes *elastic.SearchResult, Key string) *SearchRes {
if err == nil {
record := make(map[string]interface{})
record["id"] = hit.Id
record["name"] = recordSource["name"]
record["name"] = getLabelValue("name", recordSource, hit.Highlight)
record["owner_name"] = recordSource["owner_name"]
if recordSource["description"] != nil {
desc := recordSource["description"].(string)
desc := getLabelValue("description", recordSource, hit.Highlight)
record["description"] = dealLongText(desc, Key, hit.MatchedQueries)
} else {
record["description"] = ""
@@ -277,6 +277,18 @@ func searchUserOrOrg(ctx *context.Context, TableName string, Key string, Page in
}
}

func getLabelValue(key string, recordSource map[string]interface{}, searchHighliht elastic.SearchHitHighlight) string {
if value, ok := searchHighliht[key]; !ok {
if recordSource[key] != nil {
return recordSource[key].(string)
} else {
return ""
}
} else {
return value[0]
}
}

func makeUserOrOrgResult(sRes *elastic.SearchResult, Key string, ctx *context.Context) *SearchRes {
total := sRes.Hits.TotalHits.Value
result := make([]map[string]interface{}, 0)
@@ -291,10 +303,10 @@ func makeUserOrOrgResult(sRes *elastic.SearchResult, Key string, ctx *context.Co
if err == nil {
record := make(map[string]interface{})
record["id"] = hit.Id
record["name"] = recordSource["name"]
record["full_name"] = recordSource["full_name"]
record["name"] = getLabelValue("name", recordSource, hit.Highlight)
record["full_name"] = getLabelValue("full_name", recordSource, hit.Highlight)
if recordSource["description"] != nil {
desc := recordSource["description"].(string)
desc := getLabelValue("description", recordSource, hit.Highlight)
record["description"] = dealLongText(desc, Key, hit.MatchedQueries)
} else {
record["description"] = ""
@@ -398,14 +410,15 @@ func makeDatasetResult(sRes *elastic.SearchResult, Key string) *SearchRes {
record["owerName"] = user.GetDisplayName()
record["avatar"] = user.RelAvatarLink()
}
record["title"] = recordSource["title"]
record["category"] = recordSource["category"]
record["title"] = getLabelValue("title", recordSource, hit.Highlight)
record["category"] = getLabelValue("category", recordSource, hit.Highlight)
if recordSource["description"] != nil {
desc := recordSource["description"].(string)
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)
@@ -505,9 +518,9 @@ func makeIssueResult(sRes *elastic.SearchResult, Key string) *SearchRes {
record["avatar"] = repo.RelAvatarLink()
}
}
record["name"] = recordSource["name"]
record["name"] = getLabelValue("name", recordSource, hit.Highlight)
if recordSource["content"] != nil {
desc := recordSource["content"].(string)
desc := getLabelValue("content", recordSource, hit.Highlight)
record["content"] = dealLongText(desc, Key, hit.MatchedQueries)
} else {
record["content"] = ""
@@ -516,7 +529,7 @@ func makeIssueResult(sRes *elastic.SearchResult, Key string) *SearchRes {
record["pr_id"] = recordSource["pr_id"]
}
if recordSource["comment"] != nil {
desc := recordSource["comment"].(string)
desc := getLabelValue("comment", recordSource, hit.Highlight)
record["comment"] = dealLongText(desc, Key, hit.MatchedQueries)
} else {
record["comment"] = ""


Loading…
Cancel
Save