Commit ab1db960 by 孙龙

up

parent 4e661ace
......@@ -47,6 +47,34 @@ MK=MK(米客方德)
[ZIYING_CONFIG]
Index=liexin_ziying
[SEARCH_KEYWORD_MAPPING]
`^(.* )?([\d\.]+)(欧|欧姆|R|r)( .*)?$` = ${1}${2}Ω${4}
`^(.* )?([\d\.]+)(U|u|μ)(.?)( .*)?$` = ${1}${2}Μ${4}${5}
`COG` = C0G
`NPO` = NP0
`华科|华新科技|华新科` = 华新
[mathExactGoodsName]
0=M7
1=M1
2=M4
3=M2
4=A7
5=F7
6=X2
7=G4
8=X4
9=m7
10=m1
11=m4
12=m2
13=a7
14=f7
15=x2
16=g4
17=x4
[official_website]
1 = https://www.futureelectronics.cn/search/?text=liexin
2 = http://www.powerandsignal.com/Products/Search?searchBox=liexin
......
......@@ -5,6 +5,7 @@ import (
"github.com/gin-gonic/gin"
"search_server/model"
"search_server/service"
"strings"
)
......@@ -14,7 +15,7 @@ func Zyh(ctx *gin.Context){
ctx.MultipartForm()
for requestName, requstValue := range ctx.Request.Form {
if requstValue[0] != "" {
zyhRequest[requestName] = requstValue[0]
zyhRequest[requestName] = strings.TrimSpace(requstValue[0])
}
}
......
......@@ -148,3 +148,4 @@ func Rand(min, max int) int {
n, _ := crand.Int(crand.Reader, big.NewInt(int64(max+1)))
return int(n.Int64()) + min
}
......@@ -6,7 +6,9 @@ import (
"github.com/gin-gonic/gin"
"github.com/gomodule/redigo/redis"
"github.com/ichunt2019/logger"
"github.com/syyongx/php2go"
"gopkg.in/olivere/elastic.v5"
"regexp"
"search_server/model"
"search_server/pkg/config"
"search_server/pkg/gredis"
......@@ -72,6 +74,7 @@ func zy(req map[string]string,_type byte,isCheck byte) (rsp *model.ZyhResponse){
var (
classid int64
err error
)
rsp = &model.ZyhResponse{}
zhyClassList := &model.ZhyClassList{}
......@@ -133,7 +136,9 @@ func zy(req map[string]string,_type byte,isCheck byte) (rsp *model.ZyhResponse){
func searchZiYingGoods( req map[string]string,zy bool,classList *model.ZhyClassList,classLight []*model.ZhyClassListModel,aType byte){
var (
goods_name_arr []map[string]string
keyword string
)
keyword = ""
goods_name_arr = make([]map[string]string,0)
if req["goods_name/condition"] != "" {
goodsNameCondition := strings.ToUpper(req["goods_name/condition"])
......@@ -147,26 +152,174 @@ func searchZiYingGoods( req map[string]string,zy bool,classList *model.ZhyClassL
}
//index := config.Get("ZIYING_CONFIG")
upper_field := []string{"goods_name","encap","packing","brand_name"}
int_field := []string{"status","class_id2","class_id1","single_price","stock","goods_id","goods_type","sort",
"brand_id","sample_class_id","sample_status","sample_max_number"}
upper_field=upper_field
int_field=int_field
goods_temp_status := 0
source := elastic.NewSearchSource()
source.StoredFields("goods_id","goods_name","sample_max_number","sample_status","sample_class_id")
query := elastic.NewBoolQuery()
fmt.Println(query)
for k,v:=range req{
k_temp := make([]string,0)
v = v
if strings.Contains(k,"/"){
k_temp = strings.Split(k,"/")
fmt.Println(k_temp)
if(len(req) > 0){
for k,v:=range req{
k_temp := make([]string,0)
if strings.Contains(k,"/") {
k_temp = strings.Split(k,"/")
if len(k_temp) == 2 {
isok := makeQuery(query,k_temp,&goods_temp_status,&v,&keyword)
if !isok {
continue;
}
}
}
}
}
source.Query(query)
res,_ := elastic.NewSearchRequest().Source(source).Body()
fmt.Println(res)
}
func makeQuery(query *elastic.BoolQuery,conditions []string,goods_temp_status *int,searchValue *string,keyword *string) bool{
var (
err error
stockValue int64
term_v []string
)
upper_field := []string{"goods_name","encap","packing","brand_name"}
int_field := []string{"status","class_id2","class_id1","single_price","stock","goods_id","goods_type","sort",
"brand_id","sample_class_id","sample_status","sample_max_number"}
upper_field = upper_field
int_field = int_field
searchKey := conditions[0]
searchCondition := conditions[1]
redisConn :=gredis.Conn("search_r")
defer func(){
redisConn.Close()
}()
switch searchCondition{
case "condition":
//status
if searchKey == "status"{
*goods_temp_status = 1
}
if searchKey != "status" && searchCondition == ""{
return false;
}
//goods_name
if searchKey == "goods_name"{
//fmt.Println(5569)
strNo := []string{"/" , "," ,"、" ,"?" , "," , ":",",","?",",","、",":"}
for _,strNoV:=range strNo{
*searchValue = php2go.StrReplace(string(strNoV)," ",*searchValue,-1)
}
//获取正式替换关键词
preg_arr := config.Cfg.Section("SEARCH_KEYWORD_MAPPING").KeysHash()
for pk,pv:=range preg_arr{
reg := regexp.MustCompile(pk)
*searchValue = reg.ReplaceAllString(*searchValue, pv)
}
//提取带有小数点的数字去掉.0小数
reg := regexp.MustCompile(`((\d+)\.(\d+))`)
all_ix := reg.FindAllSubmatch([]byte(*searchValue),-1)
for _,v := range all_ix{
if string(v[len(v)-1]) == "0"{
*searchValue = strings.Replace(*searchValue,".0","",-1)
break
}
}
fmt.Println(*searchValue)
keywordUper := strings.ToUpper(*searchValue)
mathExactGoodsName := config.Cfg.Section("mathExactGoodsName").KeysHash()
for _,v:=range mathExactGoodsName{
if keywordUper == v{
query.Must(elastic.NewTermQuery("auto_goods_name.raw", keywordUper))
*keyword = *searchValue
return false
}
}
skuMapStr,err := redis.String(redisConn.Do("Hget","sku_map",keywordUper))
if(err == nil || skuMapStr != ""){
filterNestedAttrsBoolQuery := elastic.NewBoolQuery()
skuMapSlice := strings.Split(skuMapStr,",")
for _,v := range skuMapSlice{
filterNestedAttrsBoolQuery.Should(elastic.NewMatchQuery("attrs.attr_value",v))
}
query.Filter(elastic.NewNestedQuery("attrs",filterNestedAttrsBoolQuery))
*keyword = skuMapStr
return false
}
//提取汉子
reg = regexp.MustCompile(`[\p{Han}]+`)
goods_name_cn := reg.FindAllString(*searchValue,-1)
if len(goods_name_cn) > 0 {
for k,v :=range goods_name_cn{
goods_name_cn[k] = strings.TrimSpace(v)
}
}
//去除汉字,并以空格分词条
reg = regexp.MustCompile(`[\P{Han}]+`)
term_v =reg.FindAllString(*searchValue, -1)
if len(term_v) > 0 {
for k,v :=range term_v{
term_v[k] = strings.TrimSpace(v)
}
}
goods_name_arr := append(term_v,goods_name_cn...)
fmt.Println("goods_name_arr",goods_name_arr)
*keyword = *searchValue
fmt.Println("goods_name",term_v)
if len(goods_name_arr) > 0{
query.Must(elastic.NewMatchQuery("goods_name_cn",strings.Join(goods_name_cn," ")).MinimumShouldMatch("100%"))
}
}else{
term_v = strings.Split(*searchValue,",")
}
//fmt.Println(term_v)
*searchValue = strings.ToUpper(strings.TrimSpace(*searchValue))
if searchKey == "brand_name"{
reg := regexp.MustCompile(`[[:^alnum:]]+`)
if len(term_v) > 0{
for k,v:=range term_v{
term_v[k] = reg.ReplaceAllString(v,"")
}
query.Must(elastic.NewTermsQuery("auto_brand_name2",term_v))
}
}
//stock
if searchKey == "stock"{
if stockValue,err = strconv.ParseInt(*searchValue, 10, 64);err == nil{
if stockValue > 1000000 {
stockValue = 1000000
}
query.Must(elastic.NewRangeQuery("stock").Gte(stockValue))
}
}
case "range":
case "sr":
case "nested":
case "eq":
}
}
return true
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment