|
@@ -84,6 +84,40 @@ func SubViewDatasCount(userId, item string, index int) int64 {
|
|
|
return elastic.Count(INDEX, TYPE, qstr)
|
|
|
}
|
|
|
|
|
|
+/*某组关键词-推送结果预览总数
|
|
|
+ *@param userId 用户id
|
|
|
+ *@param key 关键词
|
|
|
+ *@param notkey 排除词
|
|
|
+ *@param matchway 0:精准 1:模糊
|
|
|
+ */
|
|
|
+func KeysetViewDatasCount(userId, key, notkey string, matchway int) int64 {
|
|
|
+ key = strings.TrimSpace(key)
|
|
|
+ notkey = strings.TrimSpace(notkey)
|
|
|
+ if key == "" {
|
|
|
+ return 0
|
|
|
+ }
|
|
|
+ sql := GetSqlObjFromId(userId, "", -1)
|
|
|
+ viewKeyWords := []ViewKeyWord{}
|
|
|
+ if matchway == 0 {
|
|
|
+ viewKeyWords = append(viewKeyWords, ViewKeyWord{
|
|
|
+ Keyword: strings.Split(key, " "),
|
|
|
+ Exclude: strings.Split(notkey, " "),
|
|
|
+ MatchWay: matchway,
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ for _, v := range strings.Split(key, " ") {
|
|
|
+ viewKeyWords = append(viewKeyWords, ViewKeyWord{
|
|
|
+ Keyword: []string{v},
|
|
|
+ Exclude: strings.Split(notkey, " "),
|
|
|
+ MatchWay: matchway,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ sql.Keyword = viewKeyWords
|
|
|
+ qstr := GetVIPViewSql(userId, sql)
|
|
|
+ return elastic.Count(INDEX, TYPE, qstr)
|
|
|
+}
|
|
|
+
|
|
|
//获取vip订阅预览的查询语句
|
|
|
func GetVIPViewSql(userId string, scd *ViewCondition) string {
|
|
|
query := `{"query":{"bool":{"must":[%s],"should":[%s],"minimum_should_match": %d}}}`
|
|
@@ -161,15 +195,27 @@ func GetVIPViewSql(userId string, scd *ViewCondition) string {
|
|
|
must_not := []string{}
|
|
|
//附加词
|
|
|
for _, vv := range v.Keyword {
|
|
|
+ vv = strings.TrimSpace(vv)
|
|
|
+ if vv == "" {
|
|
|
+ continue
|
|
|
+ }
|
|
|
shoulds = append(shoulds, fmt.Sprintf(multi_match, "\""+vv+"\""))
|
|
|
}
|
|
|
|
|
|
for _, vv := range v.Appended {
|
|
|
+ vv = strings.TrimSpace(vv)
|
|
|
+ if vv == "" {
|
|
|
+ continue
|
|
|
+ }
|
|
|
shoulds = append(shoulds, fmt.Sprintf(multi_match, "\""+vv+"\""))
|
|
|
}
|
|
|
|
|
|
//排除词
|
|
|
for _, vv := range v.Exclude {
|
|
|
+ vv = strings.TrimSpace(vv)
|
|
|
+ if vv == "" {
|
|
|
+ continue
|
|
|
+ }
|
|
|
must_not = append(must_not, fmt.Sprintf(multi_match, "\""+vv+"\""))
|
|
|
}
|
|
|
|