|
@@ -1,15 +1,15 @@
|
|
|
package marketAnalysis
|
|
|
|
|
|
import (
|
|
|
- "encoding/json"
|
|
|
"fmt"
|
|
|
- "log"
|
|
|
qutil "qfw/util"
|
|
|
"strings"
|
|
|
- "util"
|
|
|
)
|
|
|
|
|
|
-const localMultiMatch = `{"multi_match": {"query": %s,"type": "phrase", "fields": ["purchasing","pname"]}}`
|
|
|
+const (
|
|
|
+ localMultiMatch = `{"multi_match": {"query": %s,"type": "phrase", "fields": ["purchasing","pname"]}}`
|
|
|
+ query_bool_must_and = `{"bool": {"must": [%s]%s}}`
|
|
|
+)
|
|
|
|
|
|
//GetCommonQuerySql 公共筛选
|
|
|
func (mae *MarketAnalysisEntity) GetCommonQuerySql() string {
|
|
@@ -118,67 +118,3 @@ func getKeyWordSql(v viewKeyWord) string {
|
|
|
}
|
|
|
return ""
|
|
|
}
|
|
|
-
|
|
|
-//marketScaleRefineQuery 细化聚合
|
|
|
-func (mae *MarketAnalysisEntity) marketScaleRefineQuery() (rMap map[string]interface{}, err error) {
|
|
|
- //关键词分组聚合
|
|
|
- var aggsGroup []string
|
|
|
- itemDataMap := map[string]int64{}
|
|
|
- for _, group := range mae.FormatParam.KeysItems {
|
|
|
- var bools []string
|
|
|
- for _, v := range getGroupKeywordArr(group.A_Key) {
|
|
|
- if sql := getKeyWordSql(v); sql != "" {
|
|
|
- bools = append(bools, sql)
|
|
|
- }
|
|
|
- }
|
|
|
- if len(bools) > 0 {
|
|
|
- aggsGroup = append(aggsGroup, fmt.Sprintf(`"%s":{"filter":{"query":{"bool":{"should":[%s],"minimum_should_match": 1}}},"aggs":{"project_count":{"filter":{}},"project_amount":{"sum":{"field":"sortprice"}},"winner_total_top":{"terms":{"field":"s_winner","order":[{"refine_winner_total":"desc"}],"size":3},"aggs":{"refine_winner_total":{"filter":{}}}},"winner_amount_top":{"terms":{"field":"s_winner","order":[{"refine_winner_amount":"desc"}],"size":3},"aggs":{"refine_winner_amount":{"sum":{"field":"sortprice"}}}}}}`, group.ItemName, strings.Join(bools, ",")))
|
|
|
- }
|
|
|
- itemDataMap[group.ItemName] = group.UpdateTime
|
|
|
- }
|
|
|
- finalSql := fmt.Sprintf(mae.GetCommonQuerySqlWithAggs(), strings.Join(aggsGroup, ","))
|
|
|
- log.Printf("final marketScaleRefineQuery sql: %s", finalSql)
|
|
|
-
|
|
|
- rMap = map[string]interface{}{}
|
|
|
- res, docCount := util.GetAggs("projectset", "projectset", finalSql)
|
|
|
- if res == nil || len(res) == 0 {
|
|
|
- return
|
|
|
- }
|
|
|
- log.Println("xxxx", docCount, res)
|
|
|
- type scaleRefineRow struct {
|
|
|
- Total int64 `json:"doc_count"`
|
|
|
- Amount struct {
|
|
|
- Value float64 `json:"value"`
|
|
|
- } `json:"project_amount"`
|
|
|
- WinnerTotalTop []struct {
|
|
|
- Buckets []struct {
|
|
|
- Name string `json:"key"`
|
|
|
- Total int64 `json:"doc_count"`
|
|
|
- } `json:"buckets"`
|
|
|
- } `json:"winner_total_top"`
|
|
|
- WinnerAmountTop []struct {
|
|
|
- Buckets []struct {
|
|
|
- Name string `json:"key"`
|
|
|
- Amount struct {
|
|
|
- Value float64 `json:"value"`
|
|
|
- } `json:"refine_winner_amount"`
|
|
|
- } `json:"buckets"`
|
|
|
- } `json:"winner_amount_top"`
|
|
|
- UpdateTime int64 `json:"updateTime"`
|
|
|
- }
|
|
|
- for name, object := range res {
|
|
|
- bArr, err := object.MarshalJSON()
|
|
|
- if len(bArr) == 0 || err != nil {
|
|
|
- continue
|
|
|
- }
|
|
|
- thisRow := scaleRefineRow{}
|
|
|
- if json.Unmarshal(bArr, &thisRow) != nil {
|
|
|
- continue
|
|
|
- }
|
|
|
- thisRow.UpdateTime = itemDataMap[name]
|
|
|
- }
|
|
|
- rMap["scaleRefineAll"] = ""
|
|
|
- rMap["scaleRefineTotalTop"] = ""
|
|
|
- rMap["scaleRefineAmountTop"] = ""
|
|
|
- return
|
|
|
-}
|