|
@@ -329,6 +329,10 @@ func GetBidSearchQuery(in *bxcore.SearchReq) string {
|
|
|
return query
|
|
|
}
|
|
|
|
|
|
+//包含正文或 附件 不包含标题
|
|
|
+func DetailFileORTitle(findfields string) bool {
|
|
|
+ return (strings.Contains(findfields, `"detail"`) || strings.Contains(findfields, `"filetext"`)) && !strings.Contains(findfields, `"title"`)
|
|
|
+}
|
|
|
func GetSearchQuery(in *bxcore.SearchReq, mustquery string) (qstr string) {
|
|
|
multi_match := `{"multi_match": {"query": "%s","type": "phrase", "fields": [%s]}}`
|
|
|
query := `{"query":{"bool":{"must":[%s],"must_not":[%s]}}}`
|
|
@@ -357,20 +361,27 @@ func GetSearchQuery(in *bxcore.SearchReq, mustquery string) (qstr string) {
|
|
|
if in.KeyWords != "" {
|
|
|
shoulds := []string{}
|
|
|
var switchBool = strings.Contains(findfields, "detail") && strings.Contains(findfields, "title") && IC.C.SearchTypeSwitch
|
|
|
+ keyword_multi_match := fmt.Sprintf(multi_match, "%s", findfields)
|
|
|
for _, v := range strings.Split(in.KeyWords, "+") {
|
|
|
- //多个关键词 单个字 搜索范围只有全文
|
|
|
- if len(strings.Split(in.KeyWords, "+")) > 1 && len([]rune(elastic.ReplaceYH(v))) == 1 && findfields == `"detail"` {
|
|
|
+ if elastic.ReplaceYH(v) == "" {
|
|
|
continue
|
|
|
}
|
|
|
- //标题 全文搜索 搜索类型开关打开 默认搜索全文;(全文包含标题)(单字排除)
|
|
|
- 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)
|
|
|
+ if len([]rune(elastic.ReplaceYH(v))) == 1 {
|
|
|
+ //单个字 搜索范围 有全文或者附件 无标题 例如:学 虚拟机 detail 搜索的时候加上标题
|
|
|
+ if DetailFileORTitle(findfields) {
|
|
|
+ keyword_multi_match = fmt.Sprintf(multi_match, "%s", findfields+`"title"`)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //标题 全文搜索 搜索类型开关打开 默认搜索全文;(全文包含标题)(单字排除)
|
|
|
+ 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)
|
|
|
}
|
|
|
}
|
|
|
- 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, ",")))
|
|
@@ -439,6 +450,12 @@ func GetSearchQuery(in *bxcore.SearchReq, mustquery string) (qstr string) {
|
|
|
if v == "" {
|
|
|
continue
|
|
|
}
|
|
|
+ if len([]rune(elastic.ReplaceYH(v))) == 1 {
|
|
|
+ //单个字 搜索范围 有全文或者附件 无标题 例如:学 虚拟机 detail 搜索的时候加上标题
|
|
|
+ if DetailFileORTitle(findfields) {
|
|
|
+ notkey_multi_match = fmt.Sprintf(multi_match, "%s", findfields+`"title"`)
|
|
|
+ }
|
|
|
+ }
|
|
|
notkey_must_not = append(notkey_must_not, fmt.Sprintf(notkey_multi_match, elastic.ReplaceYH(v)))
|
|
|
}
|
|
|
must_not = append(must_not, fmt.Sprintf(query_bool_should, strings.Join(notkey_must_not, ",")))
|