ソースを参照

feat:调整搜索

wangshan 3 年 前
コミット
e0b3a733b5
2 ファイル変更21 行追加9 行削除
  1. 3 1
      jyBXCore/rpc/model/es/es.go
  2. 18 8
      jyBXCore/rpc/util/search.go

+ 3 - 1
jyBXCore/rpc/model/es/es.go

@@ -3,6 +3,7 @@ package es
 import (
 	elastic "app.yhyue.com/moapp/jybase/esv1"
 	"fmt"
+	"github.com/zeromicro/go-zero/core/logx"
 	"strconv"
 	"strings"
 )
@@ -33,7 +34,7 @@ func (e *EsSearch) GetAllByNgramWithCount() (int64, *[]map[string]interface{}) {
 	if e.Query != "" {
 		if e.HighLight {
 			ws := []string{}
-			for _, w := range strings.Split(e.Fields, ",") {
+			for _, w := range strings.Split(e.FindFields, ",") {
 				ws = append(ws, fmt.Sprintf(highlightStr, w, e.Count))
 			}
 			qstr = qstr[:len(qstr)-1] + `,` + fmt.Sprintf(HL, strings.Join(ws, ",")) + `}`
@@ -47,6 +48,7 @@ func (e *EsSearch) GetAllByNgramWithCount() (int64, *[]map[string]interface{}) {
 		if e.Start > -1 {
 			qstr = qstr[:len(qstr)-1] + `,"from":` + strconv.Itoa(e.Start) + `,"size":` + strconv.Itoa(e.Limit) + "}"
 		}
+		logx.Info("qstr:", qstr)
 		return elastic.GetWithCount(e.Index, e.Itype, qstr)
 	} else {
 		return 0, nil

+ 18 - 8
jyBXCore/rpc/util/search.go

@@ -11,6 +11,7 @@ import (
 	"io/ioutil"
 	IC "jyBXCore/rpc/init"
 	"jyBXCore/rpc/internal/config"
+	"jyBXCore/rpc/model/es"
 	"jyBXCore/rpc/type/bxcore"
 	"log"
 	"math/big"
@@ -178,11 +179,7 @@ func GetBidSearchData(in *bxcore.SearchReq) (count int64, list []*bxcore.SearchL
 	}
 	qstr := GetSearchQuery(in, GetBidSearchQuery(in))
 	var start = int((in.PageNum - 1) * in.PageSize)
-	//首页
-	if qstr != "" { //&& start == 0
-		count = elastic.Count(INDEX, TYPE, qstr)
-	}
-	if count > 0 || start > 1 {
+	if start >= 0 {
 		field := bidSearch_field_1
 		if start == 0 {
 			field = bidSearch_field
@@ -190,12 +187,25 @@ func GetBidSearchData(in *bxcore.SearchReq) (count int64, list []*bxcore.SearchL
 		if IC.C.FileSignBool {
 			field = field + bidSearch_field_file
 		}
+		biddingSearch := es.EsSearch{
+			Index:      INDEX,
+			Itype:      TYPE,
+			Query:      qstr,
+			FindFields: `"detail"`,
+			Order:      bidSearch_sort,
+			Fields:     field,
+			Start:      start,
+			Limit:      int(in.PageSize),
+			Count:      0,
+			HighLight:  false,
+		}
 		var repl *[]map[string]interface{}
 		if hightlightContent {
-			repl = elastic.GetAllByNgram(INDEX, TYPE, qstr, `"detail"`, bidSearch_sort, field, start, int(in.PageSize), 115, true)
-		} else {
-			repl = elastic.GetAllByNgram(INDEX, TYPE, qstr, ``, bidSearch_sort, field, start, int(in.PageSize), 0, false)
+			biddingSearch.Count = 115
+			biddingSearch.HighLight = true
 		}
+		//repl = elastic.GetAllByNgram(INDEX, TYPE, qstr, ``, bidSearch_sort, field, start, int(in.PageSize), 0, false)
+		count, repl = biddingSearch.GetAllByNgramWithCount()
 		if repl != nil && *repl != nil && len(*repl) > 0 {
 			BidListConvert(in.Industry, repl)
 			list = searchListFormart(repl, true)