Browse Source

feat:替换语句

wangchuanjin 2 years ago
parent
commit
528a068dac
2 changed files with 7 additions and 4 deletions
  1. 5 3
      es/es.go
  2. 2 1
      es/esv7.go

+ 5 - 3
es/es.go

@@ -9,6 +9,7 @@ import (
 	"math/big"
 	"math/big"
 	"net/http"
 	"net/http"
 	"reflect"
 	"reflect"
+	"regexp"
 	"runtime"
 	"runtime"
 	"strconv"
 	"strconv"
 	"strings"
 	"strings"
@@ -21,7 +22,7 @@ const (
 	SIZE            = 30
 	SIZE            = 30
 	FilterQuery     = `{"query": {"filtered": {"filter": {"bool": {"must": [%s]}},%s}}`
 	FilterQuery     = `{"query": {"filtered": {"filter": {"bool": {"must": [%s]}},%s}}`
 	QStr            = `{"query":{"bool":{"must":[$and],"must_not":[],"should":[$or],"minimum_should_match":1}}}`
 	QStr            = `{"query":{"bool":{"must":[$and],"must_not":[],"should":[$or],"minimum_should_match":1}}}`
-	NgramStr        = `{"query":{"bool":{"must":[%s],"should":[%s],"minimum_should_match": 1}}}`
+	NgramStr        = `{"query":{"bool":{"must":[%s],"should":[%s],"minimum_should_match":1}}}`
 	NgramMust       = `{"bool":{"must":[%s]}}`
 	NgramMust       = `{"bool":{"must":[%s]}}`
 	NgramMustAndNot = `{"bool":{"must":[%s],"must_not":[%s]}}`
 	NgramMustAndNot = `{"bool":{"must":[%s],"must_not":[%s]}}`
 	minq            = `{"multi_match": {"query": "%s","type": "phrase", "fields": [%s]}}`
 	minq            = `{"multi_match": {"query": "%s","type": "phrase", "fields": [%s]}}`
@@ -77,8 +78,9 @@ type Es interface {
 }
 }
 
 
 var (
 var (
-	SR    = strings.Replace
-	VarEs Es
+	SR        = strings.Replace
+	VarEs     Es
+	filterReg = regexp.MustCompile(`,\s*"should"\s*:\s*\[\s*\]\s*,\s*"minimum_should_match"\s*:\s*1`)
 )
 )
 
 
 type KeyConfig struct {
 type KeyConfig struct {

+ 2 - 1
es/esv7.go

@@ -145,7 +145,8 @@ func (e *EsV7) Get(index, itype, query string) *[]map[string]interface{} {
 	return r
 	return r
 }
 }
 func (e *EsV7) get(index, itype, searchType, query string, isLimit, isHighlight bool) (int64, int, *[]map[string]interface{}) {
 func (e *EsV7) get(index, itype, searchType, query string, isLimit, isHighlight bool) (int64, int, *[]map[string]interface{}) {
-	log.Println("query  -- ", query)
+	query = filterReg.ReplaceAllString(query, "")
+	//log.Println("query  -- ", query)
 	client := e.GetEsConn()
 	client := e.GetEsConn()
 	defer func() {
 	defer func() {
 		go e.DestoryEsConn(client)
 		go e.DestoryEsConn(client)