|
|
@@ -313,9 +313,8 @@ func searchRepo(ctx *context.Context, TableName string, Key string, Page int, Pa |
|
|
|
|
|
|
|
res, err := client.Search(TableName).Query(boolQ).SortBy(getSort(SortBy, ascending, "num_stars", false)...).From(from).Size(Size).Highlight(queryHighlight("alias", "description", "topics")).Do(ctx.Req.Context()) |
|
|
|
if err == nil { |
|
|
|
searchJson, _ := json.Marshal(res) |
|
|
|
log.Info("searchJson=" + string(searchJson)) |
|
|
|
esresult := makeRepoResult(res, Key, OnlyReturnNum, language) |
|
|
|
setForkRepoOrder(esresult) |
|
|
|
resultObj.Total = resultObj.PrivateTotal + esresult.Total |
|
|
|
isNeedSort := false |
|
|
|
if len(resultObj.Result) > 0 { |
|
|
@@ -348,6 +347,30 @@ func searchRepo(ctx *context.Context, TableName string, Key string, Page int, Pa |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func setForkRepoOrder(esresult *SearchRes) { |
|
|
|
forkidMap := make(map[string]int, 0) |
|
|
|
for index, re := range esresult.Result { |
|
|
|
if re["fork_id"] != nil { |
|
|
|
fork_id := re["fork_id"].(string) |
|
|
|
if _, ok := forkidMap[fork_id]; !ok { |
|
|
|
forkidMap[fork_id] = index |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
for key, value := range forkidMap { |
|
|
|
for index, re := range esresult.Result { |
|
|
|
if re["id"].(string) == key { |
|
|
|
if value < index { //swap |
|
|
|
tmp := esresult.Result[index] |
|
|
|
esresult.Result[index] = esresult.Result[value] |
|
|
|
esresult.Result[value] = tmp |
|
|
|
break |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func sortRepo(Result []map[string]interface{}, SortBy string, ascending bool) { |
|
|
|
orderBy := "" |
|
|
|
switch SortBy { |
|
|
@@ -479,6 +502,7 @@ func makeRepoResult(sRes *elastic.SearchResult, Key string, OnlyReturnNum bool, |
|
|
|
record["num_stars"] = recordSource["num_stars"] |
|
|
|
record["num_forks"] = recordSource["num_forks"] |
|
|
|
record["lower_alias"] = recordSource["lower_alias"] |
|
|
|
record["fork_id"] = recordSource["fork_id"] |
|
|
|
if recordSource["topics"] != nil { |
|
|
|
topicsStr := recordSource["topics"].(string) |
|
|
|
log.Info("topicsStr=" + topicsStr) |
|
|
|