|
@@ -67,93 +67,98 @@ func ScoreFields(j *ju.Job) map[string][]*ju.ExtField {
|
|
|
if len(fmt.Sprint(v.Value)) < 1 {
|
|
|
continue //空串跳过
|
|
|
}
|
|
|
- //类型打分
|
|
|
- if v.ExtFrom == "title" {
|
|
|
- v.Score += qu.IntAll(extractype["title"])
|
|
|
+ //长度超过100个字,直接负分
|
|
|
+ vlen := len([]rune(qu.ObjToString(v.Value)))
|
|
|
+ if vlen > 100 && field != "projectscope" {
|
|
|
+ v.Score = -1
|
|
|
} else {
|
|
|
- if strings.Contains(v.Type, "table") {
|
|
|
- v.Score += qu.IntAll(extractype["table"])
|
|
|
- } else if strings.Contains(v.Type, "colon") {
|
|
|
- v.Score += qu.IntAll(extractype["colon"])
|
|
|
- } else if strings.Contains(v.Type, "space") {
|
|
|
- v.Score += qu.IntAll(extractype["space"])
|
|
|
- } else if strings.Contains(v.Type, "regexp") {
|
|
|
- v.Score += qu.IntAll(extractype["regexp"])
|
|
|
- } else if strings.Contains(v.Type, "winnerorder") {
|
|
|
- v.Score += qu.IntAll(extractype["winnerorder"])
|
|
|
+ //类型打分
|
|
|
+ if v.ExtFrom == "title" {
|
|
|
+ v.Score += qu.IntAll(extractype["title"])
|
|
|
+ } else {
|
|
|
+ if strings.Contains(v.Type, "table") {
|
|
|
+ v.Score += qu.IntAll(extractype["table"])
|
|
|
+ } else if strings.Contains(v.Type, "colon") {
|
|
|
+ v.Score += qu.IntAll(extractype["colon"])
|
|
|
+ } else if strings.Contains(v.Type, "space") {
|
|
|
+ v.Score += qu.IntAll(extractype["space"])
|
|
|
+ } else if strings.Contains(v.Type, "regexp") {
|
|
|
+ v.Score += qu.IntAll(extractype["regexp"])
|
|
|
+ } else if strings.Contains(v.Type, "winnerorder") {
|
|
|
+ v.Score += qu.IntAll(extractype["winnerorder"])
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- //字符型打分
|
|
|
- if fieldtype == "string" {
|
|
|
- //位置打分
|
|
|
- if positions, ok := scoreRule["position"].([]interface{}); ok {
|
|
|
- for _, position := range positions {
|
|
|
- if p, ok := position.(map[string]interface{}); ok {
|
|
|
- qu.Try(func() {
|
|
|
- if p["regexp"] != nil {
|
|
|
- reg := p["regexp"].(*regexp.Regexp)
|
|
|
- if reg.MatchString(qu.ObjToString(v.Value)) {
|
|
|
- v.Score += qu.IntAll(p["score"])
|
|
|
+ //字符型打分
|
|
|
+ if fieldtype == "string" {
|
|
|
+ //位置打分
|
|
|
+ if positions, ok := scoreRule["position"].([]interface{}); ok {
|
|
|
+ for _, position := range positions {
|
|
|
+ if p, ok := position.(map[string]interface{}); ok {
|
|
|
+ qu.Try(func() {
|
|
|
+ if p["regexp"] != nil {
|
|
|
+ reg := p["regexp"].(*regexp.Regexp)
|
|
|
+ if reg.MatchString(qu.ObjToString(v.Value)) {
|
|
|
+ v.Score += qu.IntAll(p["score"])
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- }, func(err interface{}) {
|
|
|
- log.Println(err)
|
|
|
- })
|
|
|
+ }, func(err interface{}) {
|
|
|
+ log.Println(err)
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- //长度打分
|
|
|
- if lengths, ok := scoreRule["length"].([]interface{}); ok {
|
|
|
- for _, tmp := range lengths {
|
|
|
- if length, ok := tmp.(map[string]interface{}); ok {
|
|
|
- min := qu.IntAll(length["min"])
|
|
|
- max := qu.IntAll(length["max"])
|
|
|
- vlen := len([]rune(qu.ObjToString(v.Value)))
|
|
|
- scores, _ := length["score"].([]interface{})
|
|
|
- if len(scores) < 3 {
|
|
|
- continue
|
|
|
- }
|
|
|
- if vlen < min {
|
|
|
- v.Score += qu.IntAll(scores[0])
|
|
|
- } else if vlen > max {
|
|
|
- v.Score += qu.IntAll(scores[2])
|
|
|
- } else {
|
|
|
- v.Score += qu.IntAll(scores[1])
|
|
|
+ //长度打分
|
|
|
+ if lengths, ok := scoreRule["length"].([]interface{}); ok {
|
|
|
+ for _, tmp := range lengths {
|
|
|
+ if length, ok := tmp.(map[string]interface{}); ok {
|
|
|
+ min := qu.IntAll(length["min"])
|
|
|
+ max := qu.IntAll(length["max"])
|
|
|
+ scores, _ := length["score"].([]interface{})
|
|
|
+ if len(scores) < 3 {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ if vlen < min {
|
|
|
+ v.Score += qu.IntAll(scores[0])
|
|
|
+ } else if vlen > max {
|
|
|
+ v.Score += qu.IntAll(scores[2])
|
|
|
+ } else {
|
|
|
+ v.Score += qu.IntAll(scores[1])
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- //float类型打分
|
|
|
- if fieldtype == "float" {
|
|
|
- min := qu.IntAll(scoreRule["min"])
|
|
|
- max := qu.IntAll(scoreRule["max"])
|
|
|
- val := qu.IntAll(v.Value)
|
|
|
- scores, _ := scoreRule["score"].([]interface{})
|
|
|
- if len(scores) < 3 {
|
|
|
- continue
|
|
|
- }
|
|
|
- if val < min && 0 < val {
|
|
|
- v.Score += qu.IntAll(scores[0])
|
|
|
- } else if val > max {
|
|
|
- v.Score += qu.IntAll(scores[2])
|
|
|
- } else if val <= max && val >= min {
|
|
|
- v.Score += qu.IntAll(scores[1])
|
|
|
- }
|
|
|
- }
|
|
|
- //decimal
|
|
|
- if fieldtype == "decimal" {
|
|
|
- min := qu.IntAll(scoreRule["min"])
|
|
|
- max := qu.IntAll(scoreRule["max"])
|
|
|
- val := qu.IntAll(v.Value)
|
|
|
- scores, _ := scoreRule["score"].([]interface{})
|
|
|
- if len(scores) < 3 {
|
|
|
- continue
|
|
|
+ //float类型打分
|
|
|
+ if fieldtype == "float" {
|
|
|
+ min := qu.IntAll(scoreRule["min"])
|
|
|
+ max := qu.IntAll(scoreRule["max"])
|
|
|
+ val := qu.IntAll(v.Value)
|
|
|
+ scores, _ := scoreRule["score"].([]interface{})
|
|
|
+ if len(scores) < 3 {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ if val < min && 0 < val {
|
|
|
+ v.Score += qu.IntAll(scores[0])
|
|
|
+ } else if val > max {
|
|
|
+ v.Score += qu.IntAll(scores[2])
|
|
|
+ } else if val <= max && val >= min {
|
|
|
+ v.Score += qu.IntAll(scores[1])
|
|
|
+ }
|
|
|
}
|
|
|
- if val > max {
|
|
|
- v.Score += qu.IntAll(scores[2])
|
|
|
- } else if val <= max && val > min {
|
|
|
- v.Score += qu.IntAll(scores[1])
|
|
|
+ //decimal
|
|
|
+ if fieldtype == "decimal" {
|
|
|
+ min := qu.IntAll(scoreRule["min"])
|
|
|
+ max := qu.IntAll(scoreRule["max"])
|
|
|
+ val := qu.IntAll(v.Value)
|
|
|
+ scores, _ := scoreRule["score"].([]interface{})
|
|
|
+ if len(scores) < 3 {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ if val > max {
|
|
|
+ v.Score += qu.IntAll(scores[2])
|
|
|
+ } else if val <= max && val > min {
|
|
|
+ v.Score += qu.IntAll(scores[1])
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|