Browse Source

提交代码。

Signed-off-by: zouap <zouap@pcl.ac.cn>
tags/v1.22.3.2^2
zouap 4 years ago
parent
commit
cfd309de2e
2 changed files with 21 additions and 6 deletions
  1. +1
    -0
      routers/routes/routes.go
  2. +20
    -6
      routers/search.go

+ 1
- 0
routers/routes/routes.go View File

@@ -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")


+ 20
- 6
routers/search.go View File

@@ -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)
}

Loading…
Cancel
Save