|
@@ -1,24 +1,21 @@
|
|
|
package util
|
|
|
|
|
|
import (
|
|
|
- MC "app.yhyue.com/moapp/jybase/common"
|
|
|
- ME "app.yhyue.com/moapp/jybase/encrypt"
|
|
|
- "crypto/rand"
|
|
|
- "encoding/json"
|
|
|
"fmt"
|
|
|
- "github.com/zeromicro/go-zero/core/logx"
|
|
|
- "io/ioutil"
|
|
|
IC "jyBXCore/rpc/init"
|
|
|
"jyBXCore/rpc/internal/config"
|
|
|
"jyBXCore/rpc/type/bxcore"
|
|
|
- "math/big"
|
|
|
"net/http"
|
|
|
"net/url"
|
|
|
"regexp"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
"time"
|
|
|
- "unicode"
|
|
|
+
|
|
|
+ MC "app.yhyue.com/moapp/jybase/common"
|
|
|
+ ME "app.yhyue.com/moapp/jybase/encrypt"
|
|
|
+ "app.yhyue.com/moapp/jybase/es"
|
|
|
+ "github.com/zeromicro/go-zero/core/logx"
|
|
|
)
|
|
|
|
|
|
var (
|
|
@@ -102,46 +99,7 @@ func InterceptSearchKW(word string, keywordsLimit int, isFilter bool) (bWord, aW
|
|
|
}
|
|
|
|
|
|
func HttpEs(ques, analyzer, esAddress string) (res string) {
|
|
|
- var adders []string
|
|
|
- curl := ""
|
|
|
- for _, s := range strings.Split(esAddress, ",") {
|
|
|
- adders = append(adders, s)
|
|
|
- }
|
|
|
- i, _ := rand.Int(rand.Reader, big.NewInt(int64(len(adders)))) //随机
|
|
|
- curl = adders[int(i.Int64())] + "/bidding/_analyze"
|
|
|
- URL, _ := url.Parse(curl)
|
|
|
- Q := URL.Query()
|
|
|
- Q.Add("text", ques)
|
|
|
- Q.Add("analyzer", analyzer)
|
|
|
- URL.RawQuery = Q.Encode()
|
|
|
- resp, err := http.Get(URL.String())
|
|
|
- if err != nil {
|
|
|
- logx.Info("es连接失败 err1:", err)
|
|
|
- resp, err = getESResp(ques, analyzer, adders)
|
|
|
- if err != nil {
|
|
|
- return
|
|
|
- }
|
|
|
- }
|
|
|
- result, err1 := ioutil.ReadAll(resp.Body)
|
|
|
- if err1 == nil {
|
|
|
- defer resp.Body.Close()
|
|
|
- var resMap map[string]interface{}
|
|
|
- json.Unmarshal(result, &resMap)
|
|
|
- if resMap != nil && resMap["tokens"] != nil {
|
|
|
- tokens := MC.ObjArrToMapArr(resMap["tokens"].([]interface{}))
|
|
|
- for _, v := range tokens {
|
|
|
- token := MC.ObjToString(v["token"])
|
|
|
- if len([]rune(token)) == 1 && !unicode.Is(unicode.Scripts["Han"], []rune(token)[0]) { //(P260保留单个汉字)
|
|
|
- continue
|
|
|
- }
|
|
|
- if res != "" && token != "" {
|
|
|
- res += IC.C.JYKeyMark
|
|
|
- }
|
|
|
- res += token
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return
|
|
|
+ return es.Analyze(ques, "bidding", analyzer)
|
|
|
}
|
|
|
|
|
|
func getESResp(ques, analyzer string, adds []string) (resp *http.Response, err error) {
|