|
@@ -119,11 +119,11 @@ func searchRepo(ctx *context.Context, TableName string, Key string, Page int, Pa |
|
|
log.Info("query searchRepo start") |
|
|
log.Info("query searchRepo start") |
|
|
if Key != "" { |
|
|
if Key != "" { |
|
|
boolQ := elastic.NewBoolQuery() |
|
|
boolQ := elastic.NewBoolQuery() |
|
|
nameQuery := elastic.NewMatchQuery("name", Key).Boost(2).QueryName("f_first") |
|
|
|
|
|
|
|
|
nameQuery := elastic.NewMatchQuery("name", Key).Boost(1024).QueryName("f_first") |
|
|
descriptionQuery := elastic.NewMatchQuery("description", Key).Boost(1.5).QueryName("f_second") |
|
|
descriptionQuery := elastic.NewMatchQuery("description", Key).Boost(1.5).QueryName("f_second") |
|
|
topicsQuery := elastic.NewMatchQuery("topics", Key).Boost(1).QueryName("f_third") |
|
|
topicsQuery := elastic.NewMatchQuery("topics", Key).Boost(1).QueryName("f_third") |
|
|
boolQ.Should(nameQuery, descriptionQuery, topicsQuery) |
|
|
boolQ.Should(nameQuery, descriptionQuery, 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(TableName).Query(boolQ).SortBy(elastic.NewScoreSort(), elastic.NewFieldSort(SortBy).Order(ascending)).From((Page - 1) * PageSize).Size(PageSize).Do(ctx.Req.Context()) |
|
|
if err == nil { |
|
|
if err == nil { |
|
|
result := makeRepoResult(res, Key) |
|
|
result := makeRepoResult(res, Key) |
|
|
ctx.JSON(200, result) |
|
|
ctx.JSON(200, result) |
|
@@ -134,7 +134,7 @@ func searchRepo(ctx *context.Context, TableName string, Key string, Page int, Pa |
|
|
} else { |
|
|
} else { |
|
|
log.Info("query all content.") |
|
|
log.Info("query all content.") |
|
|
//搜索的属性要指定{"timestamp":{"unmapped_type":"date"}} |
|
|
//搜索的属性要指定{"timestamp":{"unmapped_type":"date"}} |
|
|
res, err := client.Search(TableName).Sort(SortBy, ascending).From((Page - 1) * PageSize).Size(PageSize).Do(ctx.Req.Context()) |
|
|
|
|
|
|
|
|
res, err := client.Search(TableName).SortBy(elastic.NewFieldSort(SortBy).Order(ascending)).From((Page - 1) * PageSize).Size(PageSize).Do(ctx.Req.Context()) |
|
|
if err == nil { |
|
|
if err == nil { |
|
|
result := makeRepoResult(res, "") |
|
|
result := makeRepoResult(res, "") |
|
|
ctx.JSON(200, result) |
|
|
ctx.JSON(200, result) |
|
@@ -505,7 +505,7 @@ func searchPR(ctx *context.Context, TableName string, Key string, Page int, Page |
|
|
ascending := ctx.QueryBool("Ascending") |
|
|
ascending := ctx.QueryBool("Ascending") |
|
|
boolQ := elastic.NewBoolQuery() |
|
|
boolQ := elastic.NewBoolQuery() |
|
|
if Key != "" { |
|
|
if Key != "" { |
|
|
nameQuery := elastic.NewMatchQuery("name", Key).Boost(2).QueryName("f_first") |
|
|
|
|
|
|
|
|
nameQuery := elastic.NewMatchQuery("name", Key).Boost(1024).QueryName("f_first") |
|
|
contentQuery := elastic.NewMatchQuery("content", Key).Boost(1.5).QueryName("f_second") |
|
|
contentQuery := elastic.NewMatchQuery("content", Key).Boost(1.5).QueryName("f_second") |
|
|
commentQuery := elastic.NewMatchQuery("comment", Key).Boost(1).QueryName("f_third") |
|
|
commentQuery := elastic.NewMatchQuery("comment", Key).Boost(1).QueryName("f_third") |
|
|
boolQ.Should(nameQuery, contentQuery, commentQuery) |
|
|
boolQ.Should(nameQuery, contentQuery, commentQuery) |
|
|