|
@@ -21,14 +21,106 @@ import (
|
|
|
)
|
|
|
|
|
|
const (
|
|
|
- INDEX = "forecast"
|
|
|
- TYPE = "forecast"
|
|
|
- bidSearch_sort = `{"yucetime":-1}`
|
|
|
- findfields = `"title"`
|
|
|
-
|
|
|
+ INDEX = "forecast"
|
|
|
+ TYPE = "forecast"
|
|
|
+ bidSearch_sort = `{"yucetime":-1}`
|
|
|
+ findfields = `"title"`
|
|
|
bidSearch_field = ``
|
|
|
+
|
|
|
+ forecastQuery = `{"query":{"filtered":{"filter":{"bool":{"must":[%s]}},"query":{"bool":{"should":[%s],"minimum_should_match":1}}}}}`
|
|
|
+ filter_must_time = `{"bool":{"should":[{"bool":{"must":[{"missing":{"field":"yuceendtime"}},{"range":{"yucetime":{"gte":%d}}}]}},{"bool":{"must":[{"exists":{"field":"yuceendtime"}},{"range":{"yuceendtime":{"gte":%d}}}]}}]}}`
|
|
|
+ filter_must_area_city = `{"bool":{"should":[%s]}}`
|
|
|
+ query_should_keys = `{"bool":{"must":[%s],"must_not":[%s]}}`
|
|
|
+ query_should_multi_match = `{"multi_match":{"query":"%s","type":"phrase","fields":["results.purchasing.mypurchasing"]}}`
|
|
|
)
|
|
|
|
|
|
+/**
|
|
|
+@author:王山
|
|
|
+@descript:中标项目预测
|
|
|
+@date:2022-03-08
|
|
|
+@demand:
|
|
|
+ 有yuceendtime字段,按照yuceendtime大于当前时间||无yuceendtime字段,按照yucetime字段最近三个月查询数据;
|
|
|
+ 另有省份、城市、采购单位类型等;from 赵龙玥
|
|
|
+**/
|
|
|
+func getForecastProjectSql(scd *util.ViewCondition) string {
|
|
|
+ musts := []string{}
|
|
|
+ bools := []string{}
|
|
|
+ musts = append(musts, fmt.Sprintf(filter_must_time, time.Now().AddDate(0, -3, 0).Unix(), time.Now().Unix()))
|
|
|
+ //省份
|
|
|
+ areaCity := []string{}
|
|
|
+ if len(scd.Area) > 0 {
|
|
|
+ areaquery := `{"terms":{"area":[`
|
|
|
+ for k, v := range scd.Area {
|
|
|
+ if k > 0 {
|
|
|
+ areaquery += `,`
|
|
|
+ }
|
|
|
+ areaquery += `"` + v + `"`
|
|
|
+ }
|
|
|
+ areaquery += `]}}`
|
|
|
+ areaCity = append(areaCity, areaquery)
|
|
|
+ }
|
|
|
+
|
|
|
+ //城市
|
|
|
+ if len(scd.City) > 0 {
|
|
|
+ areaquery := `{"terms":{"city":[`
|
|
|
+ for k, v := range scd.City {
|
|
|
+ if k > 0 {
|
|
|
+ areaquery += `,`
|
|
|
+ }
|
|
|
+ areaquery += `"` + v + `"`
|
|
|
+ }
|
|
|
+ areaquery += `]}}`
|
|
|
+ areaCity = append(areaCity, areaquery)
|
|
|
+ }
|
|
|
+ if len(areaCity) > 0 {
|
|
|
+ musts = append(musts, fmt.Sprintf(filter_must_area_city, strings.Join(areaCity, ",")))
|
|
|
+ }
|
|
|
+
|
|
|
+ //采购单位类型
|
|
|
+ if len(scd.Buyerclass) > 0 {
|
|
|
+ Buyerclass := `{"terms":{"buyerclass":[`
|
|
|
+ for k, v := range scd.Buyerclass {
|
|
|
+ if k > 0 {
|
|
|
+ Buyerclass += `,`
|
|
|
+ }
|
|
|
+ Buyerclass += `"` + v + `"`
|
|
|
+ }
|
|
|
+ Buyerclass += `]}}`
|
|
|
+ musts = append(musts, Buyerclass)
|
|
|
+ }
|
|
|
+
|
|
|
+ //should
|
|
|
+ if len(scd.Keyword) > 0 {
|
|
|
+ multi_match := query_should_multi_match
|
|
|
+ for _, v := range scd.Keyword {
|
|
|
+ bool_must := []string{}
|
|
|
+ bool_must_not := []string{}
|
|
|
+ //附加词
|
|
|
+ for _, vv := range v.Keyword {
|
|
|
+ bool_must = append(bool_must, fmt.Sprintf(multi_match, vv))
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, vv := range v.Appended {
|
|
|
+ bool_must = append(bool_must, fmt.Sprintf(multi_match, vv))
|
|
|
+ }
|
|
|
+
|
|
|
+ //排除词
|
|
|
+ for _, vv := range v.Exclude {
|
|
|
+ bool_must_not = append(bool_must_not, fmt.Sprintf(multi_match, vv))
|
|
|
+ }
|
|
|
+
|
|
|
+ //添加
|
|
|
+ if len(bool_must) > 0 {
|
|
|
+ bools = append(bools, fmt.Sprintf(query_should_keys, strings.Join(bool_must, ","), strings.Join(bool_must_not, ",")))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ qstr := fmt.Sprintf(forecastQuery, strings.Join(musts, ","), strings.Join(bools, ","))
|
|
|
+ log.Println("qstr:", qstr)
|
|
|
+ return qstr
|
|
|
+}
|
|
|
+
|
|
|
// ForPContent 预测详情页
|
|
|
func (this *Analysis) ForPContent() {
|
|
|
defer qutil.Catch()
|
|
@@ -263,7 +355,8 @@ func getNewForecast(userId string, pageNum int, o_member_jy map[string]interface
|
|
|
if len(keys) == 0 {
|
|
|
return
|
|
|
}
|
|
|
- qstr := GetMemberForecastSql(sql)
|
|
|
+ // qstr := GetMemberForecastSql(sql)
|
|
|
+ qstr := getForecastProjectSql(sql)
|
|
|
count = elastic.Count(INDEX, TYPE, qstr)
|
|
|
list = *elastic.GetAllByNgram(INDEX, TYPE, qstr, findfields, bidSearch_sort, bidSearch_field, (pageNum-1)*FP_Limit, FP_Limit, 0, false)
|
|
|
if list != nil {
|
|
@@ -294,7 +387,7 @@ func getNewForecast(userId string, pageNum int, o_member_jy map[string]interface
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-//获取大会员forecast 检索库查询语句
|
|
|
+//获取大会员forecast 检索库查询语句 - 查询逻辑有调整 dev4.6.8 -ws 新方法:getForecastProjectSql()
|
|
|
func GetMemberForecastSql(scd *util.ViewCondition) string {
|
|
|
query := `{"query":{"bool":{"must":[%s],"should":[%s],"minimum_should_match": %d}}}`
|
|
|
query_bool_should := `{"bool":{"should":[%s],"minimum_should_match": 1}}`
|
|
@@ -394,8 +487,6 @@ func GetMemberForecastSql(scd *util.ViewCondition) string {
|
|
|
return qstr
|
|
|
}
|
|
|
|
|
|
-//
|
|
|
-
|
|
|
//member_jy
|
|
|
func getSqlObjFromId(o_member_jy map[string]interface{}) *util.ViewCondition {
|
|
|
if o_member_jy["a_items"] == nil {
|