From 61dc241387ca28910009188e95f21544a7ebfc66 Mon Sep 17 00:00:00 2001 From: zouap Date: Mon, 27 Dec 2021 09:46:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E6=90=9C=E7=B4=A2=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- routers/search.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/routers/search.go b/routers/search.go index 117c6503e..fbe6f701e 100644 --- a/routers/search.go +++ b/routers/search.go @@ -41,16 +41,16 @@ func Search(ctx *context.Context) { } if Key != "" { boolQ := elastic.NewBoolQuery() - nameQuery := elastic.NewTermQuery("name", Key) - descriptionQuery := elastic.NewTermQuery("description", Key) + nameQuery := elastic.NewMatchQuery("name", Key).Boost(2) + descriptionQuery := elastic.NewMatchQuery("description", Key).Boost(1) boolQ.Should(nameQuery, descriptionQuery) - res, err := client.Search(TableName + "-es-index").Query(boolQ).Do(ctx.Req.Context()) + res, err := client.Search(TableName+"-es-index").Query(boolQ).Sort("updated_unix", false).Do(ctx.Req.Context()) if err == nil { ctx.JSON(200, res) } } else { log.Info("query all content.") - res, err := client.Search(TableName + "-es-index").Do(ctx.Req.Context()) + res, err := client.Search(TableName+"-es-index").Sort("updated_unix", false).Do(ctx.Req.Context()) if err == nil { ctx.JSON(200, res) }