Эх сурвалжийг харах

Merge branch 'master' into feature/v1.0.30

yuelujie 4 сар өмнө
parent
commit
82d612df5f

+ 6 - 6
common/src/qfw/util/dataexport/dataexport.go

@@ -595,7 +595,7 @@ func GetDataExportSearchCountBySieveCondition(scd *SieveCondition, elasticAddres
 			}
 			if searchTextSize > 0 {
 				if secondKWS := jy.HttpEs(scd.Keyword[0].Keyword, "ik_smart", elasticAddress); secondKWS != "" {
-					scd.Keyword[0].Keyword = jy.KeywordsProcessing(strings.ReplaceAll(secondKWS, "+", " "), " ")
+					scd.Keyword[0].Keyword = jy.KeywordsProcessing(strings.ReplaceAll(secondKWS, "+", " "), scd.Keyword[0].Keyword, " ")
 				}
 			}
 			// 附加词分词
@@ -606,7 +606,7 @@ func GetDataExportSearchCountBySieveCondition(scd *SieveCondition, elasticAddres
 				}
 				if appendTextSize > 0 {
 					if secondKWS := jy.HttpEs(scd.Keyword[0].Appended[i], "ik_smart", elasticAddress); secondKWS != "" {
-						scd.Keyword[0].Appended[i] = jy.KeywordsProcessing(strings.ReplaceAll(secondKWS, "+", " "), " ")
+						scd.Keyword[0].Appended[i] = jy.KeywordsProcessing(strings.ReplaceAll(secondKWS, "+", " "), scd.Keyword[0].Appended[i], " ")
 					}
 				}
 			}
@@ -902,7 +902,7 @@ func GetDataExportIds(elasticAddress string, scd *SieveCondition, checkCount int
 			}
 			if searchTextSize > 0 {
 				if secondKWS := jy.HttpEs(scd.Keyword[0].Keyword, "ik_smart", elasticAddress); secondKWS != "" {
-					scd.Keyword[0].Keyword = jy.KeywordsProcessing(strings.ReplaceAll(secondKWS, "+", " "), " ")
+					scd.Keyword[0].Keyword = jy.KeywordsProcessing(strings.ReplaceAll(secondKWS, "+", " "), scd.Keyword[0].Keyword, " ")
 				}
 			}
 			// 附加词分词
@@ -913,7 +913,7 @@ func GetDataExportIds(elasticAddress string, scd *SieveCondition, checkCount int
 				}
 				if appendTextSize > 0 {
 					if secondKWS := jy.HttpEs(scd.Keyword[0].Appended[i], "ik_smart", elasticAddress); secondKWS != "" {
-						scd.Keyword[0].Appended[i] = jy.KeywordsProcessing(strings.ReplaceAll(secondKWS, "+", " "), " ")
+						scd.Keyword[0].Appended[i] = jy.KeywordsProcessing(strings.ReplaceAll(secondKWS, "+", " "), scd.Keyword[0].Appended[i], " ")
 					}
 				}
 			}
@@ -975,7 +975,7 @@ func GetDataExportSearchResult(bid mg.MongodbSim, bidMgoDBName, elasticAddress s
 			}
 			if searchTextSize > 0 {
 				if secondKWS := jy.HttpEs(scd.Keyword[0].Keyword, "ik_smart", elasticAddress); secondKWS != "" {
-					scd.Keyword[0].Keyword = jy.KeywordsProcessing(strings.ReplaceAll(secondKWS, "+", " "), " ")
+					scd.Keyword[0].Keyword = jy.KeywordsProcessing(strings.ReplaceAll(secondKWS, "+", " "), scd.Keyword[0].Keyword, " ")
 				}
 			}
 			// 附加词分词
@@ -986,7 +986,7 @@ func GetDataExportSearchResult(bid mg.MongodbSim, bidMgoDBName, elasticAddress s
 				}
 				if appendTextSize > 0 {
 					if secondKWS := jy.HttpEs(scd.Keyword[0].Appended[i], "ik_smart", elasticAddress); secondKWS != "" {
-						scd.Keyword[0].Appended[i] = jy.KeywordsProcessing(strings.ReplaceAll(secondKWS, "+", " "), " ")
+						scd.Keyword[0].Appended[i] = jy.KeywordsProcessing(strings.ReplaceAll(secondKWS, "+", " "), scd.Keyword[0].Appended[i], " ")
 					}
 				}
 			}

+ 31 - 6
common/src/qfw/util/jy/jy.go

@@ -431,11 +431,14 @@ func ClearUserCache(middleground *Middleground, positionId int64) {
 }
 
 // 关键词分词处理
-func KeywordsProcessing(keywords, sep string) string {
+func KeywordsProcessing(keywords, originalWord, sep string) string {
 	keywords = MatchSpace.ReplaceAllString(keywords, " ")
 	if keywords == "" || len(strings.Split(keywords, sep)) == 1 {
 		return keywords
 	}
+	if originalWord == "" {
+		originalWord = strings.ReplaceAll(keywords, sep, "")
+	}
 	var newWords = make([]string, 0, 0)
 	if keywords != "" && len(strings.Split(keywords, sep)) > 1 {
 		var words = strings.Split(keywords, sep)
@@ -448,14 +451,36 @@ func KeywordsProcessing(keywords, sep string) string {
 			if len([]rune(v)) == 1 {
 				//compare
 				if k == 0 { //first
-					words[k+1] = v + words[k+1]
+					newWord := v + words[k+1]
+					if strings.Contains(originalWord, newWord) { //组合后 必须包含
+						words[k+1] = newWord
+					}
 				} else if k == len(words)-1 { //last
-					newWords[len(newWords)-1] += v
+					newWord := newWords[len(newWords)-1] + v
+					if strings.Contains(originalWord, newWord) {
+						newWords[len(newWords)-1] = newWord
+					}
 				} else {
-					if len(newWords[len(newWords)-1]) < len(words[k+1]) {
-						newWords[len(newWords)-1] += v
+					if len([]rune(newWords[len(newWords)-1])) < len([]rune(words[k+1])) {
+						newWord := newWords[len(newWords)-1] + v
+						if strings.Contains(originalWord, newWord) {
+							newWords[len(newWords)-1] = newWord
+						} else {
+							newWord = v + words[k+1]
+							if strings.Contains(originalWord, newWord) { //组合后 必须包含
+								words[k+1] = newWord
+							}
+						}
 					} else {
-						words[k+1] = v + words[k+1]
+						newWord := v + words[k+1]
+						if strings.Contains(originalWord, newWord) { //组合后 必须包含
+							words[k+1] = newWord
+						} else {
+							newWord = newWords[len(newWords)-1] + v
+							if strings.Contains(originalWord, newWord) {
+								newWords[len(newWords)-1] = newWord
+							}
+						}
 					}
 				}
 			} else {