|
@@ -329,13 +329,15 @@ func isNullSearch(scd *SieveCondition) (isNull bool) {
|
|
|
* webdomain 三级页域名
|
|
|
* count 返回数量 (-1:预览数据查询)
|
|
|
*/
|
|
|
-func GetDataExportSearchResultUseId(_id, dataType string, count int) *[]map[string]interface{} {
|
|
|
+func GetDataExportSearchResultUseId(_id, dataType string, count int) (*[]map[string]interface{}, []KeyWord) {
|
|
|
defer util.Catch()
|
|
|
var res []map[string]interface{}
|
|
|
+ var kws []KeyWord
|
|
|
scd := getSqlObjFromId(_id)
|
|
|
//获取查询语句
|
|
|
qstr := getDataExportSql(scd)
|
|
|
|
|
|
+ kws = scd.Keyword
|
|
|
if count == -1 {
|
|
|
//数据预览数据查询
|
|
|
if scd.Comeinfrom == "supersearchPage" && len(scd.Keyword) == 0 && len(scd.Industry) == 0 {
|
|
@@ -349,7 +351,7 @@ func GetDataExportSearchResultUseId(_id, dataType string, count int) *[]map[stri
|
|
|
redis.Put("other", "export_news", res, 7200)
|
|
|
}
|
|
|
}
|
|
|
- return &res
|
|
|
+ return &res, kws
|
|
|
} else if scd.Comeinfrom == "supersearchPage" || scd.Comeinfrom == "exportPage" {
|
|
|
//超级搜索非空查询
|
|
|
count = int(elastic.Count(INDEX, TYPE, qstr))
|
|
@@ -366,7 +368,7 @@ func GetDataExportSearchResultUseId(_id, dataType string, count int) *[]map[stri
|
|
|
scd.Keyword[0].Keyword = secondKWS
|
|
|
qstr = getDataExportSql(scd)
|
|
|
res2 := doSearch(qstr, 0, 100-count, "")
|
|
|
- return delRepeatMapArr(res, res2)
|
|
|
+ return delRepeatMapArr(res, res2), kws
|
|
|
}
|
|
|
}
|
|
|
//非空查询
|
|
@@ -419,7 +421,7 @@ func GetDataExportSearchResultUseId(_id, dataType string, count int) *[]map[stri
|
|
|
}
|
|
|
res = *FormatExportData(&res, config.Sysconfig["webdomain"].(string), dataType, false)
|
|
|
}
|
|
|
- return &res
|
|
|
+ return &res, kws
|
|
|
}
|
|
|
|
|
|
func FormatExportData(data *[]map[string]interface{}, webdomain string, dataType string, isBreviary bool) *[]map[string]interface{} {
|
|
@@ -547,13 +549,33 @@ func getStringArrFromDbResult(c interface{}) (arr []string) {
|
|
|
}
|
|
|
|
|
|
//获取结果,空字段最少的数据
|
|
|
-func ScreenData(arr *[]map[string]interface{}, dataType string, resultNum int) (res []map[string]interface{}) {
|
|
|
+func ScreenData(arr *[]map[string]interface{}, dataType string, resultNum int, kws []KeyWord) (res []map[string]interface{}) {
|
|
|
AllMap := map[int][]map[string]interface{}{}
|
|
|
+
|
|
|
+ NoKwsMap := map[int][]map[string]interface{}{}
|
|
|
+ lastNum := resultNum
|
|
|
for _, v := range *arr {
|
|
|
emptyNum := countOfTheEmpty(v, dataType)
|
|
|
if emptyNum == -1 {
|
|
|
continue
|
|
|
}
|
|
|
+ if len(kws) > 0 && kws[0].Keyword != "" {
|
|
|
+ var kwsFlag = true
|
|
|
+ for _, vk := range kws {
|
|
|
+ if strings.Contains(util.ObjToString(v["title"]), vk.Keyword) {
|
|
|
+ kwsFlag = false
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if kwsFlag {
|
|
|
+ if NoKwsMap[emptyNum] == nil {
|
|
|
+ NoKwsMap[emptyNum] = []map[string]interface{}{v}
|
|
|
+ } else {
|
|
|
+ NoKwsMap[emptyNum] = append(NoKwsMap[emptyNum], v)
|
|
|
+ }
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ }
|
|
|
if AllMap[emptyNum] == nil {
|
|
|
AllMap[emptyNum] = []map[string]interface{}{v}
|
|
|
continue
|
|
@@ -577,6 +599,26 @@ func ScreenData(arr *[]map[string]interface{}, dataType string, resultNum int) (
|
|
|
res = tmp
|
|
|
}
|
|
|
}
|
|
|
+ if len(res) < lastNum {
|
|
|
+ resultNum = lastNum - len(res)
|
|
|
+ //获取key
|
|
|
+ Nokeys := []int{}
|
|
|
+ for k, _ := range NoKwsMap {
|
|
|
+ Nokeys = append(Nokeys, k)
|
|
|
+ }
|
|
|
+ sort.Ints(Nokeys)
|
|
|
+ log.Println("没关键词的空字段数量", Nokeys)
|
|
|
+ //选取结果
|
|
|
+ for _, v := range Nokeys {
|
|
|
+ if len(AllMap[v]) >= resultNum {
|
|
|
+ return append(res, NoKwsMap[v][:resultNum]...)
|
|
|
+ } else {
|
|
|
+ resultNum = resultNum - len(NoKwsMap[v])
|
|
|
+ tmp := append(res, NoKwsMap[v][:len(AllMap[v])]...)
|
|
|
+ res = tmp
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
return res
|
|
|
}
|
|
|
func countOfTheEmpty(m map[string]interface{}, dataType string) int {
|