| @@ -2,6 +2,7 @@ package routers | |||||
| import ( | import ( | ||||
| "code.gitea.io/gitea/modules/context" | "code.gitea.io/gitea/modules/context" | ||||
| "code.gitea.io/gitea/modules/log" | |||||
| "github.com/olivere/elastic/v7" | "github.com/olivere/elastic/v7" | ||||
| ) | ) | ||||
| @@ -44,12 +45,13 @@ func Search(ctx *context.Context) { | |||||
| descriptionQuery := elastic.NewTermQuery("description", Key) | descriptionQuery := elastic.NewTermQuery("description", Key) | ||||
| boolQ.Should(nameQuery, descriptionQuery) | 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).Do(ctx.Req.Context()) | ||||
| if err != nil { | |||||
| if err == nil { | |||||
| ctx.JSON(200, res) | ctx.JSON(200, res) | ||||
| } | } | ||||
| } else { | } else { | ||||
| log.Info("query all content.") | |||||
| res, err := client.Search(TableName + "-es-index").Do(ctx.Req.Context()) | res, err := client.Search(TableName + "-es-index").Do(ctx.Req.Context()) | ||||
| if err != nil { | |||||
| if err == nil { | |||||
| ctx.JSON(200, res) | ctx.JSON(200, res) | ||||
| } | } | ||||
| } | } | ||||