Ver Fonte

wip:新增免费用户es配置

fuwencai há 1 ano atrás
pai
commit
b28b52730c

+ 5 - 5
jyBXCore/entity/db.go

@@ -6,7 +6,6 @@ type Mongo struct {
 	Bidding *MongoStruct `json:"bidding,optional"`
 }
 
-//
 type MongoStruct struct {
 	Address        string `json:"address"`
 	Size           int    `json:"size"`
@@ -19,13 +18,12 @@ type MongoStruct struct {
 	MaxIdleConns   int    `json:"maxIdleConns,optional"`
 }
 
-//
 type Mysql struct {
 	Main *MysqlStruct `json:"main"`
 	Base *MysqlStruct `json:"base"`
 }
 
-//mysql
+// mysql
 type MysqlStruct struct {
 	DbName       string `json:"dbName"`
 	Address      string `json:"address"`
@@ -35,16 +33,18 @@ type MysqlStruct struct {
 	MaxIdleConns int    `json:"maxIdleConns"`
 }
 
-//redis
+// redis
 type RedisStuct struct {
 	Addr []string `json:"addr"`
 }
 
-//es
+// es
 type EsStruct struct {
 	Addr     string `json:"addr"`
 	Size     int    `json:"size"`
 	Version  string `json:"version"`
 	UserName string `json:"userName"`
 	Password string `json:"password"`
+	Type     string `json:"type,optional"`
+	Index    string `json:"index,optional"`
 }

+ 9 - 1
jyBXCore/rpc/etc/db.yaml

@@ -41,4 +41,12 @@ esNoLogin:
     size: 50
     version: v7
     userName: ""
-    password: ""
+    password: ""
+esFree:
+    addr: http://192.168.3.241:9205,http://192.168.3.149:9200
+    size: 50
+    version: v7
+    userName: ""
+    password: ""
+    index: bidding
+    type: bidding"

+ 13 - 0
jyBXCore/rpc/init/db.go

@@ -20,6 +20,7 @@ var (
 	Mgo        mongodb.MongodbSim
 	MgoBidding mongodb.MongodbSim //标讯详情等(第一版没用)
 	NoLoginEs  Es
+	FreeEs     Es
 )
 
 func MongoDBInit(em *entity.Mongo) {
@@ -103,3 +104,15 @@ func NoLoginEsInit(es *entity.EsStruct) {
 		NoLoginEs.Init()
 	}
 }
+func EsFreeInit(es *entity.EsStruct) {
+	if es.Addr != "" {
+		log.Println("--初始化 FreeEs  elasticsearch--")
+		FreeEs = &EsV7{
+			Address:  es.Addr,
+			Size:     es.Size,
+			UserName: es.UserName,
+			Password: es.Password,
+		}
+		FreeEs.Init()
+	}
+}

+ 1 - 0
jyBXCore/rpc/init/init.go

@@ -70,6 +70,7 @@ func init() {
 	//初始es
 	EsInit(&DB.Es)
 	NoLoginEsInit(&DB.EsNoLogin)
+	EsFreeInit(&DB.EsFree)
 	Search_Thread = make(chan bool, C.SearchConcurrency)
 	NoLoginPoolInit(C.NoLoginSearch.Switch, C.NoLoginSearch.ExecutionNum, C.NoLoginSearch.Wait)
 	//初始化标签

+ 1 - 0
jyBXCore/rpc/internal/config/config.go

@@ -68,4 +68,5 @@ type Db struct {
 	Es        entity.EsStruct   `json:"es"`
 	Mongo     entity.Mongo      `json:"mongo"`
 	EsNoLogin entity.EsStruct   `json:"esNoLogin"`
+	EsFree    entity.EsStruct   `json:"esFree"`
 }

+ 13 - 5
jyBXCore/rpc/model/es/es.go

@@ -33,8 +33,11 @@ const (
 	BidSearchFieldFile      = `,"isValidFile"`                                                                                                                                                                           //根据配置开关 选择是否显示 是否有附件提示,IC.C.FileSignBool
 	BidSearchDomainField    = BidSearchFieldOfVip + `,"purchasing"`                                                                                                                                                      //领域数据字段基本字段
 	//DefaultFields       = `"title"`
-	IndexProjectSet = "projectset" // 项目信息es index
-	TypeProjectSet  = "projectset" // 项目信息es type                                                                                                                                                                                                  //最新招标信息
+	IndexProjectSet  = "projectset" // 项目信息es index
+	TypeProjectSet   = "projectset" // 项目信息es type                                                                                                                                                                                                  //最新招标信息
+	LoginTypePay     = 1            // 付费用户
+	LoginTypeFree    = 2            // 免费用户
+	LoginTypeNoLogin = 3            // 未登录用户
 )
 
 var (
@@ -64,7 +67,7 @@ type SearchByES struct {
 }
 
 // GetAllByNgramWithCount  获取es查询结果及总数量
-func (e *SearchByES) GetAllByNgramWithCount(isLogin bool) (int64, *[]map[string]interface{}) {
+func (e *SearchByES) GetAllByNgramWithCount(loginType int) (int64, *[]map[string]interface{}) {
 	if e.Query != "" {
 		queryStr := e.Query
 		if e.HighLight {
@@ -84,9 +87,14 @@ func (e *SearchByES) GetAllByNgramWithCount(isLogin bool) (int64, *[]map[string]
 			queryStr = queryStr[:len(queryStr)-1] + `,"from":` + strconv.Itoa(e.Start) + `,"size":` + strconv.Itoa(e.Limit) + "}"
 		}
 		log.Println("queryStr:", queryStr)
-		if isLogin {
+		switch loginType {
+		case LoginTypePay:
 			return elastic.GetWithCount(e.Index, e.IType, e.Query, queryStr)
-		} else {
+		case LoginTypeFree:
+			// 免费用户 todo
+			return IC.FreeEs.GetWithCount(e.Index, e.IType, e.Query, queryStr)
+		default:
+			// 未登录
 			return IC.NoLoginEs.GetWithCount(e.Index, e.IType, e.Query, queryStr)
 		}
 	} else {

+ 13 - 2
jyBXCore/rpc/service/search.go

@@ -54,9 +54,20 @@ func GetBidSearchData(in *bxcore.SearchReq, isCache bool) (count int64, list []*
 			Count:      MC.If(strings.Contains(in.SelectType, "detail"), 115, 0).(int),       //高亮正文数量
 			HighLight:  MC.If(strings.Contains(in.SelectType, "detail"), true, false).(bool), //是否高亮正文
 		}
+		var loginType int
+		// 处理免费用户index
+		if in.UserId == "" {
+			loginType = es.LoginTypeNoLogin
+		} else if !in.IsPay {
+			biddingSearch.Index = IC.DB.EsFree.Index
+			biddingSearch.IType = IC.DB.EsFree.Type
+			loginType = es.LoginTypeFree
+		} else {
+			loginType = es.LoginTypePay
+		}
 		var repl *[]map[string]interface{}
 		if in.UserId != "" {
-			count, repl = biddingSearch.GetAllByNgramWithCount(true)
+			count, repl = biddingSearch.GetAllByNgramWithCount(loginType)
 		} else {
 			if IC.C.NoLoginSearch.Switch {
 				if flag := IC.ReqLimitInit.Limit(context.Background()); flag == 1 {
@@ -70,7 +81,7 @@ func GetBidSearchData(in *bxcore.SearchReq, isCache bool) (count int64, list []*
 					return 0, nil
 				}
 			}
-			count, repl = biddingSearch.GetAllByNgramWithCount(false)
+			count, repl = biddingSearch.GetAllByNgramWithCount(loginType)
 		}
 		if repl != nil && *repl != nil && len(*repl) > 0 {
 			//格式化查询结果