Browse Source

Merge branch 'feature/v4.7.21' into master

lianbingjie 3 years ago
parent
commit
dc45b2f1b1

+ 25 - 26
src/jfw/front/applysub.go

@@ -8,7 +8,6 @@ import (
 	"log"
 	"net/url"
 	"qfw/util"
-	"qfw/util/elastic"
 	"qfw/util/jy"
 	"qfw/util/redis"
 	"regexp"
@@ -26,7 +25,7 @@ type Applysub struct {
 	sendMsg       xweb.Mapper `xweb:"/front/applysub/sendMsg"`       //发送验证码
 	checkCode     xweb.Mapper `xweb:"/front/applysub/checkCode"`     //查询手机号是否已使用
 	subInfo       xweb.Mapper `xweb:"/front/applysub/subInfo"`       //查询手机号是否已使用
-	recList       xweb.Mapper `xweb:"/front/entsesearch/recList"`    //获取推荐企业列表
+	//recList       xweb.Mapper `xweb:"/front/entsesearch/recList"`    //获取推荐企业列表
 }
 
 func init() {
@@ -165,30 +164,30 @@ func (a *Applysub) CheckPhoneNum() error {
 }
 
 //
-func (e *Applysub) RecList() {
-	defer util.Catch()
-	//re := []map[string]interface{}{}
-	var entName = e.GetString("entName")
-	limit := 10
-	query := `{"query": {
-			    "bool": {
-			      "must_not":[],
-			      "should": [{
-			          "bool": {"must": [{"multi_match": {"query": "` + entName + `", "type": "phrase","fields": ["entname"], "analyzer": "my_ngram"}}]}
-			        }],
-				  "minimum_should_match": 1
-			    }
-			  },
-			  "_source": ["entname"],
-			  "from": 0,"size": ` + fmt.Sprint(limit) + `
-			}`
-	list := *elastic.Get("entname", "entname", query)
-	if list != nil && len(list) != 0 {
-		e.ServeJson(map[string]interface{}{
-			"recList": list,
-		})
-	}
-}
+//func (e *Applysub) RecList() {
+//	defer util.Catch()
+//	//re := []map[string]interface{}{}
+//	var entName = e.GetString("entName")
+//	limit := 10
+//	query := `{"query": {
+//			    "bool": {
+//			      "must_not":[],
+//			      "should": [{
+//			          "bool": {"must": [{"multi_match": {"query": "` + entName + `", "type": "phrase","fields": ["entname"], "analyzer": "my_ngram"}}]}
+//			        }],
+//				  "minimum_should_match": 1
+//			    }
+//			  },
+//			  "_source": ["entname"],
+//			  "from": 0,"size": ` + fmt.Sprint(limit) + `
+//			}`
+//	list := *elastic.Get("entname", "entname", query)
+//	if list != nil && len(list) != 0 {
+//		e.ServeJson(map[string]interface{}{
+//			"recList": list,
+//		})
+//	}
+//}
 
 //
 func (a *Applysub) Index() error {

+ 4 - 3
src/jfw/front/message.go

@@ -3,8 +3,8 @@ package front
 import (
 	"encoding/json"
 	"html/template"
+	"jfw/public"
 	"qfw/util"
-	"qfw/util/elastic"
 	"qfw/util/redis"
 
 	"github.com/go-xweb/xweb"
@@ -28,8 +28,9 @@ func (m *Message) MesContent(_id string) error {
 		m.T["data"] = retlist
 	} else {
 		id := se.DecodeString(_id)
-		r := elastic.GetByIdField("content", "content", id, `"s_title","l_createdate","releasetime","s_content","s_source"`)
-		if r != nil {
+		//r := elastic.GetByIdField("content", "content", id, `"s_title","l_createdate","releasetime","s_content","s_source"`)
+		r, _ := public.MQFW.FindById("content", id, `{"s_title":1,"s_content":1,"releasetime":1,"s_source":1,"l_createdate":1}`)
+		if r != nil && len(*r) > 0 {
 			tmpdate1 := util.Int64All((*r)["l_createdate"])
 			(*r)["l_createdate"] = util.FormatDateByInt64(&tmpdate1, util.Date_Short_Layout)
 			tmpdate2 := util.Int64All((*r)["releasetime"])

+ 58 - 73
src/jfw/front/swordfish.go

@@ -1364,7 +1364,6 @@ func (f *Front) Jyblog(param /*参数*/ string) error {
 		paramstr := param[1:]
 		bs, _ := base64.StdEncoding.DecodeString(paramstr)
 		json.Unmarshal(bs, &querymap)
-
 	}
 	var shareid = f.GetString("id")
 	if len(shareid) == 0 {
@@ -1391,92 +1390,66 @@ func SearhWebContentblog(querymap map[string]string) (*[]map[string]interface{},
 	}
 	contentType := querymap["contentType"]
 	queryStr := querymap["query"]
-	str := ``
+
+	queryMap := map[string]interface{}{
+		"s_contenttype": contentType,
+	}
+
 	if queryStr != "" {
-		str = `{
-	          "match": {
-	            "s_title": {
-	              "query":"` + queryStr + `",
-	              "operator": "and"
-	            }
-	          }
-	        },{
-	          "match": {
-	            "s_content": {
-	              "query":"` + queryStr + `"
-	            }
-	          }
-	        }`
-	}
-	var tempQuery = `{"query": {
-	    "bool": {
-			"must":[{"term":{"s_contenttype":"` + contentType + `"}}],
-	      	"should": [` + str + `],
-	      	"minimum_should_match": 0
-	    }
-	  }}`
-	var query = tempQuery[:len(tempQuery)-1] +
-		`,"highlight":{
-        "pre_tags":["<span class='highlight'>"],
-        "post_tags":["</span>"],
-        "fields":{
-            "s_title":{"force_source": true}
-			,"s_content":{"force_source": true}
-        }
-    },"_source":["s_title","s_date","s_contenttype","s_content","releasetime","s_description","praise","s_source","s_pic","s_pic1","l_createdate","s_code","_id","s_author"]
-	,"from":` + fmt.Sprintf("%v", ((currentPage-1)*perPage)) + `,
-	"size":` + fmt.Sprintf("%v", perPage) +
-		`,"sort":[{"releasetime":{"order":"desc"}}] }`
-
-	total := elastic.Count("content", "content", tempQuery)
+		queryMap["$or"] = []interface{}{
+			map[string]interface{}{
+				"s_title": map[string]interface{}{"$regex": queryStr},
+			},
+			map[string]interface{}{
+				"s_content": map[string]interface{}{"$regex": queryStr},
+			},
+		}
+	}
+
+	total := public.MQFW.Count("content", queryMap)
+
 	//查询列表数据
 	client := elastic.GetEsConn()
 	defer elastic.DestoryEsConn(client)
 	if client == nil {
 		return nil, nil
 	}
-	searchResult, err := client.Search().Index("content").Type("content").Source(query).Do()
-	if err != nil {
-		return nil, nil
-	}
+	searchResult, _ := public.MQFW.Find("content", queryMap, `{"releasetime":-1}`, `{"s_title":1,"s_contenttype":1,"s_content":1,"releasetime":1,"s_description":1,"praise":1,"s_source":1,"s_pic":1,"s_pic1":1,"l_createdate":1,"_id":1,"s_author":1}`, false, (currentPage-1)*perPage, perPage)
+
 	var res []map[string]interface{}
-	if searchResult.Hits != nil {
-		resNum := len(searchResult.Hits.Hits)
-		res = make([]map[string]interface{}, resNum)
-		for i, hit := range searchResult.Hits.Hits {
-			json.Unmarshal(*hit.Source, &res[i])
-			//查询结果数据加工处理
-			for k, v := range hit.Highlight {
-				res[i][k] = v[0]
-			}
-			s_content, _ := res[i]["s_content"].(string)
+	if searchResult != nil && len(*searchResult) > 0 {
+		for _, m := range *searchResult {
+			s_content, _ := m["s_content"].(string)
 			if len(s_content) > 500 {
-				res[i]["s_content"] = ""
+				m["s_content"] = ""
 			} else {
 				con, _ := regexp.Compile("^[^<]*?>")
 				content := con.ReplaceAllString(s_content, "")
 				con1, _ := regexp.Compile("<[^>]*$")
-				res[i]["s_content"] = template.HTML(con1.ReplaceAllString(content, ""))
-			}
-			s_title, _ := res[i]["s_title"].(string)
-			res[i]["s_title"] = template.HTML(s_title)
-			tmpdate, _ := res[i]["l_createdate"]
-			res[i]["l_createdate"] = util.TimeDiff(time.Unix(util.Int64All(tmpdate.(float64)), 0))
-			tmpdate1, _ := res[i]["releasetime"]
-			res[i]["releasetime"] = util.TimeDiff(time.Unix(util.Int64All(tmpdate1.(float64)), 0))
-			reltime := time.Unix(util.Int64All(tmpdate1.(float64)), 0)
-			res[i]["time"] = reltime.Format(util.Date_Short_Layout) //首页展示
-			s_pic, _ := res[i]["s_pic"].(string)
+				m["s_content"] = template.HTML(con1.ReplaceAllString(content, ""))
+			}
+
+			s_title, _ := m["s_title"].(string)
+			m["s_title"] = template.HTML(s_title)
+
+			tmpdate, _ := m["l_createdate"]
+			m["l_createdate"] = util.TimeDiff(time.Unix(util.Int64All(tmpdate), 0))
+			tmpdate1, _ := m["releasetime"]
+			m["releasetime"] = util.TimeDiff(time.Unix(util.Int64All(tmpdate1), 0))
+			reltime := time.Unix(util.Int64All(tmpdate1), 0)
+			m["time"] = reltime.Format(util.Date_Short_Layout) //首页展示
+			s_pic, _ := m["s_pic"].(string)
 			if s_pic != "" {
 				s_pic = config.Seoconfig["jyadd"].(string) + s_pic
 			}
-			res[i]["s_pic"] = s_pic
-			s_pic1, _ := res[i]["s_pic1"].(string)
+			m["s_pic"] = s_pic
+			s_pic1, _ := m["s_pic1"].(string)
 			if s_pic1 != "" {
 				s_pic1 = config.Seoconfig["jyadd"].(string) + s_pic1
 			}
-			res[i]["s_pic1"] = s_pic1
-			res[i]["_id"] = se.EncodeString(res[i]["_id"].(string))
+			m["s_pic1"] = s_pic1
+			m["_id"] = se.EncodeString(BsonIdToSId(m["_id"]))
+			res = append(res, m)
 		}
 	}
 	//生成分页
@@ -1522,6 +1495,17 @@ func MakePagination(perPage, currentPage, total int, param map[string]string, ur
 	url = fmt.Sprintf(urltpl, paramstr)
 	iscurrent = currentPage == totalPages
 	ret[index] = map[string]interface{}{"page": "下一页 >", "url": url, "iscurrent": iscurrent}
+
+	//
+	u := map[string]interface{}{
+		"currentPage": 1,
+		"query":       "招标",
+		"contentType": param["contentType"],
+	}
+	bs, _ = json.Marshal(u)
+	paramstr = base64.StdEncoding.EncodeToString(bs)
+	fmt.Println("ooooo", paramstr)
+
 	return ret
 }
 
@@ -1542,14 +1526,15 @@ func (f *Front) Jybdetail(_id string) error {
 		f.T["data"] = retlist
 	} else {
 		id := se.DecodeString(_id)
-		r := elastic.GetByIdField("content", "content", id, `"_id","s_title","l_createdate","s_pic","s_author","s_editorname","s_contenttype","praise","releasetime","s_subcontent","s_url","s_content","s_source","s_keywords","s_description","s_contenttype","s_pic1"`)
+		//r := elastic.GetByIdField("content", "content", id, `"_id","s_title","l_createdate","s_pic","s_author","s_editorname","s_contenttype","praise","releasetime","s_subcontent","s_url","s_content","s_source","s_keywords","s_description","s_contenttype","s_pic1"`)
+		r, _ := public.MQFW.FindById("content", id, `{"s_title":1,"s_contenttype":1,"s_content":1,"releasetime":1,"s_description":1,"praise":1,"s_source":1,"s_pic":1,"s_pic1":1,"l_createdate":1,"_id":1,"s_author":1,"s_editorname":1,"s_url":1,"s_subcontent":1,"s_keywords":1}`)
 		if r != nil {
 			tmpdate1, _ := (*r)["l_createdate"]
-			(*r)["l_createdate"] = util.TimeDiff(time.Unix(util.Int64All(tmpdate1.(float64)), 0))
+			(*r)["l_createdate"] = util.TimeDiff(time.Unix(util.Int64All(tmpdate1), 0))
 			tmpdate2, _ := (*r)["releasetime"]
-			(*r)["releasetime"] = util.TimeDiff(time.Unix(util.Int64All(tmpdate2.(float64)), 0))
-			(*r)["s_content"] = template.HTML((*r)["s_content"].(string))
-			(*r)["_id"] = se.EncodeString((*r)["_id"].(string))
+			(*r)["releasetime"] = util.TimeDiff(time.Unix(util.Int64All(tmpdate2), 0))
+			(*r)["s_content"] = template.HTML(util.ObjToString((*r)["s_content"]))
+			(*r)["_id"] = se.EncodeString(BsonIdToSId((*r)["_id"]))
 			s_pic, _ := (*r)["s_pic"].(string)
 			if s_pic != "" {
 				s_pic = config.Seoconfig["jyadd"].(string) + s_pic

+ 4 - 3
src/jfw/modules/app/src/app/front/message.go

@@ -3,8 +3,8 @@ package front
 import (
 	"encoding/json"
 	"html/template"
+	"jfw/public"
 	"qfw/util"
-	"qfw/util/elastic"
 	"qfw/util/redis"
 
 	"github.com/go-xweb/xweb"
@@ -29,8 +29,9 @@ func (m *Message) MesContent(_id string) error {
 		m.T["data"] = retlist
 	} else {
 		id := se.DecodeString(_id)
-		r := elastic.GetByIdField("content", "content", id, `"s_title","l_createdate","releasetime","s_content","s_source"`)
-		if r != nil {
+		//r := elastic.GetByIdField("content", "content", id, `"s_title","l_createdate","releasetime","s_content","s_source"`)
+		r, _ := public.MQFW.FindById("content", id, `{"s_title":1,"s_content":1,"releasetime":1,"s_source":1,"l_createdate":1}`)
+		if r != nil && len(*r) > 0 {
 			tmpdate1 := util.Int64All((*r)["l_createdate"])
 			(*r)["l_createdate"] = util.FormatDateByInt64(&tmpdate1, util.Date_Short_Layout)
 			tmpdate2 := util.Int64All((*r)["releasetime"])