From cfd309de2e254b3008def53c389d2067bdd75701 Mon Sep 17 00:00:00 2001 From: zouap Date: Fri, 24 Dec 2021 10:44:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- routers/routes/routes.go | 1 + routers/search.go | 26 ++++++++++++++++++++------ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/routers/routes/routes.go b/routers/routes/routes.go index 221950949..4776f9758 100755 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -319,6 +319,7 @@ func RegisterRoutes(m *macaron.Macaron) { m.Get("/action/notification", routers.ActionNotification) m.Get("/recommend/org", routers.RecommendOrgFromPromote) m.Get("/recommend/repo", routers.RecommendRepoFromPromote) + m.Get("/all/search/", routers.Search) m.Group("/explore", func() { m.Get("", func(ctx *context.Context) { ctx.Redirect(setting.AppSubURL + "/explore/repos") diff --git a/routers/search.go b/routers/search.go index 37665c961..60d7be80e 100644 --- a/routers/search.go +++ b/routers/search.go @@ -2,6 +2,7 @@ package routers import ( "code.gitea.io/gitea/modules/context" + "github.com/olivere/elastic" ) type Table struct { @@ -18,13 +19,26 @@ type SearchOptions struct { SearchObj []Table } +var client *elastic.Client + +var host = "http://192.168.207.94:9200" + func Search(ctx *context.Context) { - // TableName := ctx.Query("TableName") - // Key := ctx.Query("Key") - // SortBy := ctx.Query("SortBy") - // Page := ctx.QueryInt64("Page") - // PageSize := ctx.QueryInt64("PageSize") + TableName := ctx.Query("TableName") + //Key := ctx.Query("Key") + //SortBy := ctx.Query("SortBy") + //Page := ctx.QueryInt64("Page") + //PageSize := ctx.QueryInt64("PageSize") + + //ESSearchUrl := setting.RecommentRepoAddr - // ESSearchUrl := setting.RecommentRepoAddr + var err error + //这个地方有个小坑 不加上elastic.SetSniff(false) 会连接不上 + client, err = elastic.NewClient(elastic.SetSniff(false), elastic.SetURL(host)) + if err != nil { + panic(err) + } + res, err := client.Search(TableName + "-es-index").Do(ctx) + ctx.JSON(200, res) }