|
@@ -31,6 +31,8 @@ type EnterpriseSearch struct {
|
|
|
PageNum int //页码
|
|
|
IsVip bool //是否是会员
|
|
|
IsFree bool //是否免费用户
|
|
|
+ //ZhiMa map[string]interface{}
|
|
|
+ ZhiMa string
|
|
|
}
|
|
|
|
|
|
const (
|
|
@@ -40,7 +42,7 @@ const (
|
|
|
entSearchCacheKey = "entSearchIndexCache_%v"
|
|
|
|
|
|
index, itype = "qyxy", "qyxy"
|
|
|
- entQuery = `{"query":{"bool":{"must":[%s],"must_not":[%s]}},"_source":["_id","company_name","company_status","legal_person","capital","company_address","company_shortname","company_phone","establish_date","nseo_id","currency"],"sort":[{"capital":{"order":"desc"}}]}`
|
|
|
+ entQuery = `{"query":{"bool":{"must":[%s],"must_not":[%s]}},"_source":["_id","company_name","company_status","legal_person","capital","company_address","company_shortname","company_phone","establish_date","nseo_id","currency","zhima_labels"],"sort":[{"capital":{"order":"desc"}}]}`
|
|
|
entQueryCount = `{"query":{"bool":{"must":[%s],"must_not":[%s]}}}`
|
|
|
)
|
|
|
|
|
@@ -116,6 +118,7 @@ func (es *EnterpriseSearch) Check() (*EnterpriseSearch, error) {
|
|
|
if es.EntContact != "" && !(es.EntContact == "1" || es.EntContact == "2" || es.EntContact == "3" || es.EntContact == "4") {
|
|
|
es.EntContact = ""
|
|
|
}
|
|
|
+
|
|
|
return es, nil
|
|
|
}
|
|
|
|
|
@@ -130,7 +133,8 @@ func (es *EnterpriseSearch) isEmptySearch() bool {
|
|
|
es.Establish == "" &&
|
|
|
es.BiddingArea == "" &&
|
|
|
es.EntClass == "" &&
|
|
|
- es.EntContact == "" {
|
|
|
+ es.EntContact == "" &&
|
|
|
+ es.ZhiMa == "" {
|
|
|
return true
|
|
|
}
|
|
|
return false
|
|
@@ -249,6 +253,111 @@ func (es *EnterpriseSearch) GetQuerySql() (string, string) {
|
|
|
if es.EntContact != "" && es.IsVip {
|
|
|
musts = append(musts, fmt.Sprintf(`{"term":{"bid_contracttype":"%s"}}`, es.EntContact))
|
|
|
}
|
|
|
+ //芝麻实力标
|
|
|
+ if es.ZhiMa != "" {
|
|
|
+ var (
|
|
|
+ thisQuery, topType, subType, names []string
|
|
|
+ //name存在数据
|
|
|
+ name1 = `{
|
|
|
+ "bool": {
|
|
|
+ "must": [
|
|
|
+ {
|
|
|
+ "term": {
|
|
|
+ "zhima_labels.zhima_toptype": "%s"
|
|
|
+ }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "term": {
|
|
|
+ "zhima_labels.zhima_subtype": "%s"
|
|
|
+ }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "terms": {
|
|
|
+ "zhima_labels.zhima_name": ["%s"]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ }`
|
|
|
+ //部分name存在 部分不存在name 数据时
|
|
|
+ name2 = `{
|
|
|
+ "bool": {
|
|
|
+ "must": [
|
|
|
+ {
|
|
|
+ "term": {
|
|
|
+ "zhima_labels.zhima_toptype": "%s"
|
|
|
+ }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "term": {
|
|
|
+ "zhima_labels.zhima_subtype": "%s"
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ }`
|
|
|
+ //name不存在数据
|
|
|
+ name3 = `{
|
|
|
+ "bool": {
|
|
|
+ "must": [
|
|
|
+ {
|
|
|
+ "term": {
|
|
|
+ "zhima_labels.zhima_toptype": "%s"
|
|
|
+ }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "terms": {
|
|
|
+ "zhima_labels.zhima_subtype": ["%s"]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ }`
|
|
|
+ //sub不存在数据
|
|
|
+ name4 = `{"terms":{"zhima_labels.zhima_toptype":["%s"]}}`
|
|
|
+ )
|
|
|
+ zhiMaMap := qutil.ObjToMap(es.ZhiMa)
|
|
|
+ for s, i := range *zhiMaMap {
|
|
|
+ iMap := qutil.StructToMapMore(i)
|
|
|
+ if iMap != nil && len(iMap) > 0 {
|
|
|
+ var (
|
|
|
+ isSub bool
|
|
|
+ isSubType []string
|
|
|
+ sbt []string
|
|
|
+ )
|
|
|
+ for s2, i2 := range iMap {
|
|
|
+ strName, _ := i2.([]interface{})
|
|
|
+ if strName != nil && len(strName) > 0 {
|
|
|
+ isSub = true
|
|
|
+ name := qutil.ObjArrToStringArr(strName)
|
|
|
+ names = append(names, fmt.Sprintf(name1, s, s2, strings.Join(name, `","`)))
|
|
|
+ } else {
|
|
|
+ sbt = append(sbt, s2)
|
|
|
+ isSubType = append(isSubType, fmt.Sprintf(name2, s, s2))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if !isSub { //校验是否name下数据
|
|
|
+ subType = append(subType, fmt.Sprintf(name3, s, strings.Join(sbt, `","`)))
|
|
|
+ } else {
|
|
|
+ subType = append(subType, isSubType...)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ topType = append(topType, fmt.Sprintf(name4, s))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if topType != nil {
|
|
|
+ thisQuery = append(thisQuery, topType...)
|
|
|
+ }
|
|
|
+ if subType != nil {
|
|
|
+ thisQuery = append(thisQuery, subType...)
|
|
|
+ //thisQuery = append(thisQuery, fmt.Sprintf(`{"terms":{"zhima_labels.zhima_subtype":["%s"]}}`, strings.Join(subType, `","`)))
|
|
|
+ }
|
|
|
+ if names != nil {
|
|
|
+ thisQuery = append(thisQuery, names...)
|
|
|
+ //thisQuery = append(thisQuery, fmt.Sprintf(`{"terms":{"zhima_labels.zhima_name":["%s"]}}`, strings.Join(names, `","`)))
|
|
|
+ }
|
|
|
+ musts = append(musts, fmt.Sprintf(`{"nested":{"path":"zhima_labels","query": {"bool":{"should":[%s],"minimum_should_match": 1}}}}`, strings.Join(thisQuery, ",")))
|
|
|
+ }
|
|
|
return fmt.Sprintf(entQueryCount, strings.Join(musts, ","), ""), fmt.Sprintf(entQuery, strings.Join(musts, ","), "")
|
|
|
}
|
|
|
|