فهرست منبع

wip:搜索添加行业其他

wangshan 1 سال پیش
والد
کامیت
216152cb1d
2فایلهای تغییر یافته به همراه22 افزوده شده و 2 حذف شده
  1. 1 1
      jyBXCore/rpc/model/es/es.go
  2. 21 1
      jyBXCore/rpc/model/es/search.go

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

@@ -16,7 +16,7 @@ const (
 	query                   = `{"query":{"bool":{"must":[%s],"must_not":[%s]}}}`
 	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]}}]}}`
+	queryBoolMustScopeClass = `{"bool":{"should":[{"terms":{"s_subscopeclass":[%s]}},{"bool":{"must":[{"terms":{"s_topscopeclass":[%s]}},{"bool":{"must_not":[{"exists":{"field":"s_subscopeclass"}}]}}]}}],"minimum_should_match":1}}` //`{"bool":{"must":[{"terms":{"s_subscopeclass":[%s]}}]}}`
 	queryBoolMustTerm       = `{"bool": {"must": [{ "term": {"isValidFile": %t }}]}}`
 	queryBoolMustA          = `{"bool":{"must":[{"terms":{"%s":[%s]}}]}}`
 	queryExists             = `{"constant_score":{"filter":{"exists":{"field":"%s"}}}}`

+ 21 - 1
jyBXCore/rpc/model/es/search.go

@@ -149,7 +149,27 @@ func GetSearchQuery(in *bxcore.SearchReq, mustQuery string) (qstr string) {
 	}
 	//行业
 	if in.Industry != "" && isLogin {
-		musts = append(musts, fmt.Sprintf(queryBoolMust, `"`+strings.ReplaceAll(in.Industry, ",", `","`)+`"`))
+		var (
+			topSC []string
+			topQT bool
+		)
+		for _, sv := range strings.Split(in.Industry, ",") {
+			if strings.Contains(sv, "其他") {
+				if len(strings.Split(sv, "_")) > 1 {
+					topSC = append(topSC, strings.Split(sv, "_")[0])
+				} else {
+					topQT = true
+				}
+			}
+		}
+		if topQT {
+			mustNot = append(mustNot, `{"exists": {"field": "s_subscopeclass"}}`)
+		}
+		if len(topSC) > 0 {
+			musts = append(musts, fmt.Sprintf(queryBoolMustScopeClass, `"`+strings.ReplaceAll(in.Industry, ",", `","`)+`"`, `"`+strings.Join(topSC, `","`)+`"`))
+		} else {
+			musts = append(musts, fmt.Sprintf(queryBoolMustA, "s_subscopeclass", `"`+strings.ReplaceAll(in.Industry, ",", `","`)+`"`))
+		}
 	}
 	//价格
 	if in.Price != "" && len(strings.Split(in.Price, "-")) > 1 {