浏览代码

feat:修改查询语句

wangchuanjin 2 年之前
父节点
当前提交
6f55523ae3
共有 2 个文件被更改,包括 19 次插入20 次删除
  1. 11 11
      common/src/qfw/util/bidsearch/search.go
  2. 8 9
      common/src/qfw/util/dataexport/dataexport.go

+ 11 - 11
common/src/qfw/util/bidsearch/search.go

@@ -1,8 +1,6 @@
 package bidsearch
 
 import (
-	"app.yhyue.com/moapp/jybase/go-xweb/httpsession"
-	"app.yhyue.com/moapp/jypkg/middleground"
 	"fmt"
 	"log"
 	"net/http"
@@ -10,6 +8,9 @@ import (
 	"strings"
 	"time"
 
+	"app.yhyue.com/moapp/jybase/go-xweb/httpsession"
+	"app.yhyue.com/moapp/jypkg/middleground"
+
 	. "app.yhyue.com/moapp/jybase/encrypt"
 	"app.yhyue.com/moapp/jypkg/public"
 
@@ -269,8 +270,8 @@ func GetSearchQuery(keyword, industry, minprice, maxprice, hasBuyerTel, hasWinne
 	query_bool_should := `{"bool":{"should":[%s],"minimum_should_match": 1}}`
 	query_bools_must := `{"bool":{"must":[{"range":{"bidamount":{%s}}}]}},{"bool":{"must":[{"range":{"budget":{%s}}}],"must_not":[{"range":{"bidamount":{"gte":-1}}}]}}`
 	query_bool_must := `{"bool":{"must":[{"terms":{"s_subscopeclass":[%s]}}]}}`
-	query_missing := `{"constant_score":{"filter":{"missing":{"field":"%s"}}}}`
-	query_bool_must_term := `{"bool": {"must": [{ "term": {"isValidFile": %d }}]}}`
+	query_exists := `{"constant_score":{"filter":{"exists":{"field":"%s"}}}}`
+	query_bool_must_term := `{"bool": {"must": [{ "term": {"isValidFile": %t }}]}}`
 	query_bool_must_term_domain := `{"bool": {"must": [{ "term": {"bid_field": "%s" }}]}}` // 领域化数据类型
 	gte := `"gte": %s`
 	lte := `"lte": %s`
@@ -344,16 +345,16 @@ func GetSearchQuery(keyword, industry, minprice, maxprice, hasBuyerTel, hasWinne
 	}
 	if hasBuyerTel != "" {
 		if hasBuyerTel == "y" {
-			must_not = append(must_not, fmt.Sprintf(query_missing, "buyertel"))
+			musts = append(musts, fmt.Sprintf(query_exists, "buyertel"))
 		} else {
-			musts = append(musts, fmt.Sprintf(query_missing, "buyertel"))
+			must_not = append(must_not, fmt.Sprintf(query_exists, "buyertel"))
 		}
 	}
 	if hasWinnerTel != "" {
 		if hasWinnerTel == "y" {
-			must_not = append(must_not, fmt.Sprintf(query_missing, "winnertel"))
+			musts = append(musts, fmt.Sprintf(query_exists, "winnertel"))
 		} else {
-			musts = append(musts, fmt.Sprintf(query_missing, "winnertel"))
+			must_not = append(must_not, fmt.Sprintf(query_exists, "winnertel"))
 		}
 	}
 	if notkey = strings.TrimSpace(notkey); notkey != "" {
@@ -376,10 +377,9 @@ func GetSearchQuery(keyword, industry, minprice, maxprice, hasBuyerTel, hasWinne
 	}
 	if !isFileSearch && fileExists != "" {
 		if fileExists == "1" { //有附件
-			must_not = append(must_not, fmt.Sprintf(query_missing, "isValidFile"))
-			musts = append(musts, fmt.Sprintf(query_bool_must_term, 1))
+			musts = append(musts, fmt.Sprintf(query_bool_must_term, true))
 		} else if fileExists == "-1" { //无附件
-			musts = append(musts, fmt.Sprintf(query_missing, "isValidFile"))
+			must_not = append(must_not, fmt.Sprintf(query_bool_must_term, true))
 		}
 	}
 	// 如果是领域化数据则需要加标签

+ 8 - 9
common/src/qfw/util/dataexport/dataexport.go

@@ -118,8 +118,8 @@ func getDataExportSql(scd *SieveCondition) string {
 	query_price := `{"bool":{"must":[{"range":{"bidamount":{%s}}}]}},{"bool":{"must":[{"range":{"budget":{%s}}}],"must_not":[{"range":{"bidamount":{"gte":-1}}}]}}`
 	query_bool_must := `{"terms":{"%s":[%s]}}`
 	query_bool_must_and := `{"bool":{"must":[%s]%s}}`
-	query_missing := `{"constant_score":{"filter":{"missing":{"field":"%s"}}}}`
-	query_bool_must_term := `{"bool": {"must": [{ "term": {"isValidFile": %d }}]}}`
+	query_exists := `{"constant_score":{"filter":{"exists":{"field":"%s"}}}}`
+	query_bool_must_term := `{"bool": {"must": [{ "term": {"isValidFile": %t }}]}}`
 	query_bool_must_term_bidField := `{"bool": {"must": [{ "term": {"bid_field": "%s" }}]}}` // 领域化数据类型
 
 	gte := `"gte": %s`
@@ -429,16 +429,16 @@ func getDataExportSql(scd *SieveCondition) string {
 	}
 	if scd.HasBuyerTel != "" {
 		if scd.HasBuyerTel == "y" {
-			must_not = append(must_not, fmt.Sprintf(query_missing, "buyertel"))
+			musts = append(musts, fmt.Sprintf(query_exists, "buyertel"))
 		} else {
-			musts = append(musts, fmt.Sprintf(query_missing, "buyertel"))
+			must_not = append(must_not, fmt.Sprintf(query_exists, "buyertel"))
 		}
 	}
 	if scd.HasWinnerTel != "" {
 		if scd.HasWinnerTel == "y" {
-			must_not = append(must_not, fmt.Sprintf(query_missing, "winnertel"))
+			musts = append(musts, fmt.Sprintf(query_exists, "winnertel"))
 		} else {
-			musts = append(musts, fmt.Sprintf(query_missing, "winnertel"))
+			must_not = append(must_not, fmt.Sprintf(query_exists, "winnertel"))
 		}
 	}
 
@@ -447,10 +447,9 @@ func getDataExportSql(scd *SieveCondition) string {
 	var isFileSearch = strings.ReplaceAll(selectType, ",", "\",\"") == "filetext"
 	if !isFileSearch && scd.FileExists != "" {
 		if scd.FileExists == "1" { //有附件
-			must_not = append(must_not, fmt.Sprintf(query_missing, "isValidFile"))
-			musts = append(musts, fmt.Sprintf(query_bool_must_term, 1))
+			musts = append(musts, fmt.Sprintf(query_bool_must_term, true))
 		} else if scd.FileExists == "-1" { //无附件
-			musts = append(musts, fmt.Sprintf(query_missing, "isValidFile"))
+			must_not = append(must_not, fmt.Sprintf(query_bool_must_term, true))
 		}
 	}
 	// 如果是领域化数据则需要加标签