|
@@ -15,10 +15,6 @@ import (
|
|
|
es "github.com/olivere/elastic/v7"
|
|
|
)
|
|
|
|
|
|
-const (
|
|
|
- esv7_FilterQuery = `{"query": {"filtered": {"filter": {"bool": {"must": [%s]}},%s}}`
|
|
|
-)
|
|
|
-
|
|
|
type EsV7 struct {
|
|
|
Address string
|
|
|
UserName string
|
|
@@ -31,7 +27,6 @@ type EsV7 struct {
|
|
|
|
|
|
//初始化es,带有用户名密码认证
|
|
|
func (e *EsV7) Init() {
|
|
|
- FilterQuery = esv7_FilterQuery
|
|
|
if e.Size <= 0 {
|
|
|
e.Size = SIZE
|
|
|
}
|
|
@@ -733,13 +728,7 @@ func (e *EsV7) GetByNgram(index, itype string, query interface{}, mustquery, fin
|
|
|
//增加高亮、过滤查询、高亮截取字数
|
|
|
func (e *EsV7) GetByNgramOther(index, itype string, query interface{}, mustquery, findfields, order, fields string, start, limit int, highlight bool, filtermode bool, count int) *[]map[string]interface{} {
|
|
|
defer catch()
|
|
|
- qstr := ""
|
|
|
- if mustquery != "" && filtermode {
|
|
|
- qstr = e.GetNgramQuery(query, "", findfields)
|
|
|
- qstr = fmt.Sprintf(FilterQuery, mustquery, qstr[1:])
|
|
|
- } else {
|
|
|
- qstr = e.GetNgramQuery(query, mustquery, findfields)
|
|
|
- }
|
|
|
+ qstr := e.GetNgramQuery(query, mustquery, findfields)
|
|
|
if qstr != "" {
|
|
|
if highlight {
|
|
|
ws := []string{}
|
|
@@ -768,13 +757,7 @@ func (e *EsV7) GetByNgramOther(index, itype string, query interface{}, mustquery
|
|
|
//替换了"号
|
|
|
func (e *EsV7) GetByNgramAll(index, itype string, query interface{}, mustquery, findfields, order, fields string, start, limit int, highlight bool, filtermode bool) *[]map[string]interface{} {
|
|
|
defer catch()
|
|
|
- qstr := ""
|
|
|
- if mustquery != "" && filtermode {
|
|
|
- qstr = e.GetNgramQuery(query, "", findfields)
|
|
|
- qstr = fmt.Sprintf(FilterQuery, mustquery, qstr[1:])
|
|
|
- } else {
|
|
|
- qstr = e.GetNgramQuery(query, mustquery, findfields)
|
|
|
- }
|
|
|
+ qstr := e.GetNgramQuery(query, mustquery, findfields)
|
|
|
if qstr != "" {
|
|
|
if highlight {
|
|
|
ws := []string{}
|
|
@@ -864,9 +847,7 @@ func (e *EsV7) GetResForJY(index, itype string, keys []KeyConfig, allquery, find
|
|
|
}
|
|
|
musts = append(musts, fmt.Sprintf(NgramMustAndNot, strings.Join(mq, ","), strings.Join(notmq, ",")))
|
|
|
}
|
|
|
- qstr = fmt.Sprintf(NgramStr, "", strings.Join(musts, ","))
|
|
|
-
|
|
|
- qstr = fmt.Sprintf(FilterQuery, allquery, qstr[1:])
|
|
|
+ qstr = fmt.Sprintf(NgramStr, allquery, strings.Join(musts, ","))
|
|
|
ws := []string{}
|
|
|
for _, w := range strings.Split(findfields, ",") {
|
|
|
ws = append(ws, fmt.Sprintf(highlightStr, w, 1))
|
|
@@ -989,9 +970,7 @@ func (e *EsV7) GetResForJYView(index, itype string, keys []KeyConfig, allquery,
|
|
|
}
|
|
|
musts = append(musts, fmt.Sprintf(NgramMustAndNot, strings.Join(mq, ","), strings.Join(notmq, ",")))
|
|
|
}
|
|
|
- qstr = fmt.Sprintf(NgramStr, "", strings.Join(musts, ","))
|
|
|
-
|
|
|
- qstr = fmt.Sprintf(FilterQuery, allquery, qstr[1:])
|
|
|
+ qstr = fmt.Sprintf(NgramStr, allquery, strings.Join(musts, ","))
|
|
|
ws := []string{}
|
|
|
for _, w := range strings.Split(findfields, ",") {
|
|
|
ws = append(ws, fmt.Sprintf(highlightStr, w, 1))
|