rdluck 4 سال پیش
والد
کامیت
fe6fc0dd79
3فایلهای تغییر یافته به همراه51 افزوده شده و 44 حذف شده
  1. 2 0
      services/elastic.go
  2. 43 43
      services/industry_map.go
  3. 6 1
      services/task.go

+ 2 - 0
services/elastic.go

@@ -394,6 +394,8 @@ func EsMultiMatchFunctionScoreQuery(indexName, keyWord string, startSize, pageSi
 		keyWordArr = append(keyWordArr, keyWord)
 		keyWordLen = len(keyWordArr)
 	}
+	fmt.Println(keyWordArr)
+
 	keyWordWeight := GetWeight(keyWordLen)
 	for k, v := range keyWordArr {
 		if v != "" {

+ 43 - 43
services/industry_map.go

@@ -47,7 +47,7 @@ func GetIndustryMap() {
 	MakeTree(allNodes, rootNode)
 }
 
-func GetIndustryTree()(rootNode *models.CygxIndustryMapItems, err error) {
+func GetIndustryTree() (rootNode *models.CygxIndustryMapItems, err error) {
 	//fmt.Println("start")
 	list, err := models.GetCygxIndustryMapByParentId(0)
 	if err != nil {
@@ -315,9 +315,10 @@ func randSlice(slice []*models.CygxIndustryMapItems) {
 }
 
 //获取行业图谱切片(v2版本,调整时间:2021-03-19 18:02:07)
-func GetIndustryMapNameSliceV2(industryName string)(nameSlice []string,err error){
-	tree,err := GetIndustryTree()
-	if err != nil{
+func GetIndustryMapNameSliceV2(industryName string) (nameSlice []string, err error) {
+	nameSlice = append(nameSlice, industryName)
+	tree, err := GetIndustryTree()
+	if err != nil {
 		fmt.Println("获取树失败")
 		return
 	}
@@ -326,20 +327,20 @@ func GetIndustryMapNameSliceV2(industryName string)(nameSlice []string,err error
 
 	//已经存在的行业id的map集合
 	hasIdMap := make(map[int]string)
-	itemList,err := models.GetFirstCygxIndustryListByName(industryName)
-	if err != nil{
-		fmt.Println("获取数据失败,",err)
+	itemList, err := models.GetFirstCygxIndustryListByName(industryName)
+	if err != nil {
+		fmt.Println("获取数据失败,", err)
 		return
 	}
 	//找不到对应的数据
-	if len(itemList) <= 0{
+	if len(itemList) <= 0 {
 		return
 	}
 
 	industryMapList := make(map[int][]*models.CygxIndustryMapItems)
 	//TODO  这里好像有问题,如果传入行业的话,上面再没有是否只是找到第一个节点判断,那么就会异常抛出
-	for _,item := range itemList{
-		industryMapList[item.Level] = append(industryMapList[item.Level],item)
+	for _, item := range itemList {
+		industryMapList[item.Level] = append(industryMapList[item.Level], item)
 	}
 
 	//将查出来的根节点数据的key取出来,放在切片中,并对该切片做正序排列
@@ -349,14 +350,13 @@ func GetIndustryMapNameSliceV2(industryName string)(nameSlice []string,err error
 	}
 	sort.Ints(sortIndustryList)
 
-
 	//最底层节点的数据集合
 	list := industryMapList[sortIndustryList[0]]
 
 	//如果该数据正好是第一层节点数据,那么需要额外判断下
 	if list[0].ParentId <= 2 {
 		//如果存在第二级,那么就使用该层级
-		if len(sortIndustryList) > 1{
+		if len(sortIndustryList) > 1 {
 			list = industryMapList[sortIndustryList[1]]
 		}
 	}
@@ -366,48 +366,48 @@ func GetIndustryMapNameSliceV2(industryName string)(nameSlice []string,err error
 	otherChildMapSlice := map[int][]*models.CygxIndustryMapItems{}
 
 	//多个节点时,额外处理
-	if len(list) > 1{
-		for _,item := range list{
-			hasIdMap[item.IndustryMapId]=""
+	if len(list) > 1 {
+		for _, item := range list {
+			hasIdMap[item.IndustryMapId] = ""
 			//将自己的节点给加进去
-			otherChildMapSlice[0] = append(otherChildMapSlice[0],item)
+			otherChildMapSlice[0] = append(otherChildMapSlice[0], item)
 
 			//获取上级
 			var tmpParentSlice []*models.CygxIndustryMapItems
-			tmpParentSlice,_ = parentTreeToSlice(tree,item,0,tmpParentSlice,hasIdMap)
+			tmpParentSlice, _ = parentTreeToSlice(tree, item, 0, tmpParentSlice, hasIdMap)
 			//父节点
 			parentItem := tmpParentSlice[len(tmpParentSlice)-1]
-			if _,ok := hasIdMap[parentItem.IndustryMapId];ok==false{
+			if _, ok := hasIdMap[parentItem.IndustryMapId]; ok == false {
 				hasIdMap[parentItem.IndustryMapId] = ""
-				otherChildMapSlice[1] = append(otherChildMapSlice[1],parentItem)
+				otherChildMapSlice[1] = append(otherChildMapSlice[1], parentItem)
 			}
 		}
-	}else{
+	} else {
 		//匹配到单个节点
 		item := list[0]
-		hasIdMap[item.IndustryMapId]=""
+		hasIdMap[item.IndustryMapId] = ""
 		//将自己的节点给加进去
-		otherChildMapSlice[0] = append(otherChildMapSlice[0],item)
-		childTree := getChildTree(tree,item)
+		otherChildMapSlice[0] = append(otherChildMapSlice[0], item)
+		childTree := getChildTree(tree, item)
 
 		//如果是命中到最后一层节点
-		if len(childTree.Children) == 0{
+		if len(childTree.Children) == 0 {
 			//获取上级
 			var tmpParentSlice []*models.CygxIndustryMapItems
-			tmpParentSlice,_ = parentTreeToSlice(tree,item,0,tmpParentSlice,hasIdMap)
+			tmpParentSlice, _ = parentTreeToSlice(tree, item, 0, tmpParentSlice, hasIdMap)
 			//父节点
 			parentItem := tmpParentSlice[len(tmpParentSlice)-1]
 
-			if _,ok := hasIdMap[parentItem.IndustryMapId];ok==false{
+			if _, ok := hasIdMap[parentItem.IndustryMapId]; ok == false {
 				hasIdMap[parentItem.IndustryMapId] = ""
-				otherChildMapSlice[1] = append(otherChildMapSlice[1],parentItem)
+				otherChildMapSlice[1] = append(otherChildMapSlice[1], parentItem)
 			}
 
 			//兄弟节点
-			siblingTreeToSliceV2(parentItem,item,hasIdMap,2,otherChildMapSlice)
-		}else{
+			siblingTreeToSliceV2(parentItem, item, hasIdMap, 2, otherChildMapSlice)
+		} else {
 			//如果不是命中到最后一层节点
-			otherChildMapSlice[1] = append(otherChildMapSlice[1],childTree.Children...)
+			otherChildMapSlice[1] = append(otherChildMapSlice[1], childTree.Children...)
 		}
 	}
 
@@ -422,19 +422,19 @@ func GetIndustryMapNameSliceV2(industryName string)(nameSlice []string,err error
 	sort.Ints(sortList)
 
 	//遍历该切片,根据下标key获取对应的数据,并插入到主数据中
-	for _,v := range sortList{
+	for _, v := range sortList {
 		tmpChildSlice := otherChildMapSlice[v]
 		randSlice(tmpChildSlice)
-		tmpSlice = append(tmpSlice,tmpChildSlice...)
+		tmpSlice = append(tmpSlice, tmpChildSlice...)
 		//fmt.Println(k,"=====")
 		//for _,tmpV := range otherChildMapSlice[v]{
 		//	fmt.Println(tmpV.IndustryMapName)
 		//}
 	}
 	//名字切片
-	for _,v := range tmpSlice{
+	for _, v := range tmpSlice {
 		//fmt.Println("k===",k,"=======v=======",v)
-		nameSlice = append(nameSlice,v.IndustryMapName)
+		nameSlice = append(nameSlice, v.IndustryMapName)
 	}
 
 	//fmt.Println(nameSlice)
@@ -444,21 +444,21 @@ func GetIndustryMapNameSliceV2(industryName string)(nameSlice []string,err error
 }
 
 //获取兄弟级树
-func siblingTreeToSliceV2(rootNode *models.CygxIndustryMapItems,nowNode *models.CygxIndustryMapItems,hasIdMap map[int]string,depth int,otherChildMapSlice map[int][]*models.CygxIndustryMapItems)(maxDepth int)  {
-	if rootNode.Children != nil{
+func siblingTreeToSliceV2(rootNode *models.CygxIndustryMapItems, nowNode *models.CygxIndustryMapItems, hasIdMap map[int]string, depth int, otherChildMapSlice map[int][]*models.CygxIndustryMapItems) (maxDepth int) {
+	if rootNode.Children != nil {
 		depth++
 		maxDepth = depth
-		for _,v := range rootNode.Children {
+		for _, v := range rootNode.Children {
 			//如果父级id一致的情况下,那么代表这是兄弟节点或者是自己了
-			if v.ParentId == nowNode.ParentId{
+			if v.ParentId == nowNode.ParentId {
 				//判断是否已经录入,如果已经录入,那么不处理
-				if _,ok := hasIdMap[v.IndustryMapId];ok==false{
-					otherChildMapSlice[depth] = append(otherChildMapSlice[depth],v)
+				if _, ok := hasIdMap[v.IndustryMapId]; ok == false {
+					otherChildMapSlice[depth] = append(otherChildMapSlice[depth], v)
 					hasIdMap[v.IndustryMapId] = ""
 				}
-			}else{
-				returnDepth := siblingTreeToSliceV2(v,nowNode,hasIdMap,depth,otherChildMapSlice)
-				if returnDepth > maxDepth{
+			} else {
+				returnDepth := siblingTreeToSliceV2(v, nowNode, hasIdMap, depth, otherChildMapSlice)
+				if returnDepth > maxDepth {
 					maxDepth = returnDepth
 				}
 			}

+ 6 - 1
services/task.go

@@ -3,6 +3,7 @@ package services
 import (
 	"fmt"
 	"github.com/astaxie/beego/toolbox"
+
 	//"github.com/astaxie/beego/cache"
 )
 
@@ -11,6 +12,11 @@ func Task() {
 	//同步数据
 	syncTacticsList := toolbox.NewTask("syncTacticsList", "0 */5 * * * *", SyncTacticsList)
 	toolbox.AddTask("syncTacticsList", syncTacticsList)
+	toolbox.StartTask()
+	fmt.Println("end")
+}
+
+func ElasticOption() {
 	//SyncTacticsList()
 	//toolbox.StartTask()
 	//keyWord := "专家"
@@ -153,7 +159,6 @@ func Task() {
 
 	//indexName := "article_list"
 	//EsDeleteData(indexName,)
-	fmt.Println("end")
 }
 
 type ElasticArticleDetail struct {