Browse Source

feat:未登录查询

wangshan 1 year ago
parent
commit
6e5fe0b26b
7 changed files with 105 additions and 55 deletions
  1. 7 0
      src/db.json
  2. 1 1
      src/go.mod
  3. 2 2
      src/go.sum
  4. 21 11
      src/jfw/front/searchOptimize.go
  5. 19 4
      src/jfw/front/supsearch.go
  6. 20 3
      src/jfw/front/swordfish.go
  7. 35 34
      src/web/staticres/js/superSearch.js

+ 7 - 0
src/db.json

@@ -37,6 +37,13 @@
       "version": "v7",
       "userName": "",
       "password": ""
+    },
+    "other": {
+      "address": "http://192.168.3.241:9205,http://192.168.3.149:9200",
+      "size": 30,
+      "version": "v7",
+      "userName": "",
+      "password": ""
     }
   },
   "redis": {

+ 1 - 1
src/go.mod

@@ -6,7 +6,7 @@ require (
 	app.yhyue.com/moapp/jyMarketing v0.0.2-0.20230308011651-df591d32df88
 	app.yhyue.com/moapp/jybase v0.0.0-20230901064756-2fc66b18db40
 	app.yhyue.com/moapp/jylog v0.0.0-20230522075550-05d7230ca545
-	app.yhyue.com/moapp/jypkg v0.0.0-20230925120741-9e02619bfe25
+	app.yhyue.com/moapp/jypkg v0.0.0-20230926094058-438d017d0f81
 	bp.jydev.jianyu360.cn/BaseService/userCenter v1.2.14
 	github.com/SKatiyar/qr v0.0.0-20151201054752-25b6bdf44e67
 	github.com/bwmarrin/snowflake v0.3.0

+ 2 - 2
src/go.sum

@@ -9,8 +9,8 @@ app.yhyue.com/moapp/jybase v0.0.0-20230901064756-2fc66b18db40 h1:/FcBvpf/KW8g6GB
 app.yhyue.com/moapp/jybase v0.0.0-20230901064756-2fc66b18db40/go.mod h1:Hv9U/7oHRucqH315Tr1+d03NCvS9mOKPfk8pwwlOIwQ=
 app.yhyue.com/moapp/jylog v0.0.0-20230522075550-05d7230ca545 h1:+Lak4m1zgsigQloOsvp8AJ+0XeX/+PGp9QP550xlbBQ=
 app.yhyue.com/moapp/jylog v0.0.0-20230522075550-05d7230ca545/go.mod h1:uFrsdUBFbETiJlEmr4PtJWPsZlUpPj2bHQRhryu6ggk=
-app.yhyue.com/moapp/jypkg v0.0.0-20230925120741-9e02619bfe25 h1:2q7b1auPihIJD3Ewsd7Zi8ESeLkxuP57avWL8UoBr9U=
-app.yhyue.com/moapp/jypkg v0.0.0-20230925120741-9e02619bfe25/go.mod h1:gPCOY8bVXdY5bD7nry7th+YNkKC/viG8Dc9+z4fUaRo=
+app.yhyue.com/moapp/jypkg v0.0.0-20230926094058-438d017d0f81 h1:YrT86U95eMPFf7mdum3FtYpr4CwvTVXC4ZzXWXvW+R0=
+app.yhyue.com/moapp/jypkg v0.0.0-20230926094058-438d017d0f81/go.mod h1:gPCOY8bVXdY5bD7nry7th+YNkKC/viG8Dc9+z4fUaRo=
 app.yhyue.com/moapp/message v0.0.0-20221223100203-6402e389d9ae h1:6rDDaz6yxvE8viTSzEBwKYOFWq14TMfuBivSazUZMz4=
 app.yhyue.com/moapp/message v0.0.0-20221223100203-6402e389d9ae/go.mod h1:b0zZHev3gmJao1Fo+2Z2KPVjsuLOJVvVxf+kCnu9WkA=
 bp.jydev.jianyu360.cn/BaseService/entManageApplication v0.0.0-20230214091519-89a98c01ab0e h1:h+VEI3o1qC0jeCzkFGTrLI4f27cfa/W/y+0sXokWMgE=

+ 21 - 11
src/jfw/front/searchOptimize.go

@@ -284,9 +284,11 @@ func (so *SearchOptimize) GetBidSearchList(isCache bool) (count, total int64, li
 	if start >= 0 {
 		t := time.Now()
 		fields := util.If(so.IsPay, BidSearchFieldOfVip, BidSearchFieldBase).(string)
+		esIndex := util.If(so.UserId == "", INDEXOther, INDEX).(string)
+		esType := util.If(so.UserId == "", TYPEOther, TYPE).(string)
 		biddingSearch := SearchByES{
-			Index:      INDEX,
-			IType:      TYPE,
+			Index:      esIndex,
+			IType:      esType,
 			Query:      so.GetSearchQuery(so.GetBidSearchQuery()),
 			FindFields: util.If(isCache, "title", "detail").(string),
 			Order:      BidSearchSort,
@@ -295,6 +297,7 @@ func (so *SearchOptimize) GetBidSearchList(isCache bool) (count, total int64, li
 			Limit:      util.If(isCache, util.If(so.IsPay, bidsearch.SearchMaxPageCount_PAYED, bidsearch.SearchMaxPageCount_PC).(int), so.PageSize).(int), //缓存数据: 付费或未登录用户一次性5000条,100页数据;免费用户一次性500条,10页数据;实时数据:每页50条数据请求
 			Count:      util.If(strings.Contains(so.SelectType, "detail"), 115, 0).(int),                                                                  //高亮正文数量
 			HighLight:  util.If(strings.Contains(so.SelectType, "detail"), true, false).(bool),                                                            //是否高亮正文
+			IsLogin:    so.UserId != "",
 		}
 		var repl *[]map[string]interface{}
 		total, repl = biddingSearch.GetAllByNgramWithCount()
@@ -366,6 +369,7 @@ func (so *SearchOptimize) GetSearchQuery(mustQuery string) (qstr string) {
 		//搜索范围只选择附件,是否有附件条件无效;
 		isFileSearch  = so.SelectType == "filetext"
 		selectTypeArr = strings.Split(so.SelectType, ",")
+		isLogin       = so.UserId == ""
 	)
 	if mustQuery != "" {
 		musts = append(musts, mustQuery)
@@ -477,11 +481,11 @@ func (so *SearchOptimize) GetSearchQuery(mustQuery string) (qstr string) {
 		mustNot = append(mustNot, fmt.Sprintf(queryBoolShould, strings.Join(notKeyMustNot, ",")))
 	}
 	//行业
-	if so.Industry != "" {
+	if so.Industry != "" && isLogin {
 		musts = append(musts, fmt.Sprintf(queryBoolMust, `"`+strings.ReplaceAll(so.Industry, ",", `","`)+`"`))
 	}
 	//价格
-	if so.Price != "" && len(strings.Split(so.Price, "-")) > 1 {
+	if so.Price != "" && len(strings.Split(so.Price, "-")) > 1 && isLogin {
 		minPrice, maxPrice := strings.Split(so.Price, "-")[0], strings.Split(so.Price, "-")[1]
 		if minPrice != "" || maxPrice != "" {
 			sq := ``
@@ -515,7 +519,7 @@ func (so *SearchOptimize) GetSearchQuery(mustQuery string) (qstr string) {
 	}
 	//采购单位联系方式
 	hasBuyerTel := so.BuyerTel
-	if hasBuyerTel != "" {
+	if hasBuyerTel != "" && isLogin {
 		if hasBuyerTel == "y" {
 			musts = append(musts, fmt.Sprintf(queryExists, "buyertel"))
 		} else {
@@ -524,7 +528,7 @@ func (so *SearchOptimize) GetSearchQuery(mustQuery string) (qstr string) {
 	}
 	//中标企业联系方式
 	hasWinnerTel := so.WinnerTel
-	if hasWinnerTel != "" {
+	if hasWinnerTel != "" && isLogin {
 		if hasWinnerTel == "y" {
 			musts = append(musts, fmt.Sprintf(queryExists, "winnertel"))
 		} else {
@@ -533,7 +537,7 @@ func (so *SearchOptimize) GetSearchQuery(mustQuery string) (qstr string) {
 	}
 	//附件
 	fileExists := so.FileExists
-	if !isFileSearch && fileExists != "" {
+	if !isFileSearch && fileExists != "" && isLogin {
 		if fileExists == "1" { //有附件
 			musts = append(musts, fmt.Sprintf(queryBoolMustTerm, true))
 		} else if fileExists == "-1" { //无附件
@@ -554,7 +558,8 @@ func (so *SearchOptimize) GetBidSearchQuery() string {
 	query := ``
 	//省份
 	area := so.Province
-	if area != "" {
+	isLogin := so.UserId != ""
+	if area != "" && isLogin {
 		query += `{"terms":{"area":[`
 		for k, v := range strings.Split(area, ",") {
 			if k > 0 {
@@ -566,7 +571,7 @@ func (so *SearchOptimize) GetBidSearchQuery() string {
 	}
 	//
 	city := so.City
-	if city != "" {
+	if city != "" && isLogin {
 		if len(query) > 0 {
 			query += ","
 		}
@@ -669,7 +674,7 @@ func (so *SearchOptimize) GetBidSearchQuery() string {
 		query += fmt.Sprintf(queryBoolShould, allType)
 	}
 	//采购单位类型
-	if so.BuyerClass != "" {
+	if so.BuyerClass != "" && isLogin {
 		if len(query) > 0 {
 			query += ","
 		}
@@ -749,6 +754,7 @@ type SearchByES struct {
 	Limit      int
 	Count      int
 	HighLight  bool
+	IsLogin    bool
 }
 
 // GetAllByNgramWithCount  获取es查询结果及总数量
@@ -772,7 +778,11 @@ func (e *SearchByES) GetAllByNgramWithCount() (int64, *[]map[string]interface{})
 			queryStr = queryStr[:len(queryStr)-1] + `,"from":` + strconv.Itoa(e.Start) + `,"size":` + strconv.Itoa(e.Limit) + "}"
 		}
 		log.Println("queryStr:", queryStr)
-		return elastic.GetWithCount(e.Index, e.IType, e.Query, queryStr)
+		if e.IsLogin {
+			return elastic.GetWithCount(e.Index, e.IType, e.Query, queryStr)
+		} else {
+			return pc.Other.GetWithCount(e.Index, e.IType, e.Query, queryStr)
+		}
 	} else {
 		return 0, nil
 	}

+ 19 - 4
src/jfw/front/supsearch.go

@@ -344,6 +344,10 @@ func (p *Pcsearch) PcSearchIndex(module string) error {
 	//--end--
 	userId, _ := p.GetSession("userId").(string)
 	phone, _ := p.GetSession("phone").(string)
+	selectType := p.GetString("selectType") //搜索范围
+	if selectType == "" {
+		selectType = "title,content"
+	}
 	//p353包含采购意向与拟建
 	noLoginBl := false
 	if userId == "" {
@@ -362,6 +366,21 @@ func (p *Pcsearch) PcSearchIndex(module string) error {
 			subtype = "招标预告,招标公告,招标结果,招标信用信息"
 			noLoginBl = true
 		}
+		//未登录用户搜索范围 标题和 正文
+		var selectTypeArr []string
+		selectTypeSplit := strings.Split(selectType, ",")
+		// 未登录用户只能搜标题和正文
+		for i := 0; i < len(selectTypeSplit); i++ {
+			if selectTypeSplit[i] == "title" || selectTypeSplit[i] == "content" {
+				selectTypeArr = append(selectTypeArr, selectTypeSplit[i])
+			}
+		}
+		if len(selectTypeArr) > 0 {
+			selectType = strings.Join(selectTypeArr, ",")
+		}
+		if publishtime != "" {
+			publishtime = ""
+		}
 	}
 	//高级筛选 仅vip用户可查询
 	var (
@@ -380,10 +399,6 @@ func (p *Pcsearch) PcSearchIndex(module string) error {
 	default:
 		territorialization = ""
 	}
-	selectType := p.GetString("selectType")
-	if selectType == "" {
-		selectType = "title,content"
-	}
 	userInfo := jy.GetVipState(p.Session(), *config.Middleground, userId)
 	queryItems := userInfo.GetQueryItems(selectType, util.Int64All(config.Sysconfig["bidSearchOldUserLimit"]))
 	isPayedUser := userInfo.IsPayedUser()

+ 20 - 3
src/jfw/front/swordfish.go

@@ -129,6 +129,21 @@ func (m *Front) PcAjaxReq() {
 			subtype = "招标预告,招标公告,招标结果,招标信用信息"
 		}
 
+		//未登录用户搜索范围 标题和 正文
+		var selectTypeArr []string
+		selectTypeSplit := strings.Split(selectType, ",")
+		// 未登录用户只能搜标题和正文
+		for i := 0; i < len(selectTypeSplit); i++ {
+			if selectTypeSplit[i] == "title" || selectTypeSplit[i] == "content" {
+				selectTypeArr = append(selectTypeArr, selectTypeSplit[i])
+			}
+		}
+		if len(selectTypeArr) > 0 {
+			selectType = strings.Join(selectTypeArr, ",")
+		}
+		if publishtime != "" {
+			publishtime = ""
+		}
 	}
 	industry := strings.TrimSpace(m.GetString("industry"))
 	minprice := m.GetString("minprice")               //最低价格
@@ -1180,9 +1195,11 @@ func (m *Front) AjaxReq() error {
 }
 
 const (
-	INDEX = "bidding"
-	TYPE  = "bidding"
-	FINDF = `"title"`
+	INDEX      = "bidding"
+	TYPE       = "bidding"
+	INDEXOther = "bidding_year"
+	TYPEOther  = "bidding_year"
+	FINDF      = `"title"`
 )
 
 // 预览结果

+ 35 - 34
src/web/staticres/js/superSearch.js

@@ -170,10 +170,10 @@ $(function() {
     })
   })
 
-  if (!loginflag) {
-    // @2023/9/26 未登录限制搜索条件,使用接口
-    beforeSubmit('filter-selectType')
-  }
+  // if (!loginflag) {
+  //   // @2023/9/26 未登录限制搜索条件,使用接口
+  //   beforeSubmit('filter-selectType')
+  // }
 })
 
 //取redis里的数据
@@ -938,12 +938,12 @@ function beforeSubmit(from){
   // from=='page-init-recovery'回显搜索
   from = from || ''
 
-  // @2023/9/26 未登录限制搜索条件
-  if (!loginflag) {
-    if (from.indexOf('filter-') !== -1 && from !== 'filter-selectType') {
-      return openLoginDig()
-    }
-  }
+  // // @2023/9/26 未登录限制搜索条件
+  // if (!loginflag) {
+  //   if (from.indexOf('filter-') !== -1 && from !== 'filter-selectType') {
+  //     return openLoginDig()
+  //   }
+  // }
 
   var searchKeywords = $.trim($("#zbSeatchT input[name='keywords']").val())
   // 如果在反爬白名单,则空搜索刷新搜索结果(即允许空搜索)
@@ -1213,7 +1213,8 @@ function searchOnsubmit(clickpaging){
     additionalWords: $("#zbSeatchT [name='additionalWords']").val()
   };
 
-  function queryBack (r) {
+  // function queryBack (r) {
+  $.post("/front/pcAjaxReq",param,function(r){
     heightWords = r.heightWords
     if(r.limitFlag){
       LimitClass.limitFlag = true;
@@ -1231,34 +1232,34 @@ function searchOnsubmit(clickpaging){
       LimitClass.limitFlag = false;
       pcAjaxReqCallBack(r);
     }
-    if (loginflag) {
+    // if (loginflag) {
       autoModelFn(r)
-    }
+    });
     // getBidIsColl()
   }
 
   // @2023/9/26 未登录限制搜索条件,更换接口
-  if (!loginflag) {
-    $.ajax({
-      type: 'POST',
-      url: '/jyapi/jybx/core/nologin/search',
-      data: JSON.stringify({
-        pageNum: param.pageNumber,
-        pageSize: param.pageSize,
-        selectType: param.selectType,
-        keyWords: param.searchvalue,
-      }),
-      contentType: 'application/json',
-      success: function (r) {
-        queryBack(r)
-      }
-    })
-  } else {
-    $.post("/front/pcAjaxReq",param,function(r){
-      queryBack(r)
-    });
-  }
-}
+  // if (!loginflag) {
+  //   $.ajax({
+  //     type: 'POST',
+  //     url: '/jyapi/jybx/core/nologin/search',
+  //     data: JSON.stringify({
+  //       pageNum: param.pageNumber,
+  //       pageSize: param.pageSize,
+  //       selectType: param.selectType,
+  //       keyWords: param.searchvalue,
+  //     }),
+  //     contentType: 'application/json',
+  //     success: function (r) {
+  //       queryBack(r)
+  //     }
+  //   })
+  // } else {
+  //   $.post("/front/pcAjaxReq",param,function(r){
+  //     queryBack(r)
+  //   });
+  // }
+// }
 function showSearchTipForTimeRange (type) {
 	var tempDom = $("#hasNoData_tiptext>font:eq(0)")
 	var tipMap = {