wangshan před 2 roky
rodič
revize
637e14c49d
2 změnil soubory, kde provedl 17 přidání a 21 odebrání
  1. 3 4
      jyBXCore/rpc/entity/search.go
  2. 14 17
      jyBXCore/rpc/model/es/search.go

+ 3 - 4
jyBXCore/rpc/entity/search.go

@@ -119,7 +119,7 @@ func (kws *KeyWordsSearch) SaveKeyWordsToHistory(in *bxcore.SearchReq) {
 }
 
 // GetSearchKeyWordsQueryStr 关键词和附加词处理 获取关键词查询条件;是否进行分词查询
-func (kws *KeyWordsSearch) GetSearchKeyWordsQueryStr(in *bxcore.SearchReq) (words []string) {
+func (kws *KeyWordsSearch) GetSearchKeyWordsQueryStr(in *bxcore.SearchReq) (searchWords []string) {
 	// in.SearchMode 搜索模式:0:精准搜索;1:模糊搜索
 	// 精准搜索:不分词,完全匹配;(中间带空格的关键词组自动分词)
 	// 模糊搜索:对用户输入的单个关键词进行分词处理,但必须都存在;
@@ -130,9 +130,8 @@ func (kws *KeyWordsSearch) GetSearchKeyWordsQueryStr(in *bxcore.SearchReq) (word
 				in.KeyWords = ikWords
 			}
 		}
-		words = append(words, in.KeyWords)
+		searchWords = append(searchWords, in.KeyWords)
 	}
-	//附加词组
 	//多组附加词,每组间,号隔开。每组内如果关键词中间有空格,自动分词
 	if in.AdditionalWords != "" {
 		if in.SearchMode == 1 {
@@ -150,7 +149,7 @@ func (kws *KeyWordsSearch) GetSearchKeyWordsQueryStr(in *bxcore.SearchReq) (word
 				in.AdditionalWords = strings.Join(addWords, ",")
 			}
 		}
-		words = append(words, strings.Split(in.AdditionalWords, ",")...)
+		searchWords = append(searchWords, strings.Split(in.AdditionalWords, ",")...)
 	}
 	return
 }

+ 14 - 17
jyBXCore/rpc/model/es/search.go

@@ -14,25 +14,22 @@ import (
 // GetSearchQuery  整理关键词等查询条件
 func GetSearchQuery(in *bxcore.SearchReq, mustQuery string) (qstr string) {
 	var (
-		musts, mustNot []string
+		//搜索范围是否只有附件
+		//搜索范围只选择附件,是否有附件条件无效;
+		isFileSearch                            = in.SelectType == "filetext"
+		wordsMusts, wordsShould, musts, mustNot []string
+		findFields                              string
+		selectTypeArr                           = strings.Split(in.SelectType, ",")
 	)
-	if mustQuery != "" {
-		musts = append(musts, mustQuery)
-	}
-	//搜索范围是否只有附件
-	//搜索范围只选择附件,是否有附件条件无效;
-	var isFileSearch bool = in.SelectType == "filetext"
-	selectTypeArr := strings.Split(in.SelectType, ",")
-	var findFields string
 	if selectTypeArr == nil || len(selectTypeArr) == 0 {
 		findFields = `"title"`
 	} else {
 		findFields = fmt.Sprintf(`"%s"`, strings.Join(selectTypeArr, "\",\""))
 	}
-	var (
-		wordsMusts, wordsShoulds []string
-		switchBool               = strings.Contains(findFields, "detail") && strings.Contains(findFields, "title") && IC.C.SearchTypeSwitch
-	)
+	switchBool := strings.Contains(findFields, "detail") && strings.Contains(findFields, "title") && IC.C.SearchTypeSwitch
+	if mustQuery != "" {
+		musts = append(musts, mustQuery)
+	}
 	//此时关键词中间有IC.C.JYKeyMark进行隔离
 	if in.KeyWords != "" {
 		var (
@@ -58,7 +55,7 @@ func GetSearchQuery(in *bxcore.SearchReq, mustQuery string) (qstr string) {
 		}
 		//搜索关键词模式;默认0:包含所有,1:包含任意
 		if in.WordsMode == 1 {
-			wordsShoulds = append(wordsShoulds, fmt.Sprintf(elastic.NgramMust, strings.Join(keyWordsMusts, ",")))
+			wordsShould = append(wordsShould, fmt.Sprintf(elastic.NgramMust, strings.Join(keyWordsMusts, ",")))
 		} else {
 			wordsMusts = append(wordsMusts, keyWordsMusts...)
 		}
@@ -97,15 +94,15 @@ func GetSearchQuery(in *bxcore.SearchReq, mustQuery string) (qstr string) {
 			}
 			//搜索关键词模式;默认0:包含所有,1:包含任意
 			if in.WordsMode == 1 {
-				wordsShoulds = append(wordsShoulds, fmt.Sprintf(elastic.NgramMust, strings.Join(addWordsMusts, ",")))
+				wordsShould = append(wordsShould, fmt.Sprintf(elastic.NgramMust, strings.Join(addWordsMusts, ",")))
 				addWordsMusts = []string{}
 			}
 		}
 	}
 	//搜索关键词模式;默认0:包含所有,1:包含任意
 	//包含任意一组
-	if len(wordsShoulds) > 0 {
-		musts = append(musts, fmt.Sprintf(queryBoolShould, strings.Join(wordsShoulds, ",")))
+	if len(wordsShould) > 0 {
+		musts = append(musts, fmt.Sprintf(queryBoolShould, strings.Join(wordsShould, ",")))
 	} else if len(wordsMusts) > 0 {
 		musts = append(musts, fmt.Sprintf(elastic.NgramMust, strings.Join(wordsMusts, ",")))
 	}