wangshan 3 лет назад
Родитель
Сommit
0e822fe3e4
1 измененных файлов с 10 добавлено и 9 удалено
  1. 10 9
      jyBXCore/rpc/util/search.go

+ 10 - 9
jyBXCore/rpc/util/search.go

@@ -361,17 +361,18 @@ func GetSearchQuery(in *bxcore.SearchReq, mustquery string) (qstr string) {
 		if strings.Contains(findfields, "filetext") { //搜索范围选择附件,是否有附件条件无效;
 			isFileSearch = true
 		}
-		//标题 全文搜索 搜索类型开关打开 默认搜索全文;(全文包含标题)
-		if strings.Contains(findfields, "detail") && strings.Contains(findfields, "title") && IC.C.SearchTypeSwitch {
-			if strings.Contains(findfields, "title,") {
-				findfields = strings.Replace(findfields, "title,", "", -1)
-			} else if strings.Contains(findfields, ",title") {
-				findfields = strings.Replace(findfields, ",title", "", -1)
-			}
-		}
-		keyword_multi_match := fmt.Sprintf(multi_match, "%s", findfields)
 		shoulds := []string{}
+		var switchBool = strings.Contains(findfields, "detail") && strings.Contains(findfields, "title") && IC.C.SearchTypeSwitch
 		for _, v := range strings.Split(in.KeyWords, "+") {
+			//标题 全文搜索 搜索类型开关打开 默认搜索全文;(全文包含标题)(单字排除)
+			if switchBool && len([]rune(elastic.ReplaceYH(v))) > 1 {
+				if strings.Contains(findfields, "title,") {
+					findfields = strings.Replace(findfields, "title,", "", -1)
+				} else if strings.Contains(findfields, ",title") {
+					findfields = strings.Replace(findfields, ",title", "", -1)
+				}
+			}
+			keyword_multi_match := fmt.Sprintf(multi_match, "%s", findfields)
 			shoulds = append(shoulds, fmt.Sprintf(keyword_multi_match, elastic.ReplaceYH(v)))
 		}
 		musts = append(musts, fmt.Sprintf(elastic.NgramMust, strings.Join(shoulds, ",")))