|
|
|
@@ -43,6 +43,7 @@ func SearchApi(ctx *context.Context) { |
|
|
|
Key := ctx.Query("Key") |
|
|
|
Page := ctx.QueryInt("Page") |
|
|
|
PageSize := ctx.QueryInt("PageSize") |
|
|
|
OnlyReturnNum := ctx.QueryBool("OnlyReturnNum") |
|
|
|
if Page <= 0 { |
|
|
|
Page = 1 |
|
|
|
} |
|
|
|
@@ -51,27 +52,27 @@ func SearchApi(ctx *context.Context) { |
|
|
|
} |
|
|
|
|
|
|
|
if TableName == "repository" { |
|
|
|
searchRepo(ctx, "repository-es-index", Key, Page, PageSize) |
|
|
|
searchRepo(ctx, "repository-es-index", Key, Page, PageSize, OnlyReturnNum) |
|
|
|
return |
|
|
|
} else if TableName == "issue" { |
|
|
|
searchIssue(ctx, "issue-es-index", Key, Page, PageSize) |
|
|
|
searchIssue(ctx, "issue-es-index", Key, Page, PageSize, OnlyReturnNum) |
|
|
|
return |
|
|
|
} else if TableName == "user" { |
|
|
|
searchUserOrOrg(ctx, "user-es-index", Key, Page, PageSize, true) |
|
|
|
searchUserOrOrg(ctx, "user-es-index", Key, Page, PageSize, true, OnlyReturnNum) |
|
|
|
return |
|
|
|
} else if TableName == "org" { |
|
|
|
searchUserOrOrg(ctx, "user-es-index", Key, Page, PageSize, false) |
|
|
|
searchUserOrOrg(ctx, "user-es-index", Key, Page, PageSize, false, OnlyReturnNum) |
|
|
|
return |
|
|
|
} else if TableName == "dataset" { |
|
|
|
searchDataSet(ctx, "dataset-es-index", Key, Page, PageSize) |
|
|
|
searchDataSet(ctx, "dataset-es-index", Key, Page, PageSize, OnlyReturnNum) |
|
|
|
return |
|
|
|
} else if TableName == "pr" { |
|
|
|
searchPR(ctx, "issue-es-index", Key, Page, PageSize) |
|
|
|
searchPR(ctx, "issue-es-index", Key, Page, PageSize, OnlyReturnNum) |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func searchRepoByLabel(ctx *context.Context, TableName string, Key string, Page int, PageSize int) { |
|
|
|
func searchRepoByLabel(ctx *context.Context, TableName string, Key string, Page int, PageSize int, OnlyReturnNum bool) { |
|
|
|
/* |
|
|
|
项目, ES名称: repository-es-index |
|
|
|
搜索: |
|
|
|
@@ -96,7 +97,7 @@ func searchRepoByLabel(ctx *context.Context, TableName string, Key string, Page |
|
|
|
boolQ.Should(topicsQuery) |
|
|
|
res, err := client.Search(TableName).Query(boolQ).Sort(SortBy, ascending).From((Page - 1) * PageSize).Size(PageSize).Do(ctx.Req.Context()) |
|
|
|
if err == nil { |
|
|
|
result := makeRepoResult(res, "") |
|
|
|
result := makeRepoResult(res, "", OnlyReturnNum) |
|
|
|
ctx.JSON(200, result) |
|
|
|
return |
|
|
|
} else { |
|
|
|
@@ -106,7 +107,7 @@ func searchRepoByLabel(ctx *context.Context, TableName string, Key string, Page |
|
|
|
ctx.JSON(200, "") |
|
|
|
} |
|
|
|
|
|
|
|
func searchRepo(ctx *context.Context, TableName string, Key string, Page int, PageSize int) { |
|
|
|
func searchRepo(ctx *context.Context, TableName string, Key string, Page int, PageSize int, OnlyReturnNum bool) { |
|
|
|
/* |
|
|
|
项目, ES名称: repository-es-index |
|
|
|
搜索: |
|
|
|
@@ -136,7 +137,7 @@ func searchRepo(ctx *context.Context, TableName string, Key string, Page int, Pa |
|
|
|
if err == nil { |
|
|
|
searchJson, _ := json.Marshal(res) |
|
|
|
log.Info("searchJson=" + string(searchJson)) |
|
|
|
result := makeRepoResult(res, Key) |
|
|
|
result := makeRepoResult(res, Key, OnlyReturnNum) |
|
|
|
ctx.JSON(200, result) |
|
|
|
} else { |
|
|
|
log.Info("query es error," + err.Error()) |
|
|
|
@@ -149,7 +150,7 @@ func searchRepo(ctx *context.Context, TableName string, Key string, Page int, Pa |
|
|
|
if err == nil { |
|
|
|
searchJson, _ := json.Marshal(res) |
|
|
|
log.Info("searchJson=" + string(searchJson)) |
|
|
|
result := makeRepoResult(res, "") |
|
|
|
result := makeRepoResult(res, "", OnlyReturnNum) |
|
|
|
ctx.JSON(200, result) |
|
|
|
} else { |
|
|
|
log.Info("query es error," + err.Error()) |
|
|
|
@@ -158,47 +159,47 @@ func searchRepo(ctx *context.Context, TableName string, Key string, Page int, Pa |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func makeRepoResult(sRes *elastic.SearchResult, Key string) *SearchRes { |
|
|
|
func makeRepoResult(sRes *elastic.SearchResult, Key string, OnlyReturnNum bool) *SearchRes { |
|
|
|
total := sRes.Hits.TotalHits.Value |
|
|
|
result := make([]map[string]interface{}, 0) |
|
|
|
if !OnlyReturnNum { |
|
|
|
for i, hit := range sRes.Hits.Hits { |
|
|
|
log.Info("this is repo query " + fmt.Sprint(i) + " result.") |
|
|
|
recordSource := make(map[string]interface{}) |
|
|
|
source, err := hit.Source.MarshalJSON() |
|
|
|
|
|
|
|
for i, hit := range sRes.Hits.Hits { |
|
|
|
log.Info("this is repo query " + fmt.Sprint(i) + " result.") |
|
|
|
recordSource := make(map[string]interface{}) |
|
|
|
source, err := hit.Source.MarshalJSON() |
|
|
|
|
|
|
|
if err == nil { |
|
|
|
err = json.Unmarshal(source, &recordSource) |
|
|
|
if err == nil { |
|
|
|
record := make(map[string]interface{}) |
|
|
|
record["id"] = hit.Id |
|
|
|
record["name"] = getLabelValue("name", recordSource, hit.Highlight) |
|
|
|
record["owner_name"] = recordSource["owner_name"] |
|
|
|
if recordSource["description"] != nil { |
|
|
|
desc := getLabelValue("description", recordSource, hit.Highlight) |
|
|
|
record["description"] = dealLongText(desc, Key, hit.MatchedQueries) |
|
|
|
} else { |
|
|
|
record["description"] = "" |
|
|
|
} |
|
|
|
err = json.Unmarshal(source, &recordSource) |
|
|
|
if err == nil { |
|
|
|
record := make(map[string]interface{}) |
|
|
|
record["id"] = hit.Id |
|
|
|
record["name"] = getLabelValue("name", recordSource, hit.Highlight) |
|
|
|
record["owner_name"] = recordSource["owner_name"] |
|
|
|
if recordSource["description"] != nil { |
|
|
|
desc := getLabelValue("description", recordSource, hit.Highlight) |
|
|
|
record["description"] = dealLongText(desc, Key, hit.MatchedQueries) |
|
|
|
} else { |
|
|
|
record["description"] = "" |
|
|
|
} |
|
|
|
|
|
|
|
record["num_watches"] = recordSource["num_watches"] |
|
|
|
record["num_stars"] = recordSource["num_stars"] |
|
|
|
record["num_forks"] = recordSource["num_forks"] |
|
|
|
record["topics"] = recordSource["topics"] |
|
|
|
if recordSource["avatar"] != nil { |
|
|
|
record["avatar"] = setting.AppSubURL + "/repo-avatars/" + recordSource["avatar"].(string) |
|
|
|
record["num_watches"] = recordSource["num_watches"] |
|
|
|
record["num_stars"] = recordSource["num_stars"] |
|
|
|
record["num_forks"] = recordSource["num_forks"] |
|
|
|
record["topics"] = recordSource["topics"] |
|
|
|
if recordSource["avatar"] != nil { |
|
|
|
record["avatar"] = setting.AppSubURL + "/repo-avatars/" + recordSource["avatar"].(string) |
|
|
|
} |
|
|
|
record["updated_unix"] = recordSource["updated_unix"] |
|
|
|
record["lang"] = recordSource["lang"] |
|
|
|
result = append(result, record) |
|
|
|
} else { |
|
|
|
log.Info("deal repo source error," + err.Error()) |
|
|
|
} |
|
|
|
record["updated_unix"] = recordSource["updated_unix"] |
|
|
|
record["lang"] = recordSource["lang"] |
|
|
|
result = append(result, record) |
|
|
|
} else { |
|
|
|
log.Info("deal repo source error," + err.Error()) |
|
|
|
} |
|
|
|
} else { |
|
|
|
log.Info("deal repo source error," + err.Error()) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
returnObj := &SearchRes{ |
|
|
|
Total: total, |
|
|
|
Result: result, |
|
|
|
@@ -241,7 +242,7 @@ func dealLongText(text string, Key string, MatchedQueries []string) string { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
func searchUserOrOrg(ctx *context.Context, TableName string, Key string, Page int, PageSize int, IsQueryUser bool) { |
|
|
|
func searchUserOrOrg(ctx *context.Context, TableName string, Key string, Page int, PageSize int, IsQueryUser bool, OnlyReturnNum bool) { |
|
|
|
/* |
|
|
|
用户或者组织 ES名称: user-es-index |
|
|
|
搜索: |
|
|
|
@@ -280,7 +281,7 @@ func searchUserOrOrg(ctx *context.Context, TableName string, Key string, Page in |
|
|
|
if err == nil { |
|
|
|
searchJson, _ := json.Marshal(res) |
|
|
|
log.Info("searchJson=" + string(searchJson)) |
|
|
|
result := makeUserOrOrgResult(res, Key, ctx) |
|
|
|
result := makeUserOrOrgResult(res, Key, ctx, OnlyReturnNum) |
|
|
|
ctx.JSON(200, result) |
|
|
|
} else { |
|
|
|
log.Info("query es error," + err.Error()) |
|
|
|
@@ -300,61 +301,60 @@ func getLabelValue(key string, recordSource map[string]interface{}, searchHighli |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func makeUserOrOrgResult(sRes *elastic.SearchResult, Key string, ctx *context.Context) *SearchRes { |
|
|
|
func makeUserOrOrgResult(sRes *elastic.SearchResult, Key string, ctx *context.Context, OnlyReturnNum bool) *SearchRes { |
|
|
|
total := sRes.Hits.TotalHits.Value |
|
|
|
result := make([]map[string]interface{}, 0) |
|
|
|
if !OnlyReturnNum { |
|
|
|
for i, hit := range sRes.Hits.Hits { |
|
|
|
log.Info("this is user query " + fmt.Sprint(i) + " result.") |
|
|
|
recordSource := make(map[string]interface{}) |
|
|
|
source, err := hit.Source.MarshalJSON() |
|
|
|
|
|
|
|
for i, hit := range sRes.Hits.Hits { |
|
|
|
log.Info("this is user query " + fmt.Sprint(i) + " result.") |
|
|
|
recordSource := make(map[string]interface{}) |
|
|
|
source, err := hit.Source.MarshalJSON() |
|
|
|
|
|
|
|
if err == nil { |
|
|
|
err = json.Unmarshal(source, &recordSource) |
|
|
|
if err == nil { |
|
|
|
record := make(map[string]interface{}) |
|
|
|
record["id"] = hit.Id |
|
|
|
record["name"] = getLabelValue("name", recordSource, hit.Highlight) |
|
|
|
record["full_name"] = getLabelValue("full_name", recordSource, hit.Highlight) |
|
|
|
if recordSource["description"] != nil { |
|
|
|
desc := getLabelValue("description", recordSource, hit.Highlight) |
|
|
|
record["description"] = dealLongText(desc, Key, hit.MatchedQueries) |
|
|
|
} else { |
|
|
|
record["description"] = "" |
|
|
|
} |
|
|
|
if ctx.User != nil { |
|
|
|
record["email"] = recordSource["email"] |
|
|
|
} else { |
|
|
|
record["email"] = "" |
|
|
|
} |
|
|
|
err = json.Unmarshal(source, &recordSource) |
|
|
|
if err == nil { |
|
|
|
record := make(map[string]interface{}) |
|
|
|
record["id"] = hit.Id |
|
|
|
record["name"] = getLabelValue("name", recordSource, hit.Highlight) |
|
|
|
record["full_name"] = getLabelValue("full_name", recordSource, hit.Highlight) |
|
|
|
if recordSource["description"] != nil { |
|
|
|
desc := getLabelValue("description", recordSource, hit.Highlight) |
|
|
|
record["description"] = dealLongText(desc, Key, hit.MatchedQueries) |
|
|
|
} else { |
|
|
|
record["description"] = "" |
|
|
|
} |
|
|
|
if ctx.User != nil { |
|
|
|
record["email"] = recordSource["email"] |
|
|
|
} else { |
|
|
|
record["email"] = "" |
|
|
|
} |
|
|
|
|
|
|
|
record["location"] = recordSource["location"] |
|
|
|
record["website"] = recordSource["website"] |
|
|
|
record["num_repos"] = recordSource["num_repos"] |
|
|
|
record["num_teams"] = recordSource["num_teams"] |
|
|
|
record["num_members"] = recordSource["num_members"] |
|
|
|
record["location"] = recordSource["location"] |
|
|
|
record["website"] = recordSource["website"] |
|
|
|
record["num_repos"] = recordSource["num_repos"] |
|
|
|
record["num_teams"] = recordSource["num_teams"] |
|
|
|
record["num_members"] = recordSource["num_members"] |
|
|
|
|
|
|
|
record["avatar"] = strings.TrimRight(setting.AppSubURL, "/") + "/user/avatar/" + recordSource["name"].(string) + "/" + strconv.Itoa(-1) |
|
|
|
record["updated_unix"] = recordSource["updated_unix"] |
|
|
|
record["created_unix"] = recordSource["created_unix"] |
|
|
|
result = append(result, record) |
|
|
|
record["avatar"] = strings.TrimRight(setting.AppSubURL, "/") + "/user/avatar/" + recordSource["name"].(string) + "/" + strconv.Itoa(-1) |
|
|
|
record["updated_unix"] = recordSource["updated_unix"] |
|
|
|
record["created_unix"] = recordSource["created_unix"] |
|
|
|
result = append(result, record) |
|
|
|
} else { |
|
|
|
log.Info("deal user source error," + err.Error()) |
|
|
|
} |
|
|
|
} else { |
|
|
|
log.Info("deal user source error," + err.Error()) |
|
|
|
} |
|
|
|
} else { |
|
|
|
log.Info("deal user source error," + err.Error()) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
returnObj := &SearchRes{ |
|
|
|
Total: total, |
|
|
|
Result: result, |
|
|
|
} |
|
|
|
|
|
|
|
return returnObj |
|
|
|
} |
|
|
|
|
|
|
|
func searchDataSet(ctx *context.Context, TableName string, Key string, Page int, PageSize int) { |
|
|
|
func searchDataSet(ctx *context.Context, TableName string, Key string, Page int, PageSize int, OnlyReturnNum bool) { |
|
|
|
/* |
|
|
|
数据集,ES名称:dataset-es-index |
|
|
|
搜索: |
|
|
|
@@ -381,7 +381,7 @@ func searchDataSet(ctx *context.Context, TableName string, Key string, Page int, |
|
|
|
boolQ.Should(nameQuery, descQuery, categoryQuery, fileNameQuery) |
|
|
|
res, err := client.Search(TableName).Query(boolQ).Sort(SortBy, ascending).From((Page - 1) * PageSize).Size(PageSize).Highlight(queryHighlight("title", "description", "file_name", "category")).Do(ctx.Req.Context()) |
|
|
|
if err == nil { |
|
|
|
result := makeDatasetResult(res, Key) |
|
|
|
result := makeDatasetResult(res, Key, OnlyReturnNum) |
|
|
|
ctx.JSON(200, result) |
|
|
|
} else { |
|
|
|
log.Info("query es error," + err.Error()) |
|
|
|
@@ -391,7 +391,7 @@ func searchDataSet(ctx *context.Context, TableName string, Key string, Page int, |
|
|
|
//搜索的属性要指定{"timestamp":{"unmapped_type":"date"}} |
|
|
|
res, err := client.Search(TableName).Sort(SortBy, ascending).From((Page - 1) * PageSize).Size(PageSize).Do(ctx.Req.Context()) |
|
|
|
if err == nil { |
|
|
|
result := makeRepoResult(res, "") |
|
|
|
result := makeDatasetResult(res, "", OnlyReturnNum) |
|
|
|
ctx.JSON(200, result) |
|
|
|
} else { |
|
|
|
log.Info("query es error," + err.Error()) |
|
|
|
@@ -401,49 +401,49 @@ func searchDataSet(ctx *context.Context, TableName string, Key string, Page int, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
func makeDatasetResult(sRes *elastic.SearchResult, Key string) *SearchRes { |
|
|
|
func makeDatasetResult(sRes *elastic.SearchResult, Key string, OnlyReturnNum bool) *SearchRes { |
|
|
|
total := sRes.Hits.TotalHits.Value |
|
|
|
result := make([]map[string]interface{}, 0) |
|
|
|
if !OnlyReturnNum { |
|
|
|
for i, hit := range sRes.Hits.Hits { |
|
|
|
log.Info("this is dataset query " + fmt.Sprint(i) + " result.") |
|
|
|
recordSource := make(map[string]interface{}) |
|
|
|
source, err := hit.Source.MarshalJSON() |
|
|
|
|
|
|
|
for i, hit := range sRes.Hits.Hits { |
|
|
|
log.Info("this is dataset query " + fmt.Sprint(i) + " result.") |
|
|
|
recordSource := make(map[string]interface{}) |
|
|
|
source, err := hit.Source.MarshalJSON() |
|
|
|
|
|
|
|
if err == nil { |
|
|
|
err = json.Unmarshal(source, &recordSource) |
|
|
|
if err == nil { |
|
|
|
record := make(map[string]interface{}) |
|
|
|
record["id"] = hit.Id |
|
|
|
userIdStr := recordSource["user_id"].(string) |
|
|
|
userId, cerr := strconv.ParseInt(userIdStr, 10, 64) |
|
|
|
if cerr == nil { |
|
|
|
user, errUser := models.GetUserByID(userId) |
|
|
|
if errUser == nil { |
|
|
|
record["owerName"] = user.GetDisplayName() |
|
|
|
record["avatar"] = user.RelAvatarLink() |
|
|
|
err = json.Unmarshal(source, &recordSource) |
|
|
|
if err == nil { |
|
|
|
record := make(map[string]interface{}) |
|
|
|
record["id"] = hit.Id |
|
|
|
userIdStr := recordSource["user_id"].(string) |
|
|
|
userId, cerr := strconv.ParseInt(userIdStr, 10, 64) |
|
|
|
if cerr == nil { |
|
|
|
user, errUser := models.GetUserByID(userId) |
|
|
|
if errUser == nil { |
|
|
|
record["owerName"] = user.GetDisplayName() |
|
|
|
record["avatar"] = user.RelAvatarLink() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
record["title"] = getLabelValue("title", recordSource, hit.Highlight) |
|
|
|
record["category"] = getLabelValue("category", recordSource, hit.Highlight) |
|
|
|
if recordSource["description"] != nil { |
|
|
|
desc := getLabelValue("description", recordSource, hit.Highlight) |
|
|
|
record["description"] = dealLongText(desc, Key, hit.MatchedQueries) |
|
|
|
record["title"] = getLabelValue("title", recordSource, hit.Highlight) |
|
|
|
record["category"] = getLabelValue("category", recordSource, hit.Highlight) |
|
|
|
if recordSource["description"] != nil { |
|
|
|
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) |
|
|
|
} else { |
|
|
|
record["description"] = "" |
|
|
|
log.Info("deal dataset source error," + err.Error()) |
|
|
|
} |
|
|
|
record["file_name"] = recordSource["file_name"] |
|
|
|
record["download_times"] = recordSource["download_times"] |
|
|
|
record["created_unix"] = recordSource["created_unix"] |
|
|
|
result = append(result, record) |
|
|
|
} else { |
|
|
|
log.Info("deal dataset source error," + err.Error()) |
|
|
|
} |
|
|
|
} else { |
|
|
|
log.Info("deal dataset source error," + err.Error()) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
returnObj := &SearchRes{ |
|
|
|
Total: total, |
|
|
|
Result: result, |
|
|
|
@@ -452,7 +452,7 @@ func makeDatasetResult(sRes *elastic.SearchResult, Key string) *SearchRes { |
|
|
|
return returnObj |
|
|
|
} |
|
|
|
|
|
|
|
func searchIssue(ctx *context.Context, TableName string, Key string, Page int, PageSize int) { |
|
|
|
func searchIssue(ctx *context.Context, TableName string, Key string, Page int, PageSize int, OnlyReturnNum bool) { |
|
|
|
|
|
|
|
/* |
|
|
|
任务,合并请求 ES名称:issue-es-index |
|
|
|
@@ -487,7 +487,7 @@ func searchIssue(ctx *context.Context, TableName string, Key string, Page int, P |
|
|
|
if err == nil { |
|
|
|
searchJson, _ := json.Marshal(res) |
|
|
|
log.Info("searchJson=" + string(searchJson)) |
|
|
|
result := makeIssueResult(res, Key) |
|
|
|
result := makeIssueResult(res, Key, OnlyReturnNum) |
|
|
|
ctx.JSON(200, result) |
|
|
|
} else { |
|
|
|
log.Info("query es error," + err.Error()) |
|
|
|
@@ -507,58 +507,58 @@ func queryHighlight(names ...string) *elastic.Highlight { |
|
|
|
return re |
|
|
|
} |
|
|
|
|
|
|
|
func makeIssueResult(sRes *elastic.SearchResult, Key string) *SearchRes { |
|
|
|
func makeIssueResult(sRes *elastic.SearchResult, Key string, OnlyReturnNum bool) *SearchRes { |
|
|
|
total := sRes.Hits.TotalHits.Value |
|
|
|
result := make([]map[string]interface{}, 0) |
|
|
|
if !OnlyReturnNum { |
|
|
|
for i, hit := range sRes.Hits.Hits { |
|
|
|
log.Info("this is issue query " + fmt.Sprint(i) + " result.") |
|
|
|
recordSource := make(map[string]interface{}) |
|
|
|
source, err := hit.Source.MarshalJSON() |
|
|
|
|
|
|
|
for i, hit := range sRes.Hits.Hits { |
|
|
|
log.Info("this is issue query " + fmt.Sprint(i) + " result.") |
|
|
|
recordSource := make(map[string]interface{}) |
|
|
|
source, err := hit.Source.MarshalJSON() |
|
|
|
|
|
|
|
if err == nil { |
|
|
|
err = json.Unmarshal(source, &recordSource) |
|
|
|
if err == nil { |
|
|
|
record := make(map[string]interface{}) |
|
|
|
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 { |
|
|
|
record["repoUrl"] = repo.FullName() |
|
|
|
record["avatar"] = repo.RelAvatarLink() |
|
|
|
err = json.Unmarshal(source, &recordSource) |
|
|
|
if err == nil { |
|
|
|
record := make(map[string]interface{}) |
|
|
|
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 { |
|
|
|
record["repoUrl"] = repo.FullName() |
|
|
|
record["avatar"] = repo.RelAvatarLink() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
record["name"] = getLabelValue("name", recordSource, hit.Highlight) |
|
|
|
if recordSource["content"] != nil { |
|
|
|
desc := getLabelValue("content", recordSource, hit.Highlight) |
|
|
|
record["content"] = dealLongText(desc, Key, hit.MatchedQueries) |
|
|
|
} else { |
|
|
|
record["content"] = "" |
|
|
|
} |
|
|
|
if recordSource["pr_id"] != nil { |
|
|
|
record["pr_id"] = recordSource["pr_id"] |
|
|
|
} |
|
|
|
if recordSource["comment"] != nil { |
|
|
|
desc := getLabelValue("comment", recordSource, hit.Highlight) |
|
|
|
record["comment"] = dealLongText(desc, Key, hit.MatchedQueries) |
|
|
|
record["name"] = getLabelValue("name", recordSource, hit.Highlight) |
|
|
|
if recordSource["content"] != nil { |
|
|
|
desc := getLabelValue("content", recordSource, hit.Highlight) |
|
|
|
record["content"] = dealLongText(desc, Key, hit.MatchedQueries) |
|
|
|
} else { |
|
|
|
record["content"] = "" |
|
|
|
} |
|
|
|
if recordSource["pr_id"] != nil { |
|
|
|
record["pr_id"] = recordSource["pr_id"] |
|
|
|
} |
|
|
|
if recordSource["comment"] != nil { |
|
|
|
desc := getLabelValue("comment", recordSource, hit.Highlight) |
|
|
|
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) |
|
|
|
} else { |
|
|
|
record["comment"] = "" |
|
|
|
log.Info("deal issue source error," + err.Error()) |
|
|
|
} |
|
|
|
record["num_comments"] = recordSource["num_comments"] |
|
|
|
record["updated_unix"] = recordSource["updated_unix"] |
|
|
|
result = append(result, record) |
|
|
|
} else { |
|
|
|
log.Info("deal issue source error," + err.Error()) |
|
|
|
} |
|
|
|
} else { |
|
|
|
log.Info("deal issue source error," + err.Error()) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
returnObj := &SearchRes{ |
|
|
|
Total: total, |
|
|
|
Result: result, |
|
|
|
@@ -567,7 +567,7 @@ func makeIssueResult(sRes *elastic.SearchResult, Key string) *SearchRes { |
|
|
|
return returnObj |
|
|
|
} |
|
|
|
|
|
|
|
func searchPR(ctx *context.Context, TableName string, Key string, Page int, PageSize int) { |
|
|
|
func searchPR(ctx *context.Context, TableName string, Key string, Page int, PageSize int, OnlyReturnNum bool) { |
|
|
|
|
|
|
|
/* |
|
|
|
任务,合并请求 ES名称:issue-es-index |
|
|
|
@@ -599,7 +599,7 @@ 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 { |
|
|
|
result := makeIssueResult(res, Key) |
|
|
|
result := makeIssueResult(res, Key, OnlyReturnNum) |
|
|
|
ctx.JSON(200, result) |
|
|
|
} else { |
|
|
|
log.Info("query es error," + err.Error()) |
|
|
|
|