|
@@ -123,8 +123,10 @@ func searchRepo(ctx *context.Context, TableName string, Key string, Page int, Pa |
|
|
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).SortBy(elastic.NewScoreSort(), elastic.NewFieldSort(SortBy).Order(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).Highlight(queryHighlight("name", "description", "topics")).Do(ctx.Req.Context()) |
|
|
if err == nil { |
|
|
if err == nil { |
|
|
|
|
|
searchJson, _ := json.Marshal(res) |
|
|
|
|
|
log.Info("searchJson=" + string(searchJson)) |
|
|
result := makeRepoResult(res, Key) |
|
|
result := makeRepoResult(res, Key) |
|
|
ctx.JSON(200, result) |
|
|
ctx.JSON(200, result) |
|
|
} else { |
|
|
} else { |
|
@@ -134,7 +136,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).SortBy(elastic.NewFieldSort(SortBy).Order(ascending)).From((Page - 1) * PageSize).Size(PageSize).Highlight(queryHighlight("name", "description", "topics")).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 { |
|
|
searchJson, _ := json.Marshal(res) |
|
|
searchJson, _ := json.Marshal(res) |
|
|
log.Info("searchJson=" + string(searchJson)) |
|
|
log.Info("searchJson=" + string(searchJson)) |
|
|