张金坤 8 年之前
父節點
當前提交
f659f7b0c2
共有 1 個文件被更改,包括 4 次插入3 次删除
  1. 4 3
      common/src/qfw/util/elastic/elasticutil.go

+ 4 - 3
common/src/qfw/util/elastic/elasticutil.go

@@ -916,6 +916,7 @@ const (
 
 	FilterQuery_New  = `{"query":{"bool":{"must": [%s],"should":[%s%s]}}}`
 	MatchQueryString = `{"match": {%s: { "query":"%s", "operator": "and"}}}`
+	HL_New           = `"highlight": {"pre_tags": ["<HL>"],"post_tags": ["<HL>"],"fields": {%s}}`
 )
 
 func GetNgramQuery(query interface{}, mustquery, findfields string) (qstr string) {
@@ -1091,9 +1092,9 @@ func GetByNgramAll_New(index, itype string, querystring, querymust interface{},
 		if highlight {
 			ws := []string{}
 			for _, w := range strings.Split(findfields, ",") {
-				ws = append(ws, fmt.Sprintf(highlightStr, w, 1))
+				ws = append(ws, w+`:{"force_source": true}`)
 			}
-			qstr = qstr[:len(qstr)-1] + `,` + fmt.Sprintf(HL, strings.Join(ws, ",")) + `}`
+			qstr = qstr[:len(qstr)-1] + `,` + fmt.Sprintf(HL_New, strings.Join(ws, ",")) + `}`
 		}
 		if len(fields) > 0 {
 			qstr = qstr[:len(qstr)-1] + `,"_source":[` + fields + "]}"
@@ -1104,7 +1105,7 @@ func GetByNgramAll_New(index, itype string, querystring, querymust interface{},
 		if start > -1 {
 			qstr = qstr[:len(qstr)-1] + `,"from":` + strconv.Itoa(start) + `,"size":` + strconv.Itoa(limit) + "}"
 		}
-		//log.Println("ngram-find", qstr)
+		//log.Println("ngram-find", order, qstr)
 		return Get(index, itype, qstr)
 	} else {
 		return nil