Commit 818d2023 by mushishixian

修复结果为空

parent f5879ea5
Showing with 50 additions and 1 deletions
......@@ -18,6 +18,23 @@ import (
func SearchAttr(attrOrigin, encap string) (goodsName string, err error) {
//先去切割参数得到参数列表
attrs := splitAttrs(attrOrigin)
//当切割出来的参数大于1个的时候,就要去针对每个参数进行里面再一次提纯
if len(attrs) > 1 {
for key, attr := range attrs {
attrs[key] = changeKeyword(attr)
//切割完以后,还要去对切割后的参数提取值,因为有可能参数没有分隔符
extractRes := extractAttr(attrs[key])
for ek, eAttr := range extractRes {
if ek == 0 {
attrs[key] = extractRes[0]
} else {
attrs = append(attrs, eAttr)
}
}
}
} else {
attrs = extractAttrsByStr(attrs[0])
}
var attrsSlice []string
//去转换每一个参数,得到去查询es的标准格式
for _, attr := range attrs {
......@@ -72,6 +89,34 @@ func splitAttrs(attrs string) (result []string) {
return
}
//提取参数
func extractAttr(attr string) []string {
regexpUnit := strings.Join(getNeedCheckUnit(), "|")
r, _ := regexp.Compile("(\\d+[\\/\\d. ]*|\\d)(" + regexpUnit + ")" + "")
res := r.FindAllString(attr, 100)
return res
}
//提取参数,从一个字符串里面,注意要提取出两个参数才当作是
func extractAttrsByStr(attr string) []string {
regexpUnit := strings.Join(getNeedCheckUnit(), "|")
r, _ := regexp.Compile("(\\d+[\\/\\d. ]*|\\d)(" + regexpUnit + ")" + "")
res := r.FindAllString(attr, 100)
if len(res) < 2 {
return []string{attr}
}
return res
}
func getNeedCheckUnit() (unitSlice []string) {
unitMapping := common.UnitValueMapping
for unit, _ := range unitMapping {
unitSlice = append(unitSlice, unit)
}
return
}
//将写法转成正规写法,转换单位,比如有的人喜欢将Ω输成欧姆或者O,所以要统一转成正常的Ω
func changeKeyword(attr string) (result string) {
regulars := common.KeywordRegular
......
......@@ -66,7 +66,9 @@ func AutoSpu(goodsName string) []string {
func getTermQuery(goodsName string) (query *elastic.BoolQuery) {
query = elastic.NewBoolQuery()
query.Filter(elastic.NewTermQuery("auto_goods_name", goodsName))
if config.Get("web.mode").String() != "debug" {
query.Filter(elastic.NewTermQuery("status", 1))
}
query.MustNot(elastic.NewTermQuery("brand_id", 0))
return query
}
......@@ -170,7 +172,9 @@ func getBomTermQuery(goodsName, brandName string, number int32, isRawSearch bool
field := "auto_goods_name"
query = query.Must(elastic.NewTermQuery(field, goodsName))
}
query = query.Filter(elastic.NewTermQuery("status", 1))
if config.Get("web.mode").String() != "debug" {
query.Filter(elastic.NewTermQuery("status", 1))
}
source := elastic.NewSearchSource().Query(query)
source.From(0)
if isRawSearch {
......
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