diff --git a/routers/search.go b/routers/search.go index f2a2f30d6..5dd8a9b7e 100644 --- a/routers/search.go +++ b/routers/search.go @@ -202,17 +202,21 @@ func searchRepoByLabel(ctx *context.Context, Key string, Page int, PageSize int) func getSortSingle(SortBy string, ascending bool) elastic.Sorter { var sort elastic.Sorter - if SortBy == "default" { - sort = elastic.NewScoreSort() + if SortBy != "" { + if SortBy == "default" { + sort = elastic.NewScoreSort() + } else { + sort = elastic.NewFieldSort(SortBy).Order(ascending) + } } else { - sort = elastic.NewFieldSort(SortBy).Order(ascending) + sort = elastic.NewScoreSort() } return sort } func getSort(SortBy string, ascending bool, secondSortBy string, secondAscending bool) []elastic.Sorter { sort := make([]elastic.Sorter, 0) - if SortBy == "default" { + if SortBy == "default" || SortBy == "" { sort = append(sort, elastic.NewScoreSort()) if secondSortBy != "" { log.Info("SortBy=" + SortBy + " secondSortBy=" + secondSortBy)