|
|
|
@@ -175,10 +175,10 @@ func makeRepoResult(sRes *elastic.SearchResult, Key string) *SearchRes { |
|
|
|
record["lang"] = recordSource["lang"] |
|
|
|
result = append(result, record) |
|
|
|
} else { |
|
|
|
log.Info("deal source error," + err.Error()) |
|
|
|
log.Info("deal repo source error," + err.Error()) |
|
|
|
} |
|
|
|
} else { |
|
|
|
log.Info("deal source error," + err.Error()) |
|
|
|
log.Info("deal repo source error," + err.Error()) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@@ -299,10 +299,10 @@ func makeUserOrOrgResult(sRes *elastic.SearchResult, Key string, ctx *context.Co |
|
|
|
record["created_unix"] = recordSource["created_unix"] |
|
|
|
result = append(result, record) |
|
|
|
} else { |
|
|
|
log.Info("deal source error," + err.Error()) |
|
|
|
log.Info("deal user source error," + err.Error()) |
|
|
|
} |
|
|
|
} else { |
|
|
|
log.Info("deal source error," + err.Error()) |
|
|
|
log.Info("deal user source error," + err.Error()) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@@ -326,6 +326,82 @@ func searchDataSet(ctx *context.Context, TableName string, Key string, Page int, |
|
|
|
download_times |
|
|
|
|
|
|
|
*/ |
|
|
|
SortBy := ctx.Query("SortBy") |
|
|
|
if SortBy == "" { |
|
|
|
SortBy = "download_times.keyword" |
|
|
|
} |
|
|
|
ascending := ctx.QueryBool("Ascending") |
|
|
|
log.Info("query searchRepo start") |
|
|
|
boolQ := elastic.NewBoolQuery() |
|
|
|
if Key != "" { |
|
|
|
nameQuery := elastic.NewMatchQuery("title", Key).Boost(2).QueryName("f_first") |
|
|
|
descQuery := elastic.NewMatchQuery("description", Key).Boost(1.5).QueryName("f_second") |
|
|
|
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).Sort(SortBy, ascending).From((Page - 1) * PageSize).Size(PageSize).Do(ctx.Req.Context()) |
|
|
|
if err == nil { |
|
|
|
result := makeDatasetResult(res, Key) |
|
|
|
ctx.JSON(200, result) |
|
|
|
} else { |
|
|
|
log.Info("query es error," + err.Error()) |
|
|
|
} |
|
|
|
} else { |
|
|
|
log.Info("query all content.") |
|
|
|
//搜索的属性要指定{"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, "") |
|
|
|
ctx.JSON(200, result) |
|
|
|
} else { |
|
|
|
log.Info("query es error," + err.Error()) |
|
|
|
ctx.JSON(200, "") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
func makeDatasetResult(sRes *elastic.SearchResult, Key string) *SearchRes { |
|
|
|
total := sRes.Hits.TotalHits.Value |
|
|
|
result := make([]map[string]interface{}, 0) |
|
|
|
|
|
|
|
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"] = recordSource["id"] |
|
|
|
userId := recordSource["user_id"].(int64) |
|
|
|
user, errUser := models.GetUserByID(userId) |
|
|
|
if errUser == nil { |
|
|
|
record["owerName"] = user.GetDisplayName() |
|
|
|
record["avatar"] = user.RelAvatarLink() |
|
|
|
} |
|
|
|
record["title"] = recordSource["title"] |
|
|
|
record["category"] = recordSource["category"] |
|
|
|
desc := recordSource["description"].(string) |
|
|
|
record["description"] = dealLongText(desc, Key, hit.MatchedQueries) |
|
|
|
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, |
|
|
|
} |
|
|
|
|
|
|
|
return returnObj |
|
|
|
} |
|
|
|
|
|
|
|
func searchIssue(ctx *context.Context, TableName string, Key string, Page int, PageSize int) { |
|
|
|
@@ -339,7 +415,11 @@ func searchIssue(ctx *context.Context, TableName string, Key string, Page int, P |
|
|
|
排序: |
|
|
|
updated_unix |
|
|
|
*/ |
|
|
|
|
|
|
|
SortBy := ctx.Query("SortBy") |
|
|
|
if SortBy == "" { |
|
|
|
SortBy = "updated_unix.keyword" |
|
|
|
} |
|
|
|
ascending := ctx.QueryBool("Ascending") |
|
|
|
boolQ := elastic.NewBoolQuery() |
|
|
|
if Key != "" { |
|
|
|
nameQuery := elastic.NewMatchQuery("name", Key).Boost(2).QueryName("f_first") |
|
|
|
@@ -349,7 +429,7 @@ func searchIssue(ctx *context.Context, TableName string, Key string, Page int, P |
|
|
|
} |
|
|
|
isIssueQuery := elastic.NewTermQuery("is_pull", false) |
|
|
|
boolQ.Must(isIssueQuery) |
|
|
|
res, err := client.Search(TableName).Query(boolQ).Sort("updated_unix.keyword", false).From((Page - 1) * PageSize).Size(PageSize).Do(ctx.Req.Context()) |
|
|
|
res, err := client.Search(TableName).Query(boolQ).Sort(SortBy, ascending).From((Page - 1) * PageSize).Size(PageSize).Do(ctx.Req.Context()) |
|
|
|
if err == nil { |
|
|
|
result := makeIssueResult(res, Key) |
|
|
|
ctx.JSON(200, result) |
|
|
|
@@ -377,6 +457,7 @@ func makeIssueResult(sRes *elastic.SearchResult, Key string) *SearchRes { |
|
|
|
repo, errRepo := models.GetRepositoryByID(recordSource["repo_id"].(int64)) |
|
|
|
if errRepo == nil { |
|
|
|
record["repoUrl"] = repo.FullName() |
|
|
|
record["avatar"] = repo.RelAvatarLink() |
|
|
|
} |
|
|
|
record["name"] = recordSource["name"] |
|
|
|
desc := recordSource["content"].(string) |
|
|
|
@@ -391,10 +472,10 @@ func makeIssueResult(sRes *elastic.SearchResult, Key string) *SearchRes { |
|
|
|
record["updated_unix"] = recordSource["updated_unix"] |
|
|
|
result = append(result, record) |
|
|
|
} else { |
|
|
|
log.Info("deal source error," + err.Error()) |
|
|
|
log.Info("deal issue source error," + err.Error()) |
|
|
|
} |
|
|
|
} else { |
|
|
|
log.Info("deal source error," + err.Error()) |
|
|
|
log.Info("deal issue source error," + err.Error()) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@@ -417,7 +498,11 @@ func searchPR(ctx *context.Context, TableName string, Key string, Page int, Page |
|
|
|
排序: |
|
|
|
updated_unix |
|
|
|
*/ |
|
|
|
|
|
|
|
SortBy := ctx.Query("SortBy") |
|
|
|
if SortBy == "" { |
|
|
|
SortBy = "updated_unix.keyword" |
|
|
|
} |
|
|
|
ascending := ctx.QueryBool("Ascending") |
|
|
|
boolQ := elastic.NewBoolQuery() |
|
|
|
if Key != "" { |
|
|
|
nameQuery := elastic.NewMatchQuery("name", Key).Boost(2).QueryName("f_first") |
|
|
|
@@ -427,7 +512,7 @@ func searchPR(ctx *context.Context, TableName string, Key string, Page int, Page |
|
|
|
} |
|
|
|
isIssueQuery := elastic.NewTermQuery("is_pull", true) |
|
|
|
boolQ.Must(isIssueQuery) |
|
|
|
res, err := client.Search(TableName).Query(boolQ).Sort("updated_unix.keyword", false).From((Page - 1) * PageSize).Size(PageSize).Do(ctx.Req.Context()) |
|
|
|
res, err := client.Search(TableName).Query(boolQ).Sort(SortBy, ascending).From((Page - 1) * PageSize).Size(PageSize).Do(ctx.Req.Context()) |
|
|
|
if err == nil { |
|
|
|
result := makeIssueResult(res, Key) |
|
|
|
ctx.JSON(200, result) |
|
|
|
|