|
|
|
@@ -44,6 +44,7 @@ func SearchApi(ctx *context.Context) { |
|
|
|
Page := ctx.QueryInt("Page") |
|
|
|
PageSize := ctx.QueryInt("PageSize") |
|
|
|
OnlyReturnNum := ctx.QueryBool("OnlyReturnNum") |
|
|
|
OnlySearchLabel := ctx.QueryBool("OnlySearchLabel") |
|
|
|
if Page <= 0 { |
|
|
|
Page = 1 |
|
|
|
} |
|
|
|
@@ -52,7 +53,11 @@ func SearchApi(ctx *context.Context) { |
|
|
|
} |
|
|
|
|
|
|
|
if TableName == "repository" { |
|
|
|
searchRepo(ctx, "repository-es-index", Key, Page, PageSize, OnlyReturnNum) |
|
|
|
if OnlySearchLabel { |
|
|
|
searchRepoByLabel(ctx, Key, Page, PageSize) |
|
|
|
} else { |
|
|
|
searchRepo(ctx, "repository-es-index", Key, Page, PageSize, OnlyReturnNum) |
|
|
|
} |
|
|
|
return |
|
|
|
} else if TableName == "issue" { |
|
|
|
searchIssue(ctx, "issue-es-index", Key, Page, PageSize, OnlyReturnNum) |
|
|
|
@@ -72,7 +77,7 @@ func SearchApi(ctx *context.Context) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func searchRepoByLabel(ctx *context.Context, TableName string, Key string, Page int, PageSize int, OnlyReturnNum bool) { |
|
|
|
func searchRepoByLabel(ctx *context.Context, Key string, Page int, PageSize int) { |
|
|
|
/* |
|
|
|
项目, ES名称: repository-es-index |
|
|
|
搜索: |
|
|
|
@@ -95,13 +100,16 @@ func searchRepoByLabel(ctx *context.Context, TableName string, Key string, Page |
|
|
|
boolQ := elastic.NewBoolQuery() |
|
|
|
topicsQuery := elastic.NewMatchQuery("topics", Key) |
|
|
|
boolQ.Should(topicsQuery) |
|
|
|
res, err := client.Search(TableName).Query(boolQ).Sort(SortBy, ascending).From((Page - 1) * PageSize).Size(PageSize).Do(ctx.Req.Context()) |
|
|
|
|
|
|
|
res, err := client.Search("repository-es-index").Query(boolQ).SortBy(elastic.NewScoreSort(), elastic.NewFieldSort(SortBy).Order(ascending)).From((Page - 1) * PageSize).Size(PageSize).Highlight(queryHighlight("topics")).Do(ctx.Req.Context()) |
|
|
|
if err == nil { |
|
|
|
result := makeRepoResult(res, "", OnlyReturnNum) |
|
|
|
searchJson, _ := json.Marshal(res) |
|
|
|
log.Info("searchJson=" + string(searchJson)) |
|
|
|
result := makeRepoResult(res, "", false) |
|
|
|
ctx.JSON(200, result) |
|
|
|
return |
|
|
|
} else { |
|
|
|
log.Info("query es error," + err.Error()) |
|
|
|
ctx.JSON(200, "") |
|
|
|
} |
|
|
|
} |
|
|
|
ctx.JSON(200, "") |
|
|
|
@@ -182,6 +190,9 @@ func makeRepoResult(sRes *elastic.SearchResult, Key string, OnlyReturnNum bool) |
|
|
|
} else { |
|
|
|
record["description"] = "" |
|
|
|
} |
|
|
|
if Key == "" { |
|
|
|
record["hightTopics"] = getLabelValue("topics", recordSource, hit.Highlight) |
|
|
|
} |
|
|
|
|
|
|
|
record["num_watches"] = recordSource["num_watches"] |
|
|
|
record["num_stars"] = recordSource["num_stars"] |
|
|
|
|