|
@@ -14,25 +14,22 @@ import (
|
|
// GetSearchQuery 整理关键词等查询条件
|
|
// GetSearchQuery 整理关键词等查询条件
|
|
func GetSearchQuery(in *bxcore.SearchReq, mustQuery string) (qstr string) {
|
|
func GetSearchQuery(in *bxcore.SearchReq, mustQuery string) (qstr string) {
|
|
var (
|
|
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 {
|
|
if selectTypeArr == nil || len(selectTypeArr) == 0 {
|
|
findFields = `"title"`
|
|
findFields = `"title"`
|
|
} else {
|
|
} else {
|
|
findFields = fmt.Sprintf(`"%s"`, strings.Join(selectTypeArr, "\",\""))
|
|
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进行隔离
|
|
//此时关键词中间有IC.C.JYKeyMark进行隔离
|
|
if in.KeyWords != "" {
|
|
if in.KeyWords != "" {
|
|
var (
|
|
var (
|
|
@@ -58,7 +55,7 @@ func GetSearchQuery(in *bxcore.SearchReq, mustQuery string) (qstr string) {
|
|
}
|
|
}
|
|
//搜索关键词模式;默认0:包含所有,1:包含任意
|
|
//搜索关键词模式;默认0:包含所有,1:包含任意
|
|
if in.WordsMode == 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 {
|
|
} else {
|
|
wordsMusts = append(wordsMusts, keyWordsMusts...)
|
|
wordsMusts = append(wordsMusts, keyWordsMusts...)
|
|
}
|
|
}
|
|
@@ -97,15 +94,15 @@ func GetSearchQuery(in *bxcore.SearchReq, mustQuery string) (qstr string) {
|
|
}
|
|
}
|
|
//搜索关键词模式;默认0:包含所有,1:包含任意
|
|
//搜索关键词模式;默认0:包含所有,1:包含任意
|
|
if in.WordsMode == 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{}
|
|
addWordsMusts = []string{}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
//搜索关键词模式;默认0:包含所有,1:包含任意
|
|
//搜索关键词模式;默认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 {
|
|
} else if len(wordsMusts) > 0 {
|
|
musts = append(musts, fmt.Sprintf(elastic.NgramMust, strings.Join(wordsMusts, ",")))
|
|
musts = append(musts, fmt.Sprintf(elastic.NgramMust, strings.Join(wordsMusts, ",")))
|
|
}
|
|
}
|