wangchuanjin hace 8 años
padre
commit
05de7d3d50
Se han modificado 3 ficheros con 45 adiciones y 25 borrados
  1. 3 3
      src/jfw/front/entsearch.go
  2. 2 2
      src/jfw/front/supsearch.go
  3. 40 20
      src/jfw/front/swordfish.go

+ 3 - 3
src/jfw/front/entsearch.go

@@ -3,13 +3,13 @@ package front
 import (
 	"fmt"
 	"jfw/jylabutil"
+	_ "jfw/jyutil"
 	"log"
 	"qfw/util"
 	"time"
-	_"jfw/jyutil"
 
-	"strconv"
 	"github.com/go-xweb/xweb"
+	"strconv"
 )
 
 type Entsearch struct {
@@ -99,7 +99,7 @@ func (e *Entsearch) PcSearchZbqyAjax() error {
 	fmt.Println("pricetype==", pricetype)
 
 	list := []map[string]interface{}{}
-	list = jylabutil.GetProjectByEntName(searchvalue, area, minprice, maxprice, 1, 10)
+	//list = jylabutil.GetProjectByEntName(searchvalue, area, minprice, maxprice, 1, 10)
 	//jyutil.BidListConvert("", &list)
 
 	for k, v := range list {

+ 2 - 2
src/jfw/front/supsearch.go

@@ -79,7 +79,7 @@ func (p *Pcsearch) PcSearchIndex() error {
 		count, list = getBidSearchData(searchvalue, area, publishtime, subtype, industry, minprice, maxprice, 0, true, selectType)
 	} else if p.Method() == "POST" {
 		status = 2
-		count, list = getLastNewsData(searchvalue, area, publishtime, subtype, industry, minprice, maxprice, 0, true)
+		count, list = getLastNewsData(searchvalue, area, publishtime, subtype, industry, minprice, maxprice, 0, true, true)
 	} else {
 		p.DisableHttpCache()
 		Newbids()
@@ -207,7 +207,7 @@ func Newbids() {
 			}
 		}
 		for i := 0; i < 10; i++ {
-			_, list = getLastNewsData("", "", "", "", "", "", "", intns[i], true)
+			_, list = getLastNewsData("", "", "", "", "", "", "", intns[i], true, false)
 			jyutil.BidListConvert("", list)
 			for k, v := range *list {
 				v["k"] = (k + 1) + i*50

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

@@ -30,7 +30,7 @@ const (
 	bidSearch_maxPageSize = 10 //招标搜索分页--最大页数
 	wx_maxPageNum         = 20
 	wx_pageSize           = 50
-	bidSearch_field_1     = `"_id","title","publishtime","toptype","subtype","type","area","href","bidopentime","winner","agency","bidamount","budget","biddingcontent","projectname"`
+	bidSearch_field_1     = `"_id","title","publishtime","toptype","subtype","type","area","href","bidopentime","winner","agency","bidamount","budget","s_subscopeclass","projectname"`
 	bidSearch_field       = bidSearch_field_1 + `,"detail"`
 	bidSearch_sort        = `{"publishtime":-1}`
 )
@@ -139,7 +139,7 @@ func (m *Front) NewSordfish() error {
 			return m.SetBody([]byte(ret.(string)))
 		} else {
 			m.DisableHttpCache()
-			lastBids := elastic.GetPage("bidding", "bidding", "{}", bidSearch_sort, `"_id","title","publishtime","toptype","subtype","type","area","href","biddingcontent"`, 0, 18)
+			lastBids := elastic.GetPage("bidding", "bidding", "{}", bidSearch_sort, `"_id","title","publishtime","toptype","subtype","type","area","href","s_subscopeclass"`, 0, 18)
 			if lastBids != nil && len(*lastBids) > 0 {
 				jyutil.BidListConvert("", lastBids)
 				lbnHtml, olHtml := structureLastBidsHtml(lastBids)
@@ -301,7 +301,7 @@ func (m *Front) Searchinfolist(p string) error {
 		count, list = getBidSearchData(searchvalue, area, publishtime, subtype, industry, minprice, maxprice, 0, true, selectType)
 	} else if m.Method() == "POST" {
 		status = 2
-		count, list = getLastNewsData(searchvalue, area, publishtime, subtype, industry, minprice, maxprice, 0, true)
+		count, list = getLastNewsData(searchvalue, area, publishtime, subtype, industry, minprice, maxprice, 0, true, false)
 	} else {
 		status = 2
 		if redis.Get("other", "index_list") == nil {
@@ -320,7 +320,7 @@ func (m *Front) Searchinfolist(p string) error {
 				}
 			}
 			for i := 0; i < 10; i++ {
-				count, list = getLastNewsData(searchvalue, area, publishtime, subtype, industry, minprice, maxprice, intns[i], true)
+				count, list = getLastNewsData(searchvalue, area, publishtime, subtype, industry, minprice, maxprice, intns[i], true, false)
 				for k, v := range *list {
 					v["k"] = (k + 1) + i*50
 					t := time.Unix(util.Int64All(v["publishtime"]), 0)
@@ -456,12 +456,12 @@ func (m *Front) PcAjaxReq() {
 		if status == 1 {
 			count, list = getBidSearchData(searchvalue, area, publishtime, subtype, industry, minprice, maxprice, 0, true, selectType)
 		} else if status == 2 {
-			count, list = getLastNewsData(searchvalue, area, publishtime, subtype, industry, minprice, maxprice, 0, true)
+			count, list = getLastNewsData(searchvalue, area, publishtime, subtype, industry, minprice, maxprice, 0, true, true)
 		}
 	} else if reqType == "bidSearch" {
 		count, list = getBidSearchData(searchvalue, area, publishtime, subtype, industry, minprice, maxprice, start, true, selectType)
 	} else if reqType == "lastNews" {
-		_, list = getLastNewsData(searchvalue, area, publishtime, subtype, industry, minprice, maxprice, start, false)
+		_, list = getLastNewsData(searchvalue, area, publishtime, subtype, industry, minprice, maxprice, start, false, true)
 	}
 	if list != nil && len(*list) > 0 {
 		for _, v := range *list {
@@ -495,7 +495,11 @@ func (m *Front) PcAjaxReq() {
 **/
 func getBidSearchData(searchvalue, area, publishtime, subtype, industry, minprice, maxprice string, start int, isGetCount bool, selectType string) (count int64, list *[]map[string]interface{}) {
 	//selectType:全文搜索(all)、标题搜索(title)
-	qstr := getSearchQuery(searchvalue, industry, minprice, maxprice, getBidSearchQuery(area, publishtime, subtype))
+	findfields := `"title"`
+	if selectType == "all" {
+		findfields = `"title","detail"`
+	}
+	qstr := getSearchQuery(searchvalue, industry, minprice, maxprice, findfields, getBidSearchQuery(area, publishtime, subtype))
 	if isGetCount && qstr != "" {
 		count = elastic.Count(INDEX, TYPE, qstr)
 	}
@@ -503,10 +507,10 @@ func getBidSearchData(searchvalue, area, publishtime, subtype, industry, minpric
 		var repl *[]map[string]interface{}
 		if selectType == "all" {
 			//全文搜索
-			repl = elastic.GetAllByNgram(INDEX, TYPE, qstr, `"title","detail"`, bidSearch_sort, bidSearch_field, start, bidSearch_pageSize, 115, true)
+			repl = elastic.GetAllByNgram(INDEX, TYPE, qstr, findfields, bidSearch_sort, bidSearch_field, start, bidSearch_pageSize, 115, true)
 		} else {
 			//标题搜索
-			repl = elastic.GetAllByNgram(INDEX, TYPE, qstr, "", bidSearch_sort, bidSearch_field, start, bidSearch_pageSize, 0, false)
+			repl = elastic.GetAllByNgram(INDEX, TYPE, qstr, findfields, bidSearch_sort, bidSearch_field, start, bidSearch_pageSize, 0, false)
 		}
 		if repl != nil && *repl != nil && len(*repl) > 0 {
 			jyutil.BidListConvert(industry, repl)
@@ -519,14 +523,15 @@ func getBidSearchData(searchvalue, area, publishtime, subtype, industry, minpric
 	}
 	return
 }
-func getLastNewsData(searchvalue, area, publishtime, subtype, industry, minprice, maxprice string, start int, isGetCount bool) (count int64, list *[]map[string]interface{}) {
+func getLastNewsData(searchvalue, area, publishtime, subtype, industry, minprice, maxprice string, start int, isGetCount bool, highlight bool) (count int64, list *[]map[string]interface{}) {
 	//最新招标信息
-	qstr := getSearchQuery(searchvalue, industry, minprice, maxprice, getBidSearchQuery(area, publishtime, subtype))
+	findfields := `"title","detail"`
+	qstr := getSearchQuery(searchvalue, industry, minprice, maxprice, findfields, getBidSearchQuery(area, publishtime, subtype))
 	if isGetCount {
 		count = elastic.Count(INDEX, TYPE, qstr)
 	}
 	if !isGetCount || count > 0 {
-		repl := elastic.GetAllByNgram(INDEX, TYPE, qstr, `"title","detail"`, bidSearch_sort, bidSearch_field, start, bidSearch_pageSize, 115, true)
+		repl := elastic.GetAllByNgram(INDEX, TYPE, qstr, findfields, bidSearch_sort, bidSearch_field, start, bidSearch_pageSize, 115, highlight)
 		if repl != nil && *repl != nil && len(*repl) > 0 {
 			jyutil.BidListConvert(industry, repl)
 			list = repl
@@ -909,12 +914,16 @@ func (m *Front) DelWxHistorySearch() {
 func getWxsearchlistData(keywords, searchvalue, scope, publishtime, subtype, industry, minprice, maxprice string, pageNum int, selectType string) (list *[]map[string]interface{}) {
 	//scope是地区对应传进的areas, stype是类型对应scope
 	fmt.Print("keywords>>>", keywords, "searchvalue>>", searchvalue)
-	qstr := getSearchQuery(searchvalue, industry, minprice, maxprice, getBidSearchQuery(scope, publishtime, subtype))
+	findfields := `"title"`
+	if selectType == "all" {
+		findfields = `"title","detail"`
+	}
+	qstr := getSearchQuery(searchvalue, industry, minprice, maxprice, findfields, getBidSearchQuery(scope, publishtime, subtype))
 	if len(keywords) > 0 {
 		if selectType == "all" { //全文搜索
-			list = elastic.GetAllByNgram(INDEX, TYPE, qstr, `"title","detail"`, bidSearch_sort, bidSearch_field_1, (pageNum-1)*wx_pageSize, wx_pageSize, 100, true)
+			list = elastic.GetAllByNgram(INDEX, TYPE, qstr, findfields, bidSearch_sort, bidSearch_field_1, (pageNum-1)*wx_pageSize, wx_pageSize, 100, true)
 		} else { //标题搜索
-			list = elastic.GetAllByNgram(INDEX, TYPE, qstr, "", bidSearch_sort, bidSearch_field_1, (pageNum-1)*wx_pageSize, wx_pageSize, 100, false)
+			list = elastic.GetAllByNgram(INDEX, TYPE, qstr, findfields, bidSearch_sort, bidSearch_field_1, (pageNum-1)*wx_pageSize, wx_pageSize, 100, false)
 		}
 
 		if list != nil {
@@ -2039,7 +2048,7 @@ func (f *Front) SearchResult(at, name string) error {
 			if count1 < startPage || startPage < 0 {
 				startPage = 0
 			}
-			datas = elastic.GetPage(INDEX, TYPE, query, bidSearch_sort, `"_id","title","publishtime","toptype","subtype","type","area","href","bidopentime","winner","agency","bidamount","budget","biddingcontent","projectname"`, startPage, limitcount)
+			datas = elastic.GetPage(INDEX, TYPE, query, bidSearch_sort, `"_id","title","publishtime","toptype","subtype","type","area","href","bidopentime","winner","agency","bidamount","budget","s_subscopeclass","projectname"`, startPage, limitcount)
 			redis.Put("other", "classify_"+name, datas, 2*60*60)
 		} else {
 			b, _ := json.Marshal(list)
@@ -2209,8 +2218,8 @@ func getShouldQueryMap(findfield, searchvalue, industry string) []map[string]str
 	return mps
 }
 
-func getSearchQuery(keyword, industry, minprice, maxprice, mustquery string) (qstr string) {
-	multi_match := `{"multi_match": {"query": "%s","type": "phrase", "fields": ["title","detail"],"analyzer": "my_ngram"}}`
+func getSearchQuery(keyword, industry, minprice, maxprice, findfields, mustquery string) (qstr string) {
+	multi_match := `{"multi_match": {"query": "%s","type": "phrase", "fields": [%s],"analyzer": "my_ngram"}}`
 	match_phrase := `{"match_phrase": {"s_subscopeclass": "%s"}}`
 	query := `{"query":{"bool":{"must":[%s],"should":[%s],"minimum_should_match": %d}}}`
 	query_bool := `{"bool":{"should":[%s],"minimum_should_match": 1}}`
@@ -2219,6 +2228,7 @@ func getSearchQuery(keyword, industry, minprice, maxprice, mustquery string) (qs
 	lte := `"lte": %s`
 	bools := []string{}
 	if keyword != "" {
+		multi_match = fmt.Sprintf(multi_match, "%s", findfields)
 		shoulds := []string{}
 		for _, v := range strings.Split(keyword, "+") {
 			shoulds = append(shoulds, fmt.Sprintf(multi_match, elastic.ReplaceYH(v)))
@@ -2235,16 +2245,26 @@ func getSearchQuery(keyword, industry, minprice, maxprice, mustquery string) (qs
 	if minprice != "" || maxprice != "" {
 		sq := ``
 		if minprice != "" {
+			min, _ := strconv.ParseFloat(minprice, 64)
+			minprice = fmt.Sprintf("%.0f", min*10000)
+		}
+		if maxprice != "" {
+			max, _ := strconv.ParseFloat(maxprice, 64)
+			maxprice = fmt.Sprintf("%.0f", max*10000)
+		}
+		log.Println(minprice, maxprice)
+		if minprice != "0" {
 			sq += fmt.Sprintf(gte, minprice)
 		}
-		if minprice != "" && maxprice != "" {
+		if minprice != "0" && maxprice != "0" {
 			sq += `,`
 		}
-		if maxprice != "" {
+		if maxprice != "0" {
 			sq += fmt.Sprintf(lte, maxprice)
 		}
 		bools = append(bools, fmt.Sprintf(query_bool, fmt.Sprintf(rge, sq, sq)))
 	}
 	qstr = fmt.Sprintf(query, mustquery, strings.Join(bools, ","), len(bools))
+	log.Println("getSearchQuery:", qstr)
 	return
 }