Browse Source

feat:修改es语句

wangchuanjin 2 years ago
parent
commit
7ae40ac13a
2 changed files with 8 additions and 9 deletions
  1. 2 2
      jyBXCore/rpc/model/es/es.go
  2. 6 7
      jyBXCore/rpc/model/es/search.go

+ 2 - 2
jyBXCore/rpc/model/es/es.go

@@ -16,8 +16,8 @@ const (
 	queryBoolShould         = `{"bool":{"should":[%s],"minimum_should_match": 1}}`
 	queryBoolMustBoolShould = `{"bool":{"must":[{"range":{"bidamount":{%s}}}]}},{"bool":{"must":[{"range":{"budget":{%s}}}],"must_not":[{"range":{"bidamount":{"gte":-1}}}]}}`
 	queryBoolMust           = `{"bool":{"must":[{"terms":{"s_subscopeclass":[%s]}}]}}`
-	queryBoolMustTerm       = `{"bool": {"must": [{ "term": {"isValidFile": %d }}]}}`
-	queryMissing            = `{"constant_score":{"filter":{"missing":{"field":"%s"}}}}`
+	queryBoolMustTerm       = `{"bool": {"must": [{ "term": {"isValidFile": %t }}]}}`
+	queryExists             = `{"constant_score":{"filter":{"exists":{"field":"%s"}}}}`
 	gte                     = `"gte": %s`
 	lte                     = `"lte": %s`
 	HighlightStr            = `"%s": {"fragment_size": %d,"number_of_fragments": 1}`

+ 6 - 7
jyBXCore/rpc/model/es/search.go

@@ -174,28 +174,27 @@ func GetSearchQuery(in *bxcore.SearchReq, mustQuery string) (qstr string) {
 	hasBuyerTel := in.BuyerTel
 	if hasBuyerTel != "" {
 		if hasBuyerTel == "y" {
-			mustNot = append(mustNot, fmt.Sprintf(queryMissing, "buyertel"))
+			musts = append(musts, fmt.Sprintf(queryExists, "buyertel"))
 		} else {
-			musts = append(musts, fmt.Sprintf(queryMissing, "buyertel"))
+			mustNot = append(mustNot, fmt.Sprintf(queryExists, "buyertel"))
 		}
 	}
 	//中标企业联系方式
 	hasWinnerTel := in.WinnerTel
 	if hasWinnerTel != "" {
 		if hasWinnerTel == "y" {
-			mustNot = append(mustNot, fmt.Sprintf(queryMissing, "winnertel"))
+			musts = append(musts, fmt.Sprintf(queryExists, "winnertel"))
 		} else {
-			musts = append(musts, fmt.Sprintf(queryMissing, "winnertel"))
+			mustNot = append(mustNot, fmt.Sprintf(queryExists, "winnertel"))
 		}
 	}
 	//附件
 	fileExists := in.FileExists
 	if !isFileSearch && fileExists != "" {
 		if fileExists == "1" { //有附件
-			mustNot = append(mustNot, fmt.Sprintf(queryMissing, "isValidFile"))
-			musts = append(musts, fmt.Sprintf(queryBoolMustTerm, 1))
+			musts = append(musts, fmt.Sprintf(queryBoolMustTerm, true))
 		} else if fileExists == "-1" { //无附件
-			musts = append(musts, fmt.Sprintf(queryMissing, "isValidFile"))
+			mustNot = append(mustNot, fmt.Sprintf(queryBoolMustTerm, true))
 		}
 	}
 	// 如果是领域化数据则需要加标签