|
|
@@ -200,6 +200,16 @@ 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() |
|
|
|
} else { |
|
|
|
sort = elastic.NewFieldSort(SortBy).Order(ascending) |
|
|
|
} |
|
|
|
return sort |
|
|
|
} |
|
|
|
|
|
|
|
func getSort(SortBy string, ascending bool, secondSortBy string, secondAscending bool) []elastic.Sorter { |
|
|
|
sort := make([]elastic.Sorter, 0) |
|
|
|
if SortBy == "default" { |
|
|
@@ -694,7 +704,7 @@ func searchUserOrOrg(ctx *context.Context, TableName string, Key string, Page in |
|
|
|
boolQ.Must(UserOrOrgQuery) |
|
|
|
} |
|
|
|
|
|
|
|
res, err := client.Search(TableName).Query(boolQ).SortBy(getSort(SortBy, ascending, "", false)...).From((Page - 1) * PageSize).Size(PageSize).Highlight(queryHighlight("name", "full_name", "description")).Do(ctx.Req.Context()) |
|
|
|
res, err := client.Search(TableName).Query(boolQ).SortBy(getSortSingle(SortBy, ascending)).From((Page - 1) * PageSize).Size(PageSize).Highlight(queryHighlight("name", "full_name", "description")).Do(ctx.Req.Context()) |
|
|
|
if err == nil { |
|
|
|
searchJson, _ := json.Marshal(res) |
|
|
|
log.Info("searchJson=" + string(searchJson)) |
|
|
@@ -852,7 +862,7 @@ func searchDataSet(ctx *context.Context, TableName string, Key string, Page int, |
|
|
|
fileNameQuery := elastic.NewMatchQuery("file_name", Key).Boost(1).QueryName("f_third") |
|
|
|
categoryQuery := elastic.NewMatchQuery("category", Key).Boost(1).QueryName("f_fourth") |
|
|
|
boolQ.Should(nameQuery, descQuery, categoryQuery, fileNameQuery) |
|
|
|
res, err := client.Search(TableName).Query(boolQ).SortBy(getSort(SortBy, ascending, "", false)...).From(from).Size(Size).Highlight(queryHighlight("title", "description", "file_name", "category")).Do(ctx.Req.Context()) |
|
|
|
res, err := client.Search(TableName).Query(boolQ).SortBy(getSortSingle(SortBy, ascending)).From(from).Size(Size).Highlight(queryHighlight("title", "description", "file_name", "category")).Do(ctx.Req.Context()) |
|
|
|
if err == nil { |
|
|
|
searchJson, _ := json.Marshal(res) |
|
|
|
log.Info("searchJson=" + string(searchJson)) |
|
|
@@ -867,7 +877,7 @@ func searchDataSet(ctx *context.Context, TableName string, Key string, Page int, |
|
|
|
} else { |
|
|
|
log.Info("query all datasets.") |
|
|
|
//搜索的属性要指定{"timestamp":{"unmapped_type":"date"}} |
|
|
|
res, err := client.Search(TableName).SortBy(getSort(SortBy, ascending, "", false)...).From(from).Size(Size).Do(ctx.Req.Context()) |
|
|
|
res, err := client.Search(TableName).SortBy(getSortSingle(SortBy, ascending)).From(from).Size(Size).Do(ctx.Req.Context()) |
|
|
|
if err == nil { |
|
|
|
searchJson, _ := json.Marshal(res) |
|
|
|
log.Info("searchJson=" + string(searchJson)) |
|
|
@@ -1060,7 +1070,7 @@ func searchIssueOrPr(ctx *context.Context, TableName string, Key string, Page in |
|
|
|
boolQ.Must(isIssueQuery) |
|
|
|
} |
|
|
|
|
|
|
|
res, err := client.Search(TableName).Query(boolQ).SortBy(getSort(SortBy, ascending, "", false)...).From(from).Size(Size).Highlight(queryHighlight("name", "content", "comment")).Do(ctx.Req.Context()) |
|
|
|
res, err := client.Search(TableName).Query(boolQ).SortBy(getSortSingle(SortBy, ascending)).From(from).Size(Size).Highlight(queryHighlight("name", "content", "comment")).Do(ctx.Req.Context()) |
|
|
|
if err == nil { |
|
|
|
searchJson, _ := json.Marshal(res) |
|
|
|
log.Info("searchJson=" + string(searchJson)) |
|
|
|