|
@@ -12,8 +12,8 @@ import (
|
|
|
|
|
|
// 首页搜索
|
|
|
func SearchReport(keyWord string, classifyIdFirsts []int, classifyIdSeconds []int, pageIndex, pageSize int) (searchResp *elastic.SearchResult, total int64, err error) {
|
|
|
- indexName := global.CONFIG.EsClient.Prefix+utils.ES_INDEX_RDDP_REPORT
|
|
|
- var must []map[string]interface{}
|
|
|
+ indexName := global.CONFIG.EsClient.Prefix + utils.ES_INDEX_RDDP_REPORT
|
|
|
+ var must []map[string]interface{}
|
|
|
|
|
|
shouldSub := []map[string]interface{}{
|
|
|
/*map[string]interface{}{
|
|
@@ -78,17 +78,17 @@ func SearchReport(keyWord string, classifyIdFirsts []int, classifyIdSeconds []in
|
|
|
filterMust := []map[string]interface{}{
|
|
|
map[string]interface{}{
|
|
|
"term": map[string]interface{}{
|
|
|
- "PublishState": 2, //必须是已发布的报告
|
|
|
+ "PublishState": 2, //必须是已发布的报告
|
|
|
},
|
|
|
},
|
|
|
map[string]interface{}{
|
|
|
"terms": map[string]interface{}{
|
|
|
- "ClassifyIdFirst":classifyIdFirsts, //分类必须是正常显示状态
|
|
|
+ "ClassifyIdFirst": classifyIdFirsts, //分类必须是正常显示状态
|
|
|
},
|
|
|
},
|
|
|
map[string]interface{}{
|
|
|
"terms": map[string]interface{}{
|
|
|
- "ClassifyIdSecond":classifyIdSeconds, //分类必须是正常显示状态
|
|
|
+ "ClassifyIdSecond": classifyIdSeconds, //分类必须是正常显示状态
|
|
|
},
|
|
|
},
|
|
|
}
|
|
@@ -96,54 +96,61 @@ func SearchReport(keyWord string, classifyIdFirsts []int, classifyIdSeconds []in
|
|
|
map[string]interface{}{
|
|
|
"term": map[string]interface{}{
|
|
|
"BodyContent.keyword": map[string]interface{}{
|
|
|
- "value": "", //过滤没有内容的报告(晨报和周报)bodyContent 不能为空
|
|
|
+ "value": "", //过滤没有内容的报告(晨报和周报)bodyContent 不能为空
|
|
|
},
|
|
|
},
|
|
|
},
|
|
|
}
|
|
|
+
|
|
|
+ //某章节的报告,若是继承上一期的报告内容且未作修改,搜索匹配项仅展示最新一期该章节的报告。 需求池p2_838
|
|
|
+ filteCollapse := map[string]interface{}{
|
|
|
+ "field": "BodyMd5",
|
|
|
+ }
|
|
|
filterMap := map[string]interface{}{
|
|
|
"bool": map[string]interface{}{
|
|
|
- "must": filterMust,
|
|
|
+ "must": filterMust,
|
|
|
"must_not": filterMustNot,
|
|
|
},
|
|
|
}
|
|
|
source := map[string]interface{}{
|
|
|
"query": map[string]interface{}{
|
|
|
"bool": map[string]interface{}{
|
|
|
- "must": must,
|
|
|
+ "must": must,
|
|
|
"filter": filterMap,
|
|
|
},
|
|
|
},
|
|
|
}
|
|
|
+
|
|
|
source["from"] = (pageIndex - 1) * pageSize
|
|
|
source["size"] = pageSize
|
|
|
+ source["collapse"] = filteCollapse
|
|
|
source["highlight"] = map[string]interface{}{
|
|
|
"fields": map[string]interface{}{
|
|
|
- "Title":map[string]interface{}{},
|
|
|
- "Categories":map[string]interface{}{},
|
|
|
- "BodyContent":map[string]interface{}{
|
|
|
- // "pre_tags" : "{{highlight}}",
|
|
|
- // "post_tags": "{{/highlight}}",
|
|
|
+ "Title": map[string]interface{}{},
|
|
|
+ "Categories": map[string]interface{}{},
|
|
|
+ "BodyContent": map[string]interface{}{
|
|
|
+ // "pre_tags" : "{{highlight}}",
|
|
|
+ // "post_tags": "{{/highlight}}",
|
|
|
},
|
|
|
},
|
|
|
- "pre_tags" : "<span style=\"color:#E3B377\">",
|
|
|
+ "pre_tags": "<span style=\"color:#E3B377\">",
|
|
|
"post_tags": "</span>",
|
|
|
}
|
|
|
|
|
|
source["sort"] = []map[string]interface{}{
|
|
|
map[string]interface{}{
|
|
|
- "PublishTime.keyword":map[string]interface{}{
|
|
|
- "order":"desc",
|
|
|
+ "PublishTime.keyword": map[string]interface{}{
|
|
|
+ "order": "desc",
|
|
|
},
|
|
|
},
|
|
|
map[string]interface{}{
|
|
|
- "_score":map[string]interface{}{
|
|
|
- "order":"desc",
|
|
|
+ "_score": map[string]interface{}{
|
|
|
+ "order": "desc",
|
|
|
},
|
|
|
},
|
|
|
}
|
|
|
jsonstr, err := json.Marshal(source)
|
|
|
- fmt.Printf("%s",jsonstr)
|
|
|
+ fmt.Printf("%s", jsonstr)
|
|
|
request := global.EsClient.Search(indexName).Source(source) // sets the JSON request
|
|
|
|
|
|
searchResp, err = request.Do(context.Background())
|
|
@@ -164,8 +171,8 @@ func SearchReport(keyWord string, classifyIdFirsts []int, classifyIdSeconds []in
|
|
|
|
|
|
// ReportListSearch 报告列表页的搜索
|
|
|
func ReportListSearch(keyWord string, classifyIdFirst int, classifyIdSeconds []int, pageIndex, pageSize int) (searchResp *elastic.SearchResult, total int64, err error) {
|
|
|
- indexName := global.CONFIG.EsClient.Prefix+utils.ES_INDEX_RDDP_REPORT
|
|
|
- var must []map[string]interface{}
|
|
|
+ indexName := global.CONFIG.EsClient.Prefix + utils.ES_INDEX_RDDP_REPORT
|
|
|
+ var must []map[string]interface{}
|
|
|
shouldSub := []map[string]interface{}{
|
|
|
map[string]interface{}{
|
|
|
"match": map[string]interface{}{
|
|
@@ -233,12 +240,12 @@ func ReportListSearch(keyWord string, classifyIdFirst int, classifyIdSeconds []i
|
|
|
},
|
|
|
map[string]interface{}{
|
|
|
"term": map[string]interface{}{
|
|
|
- "ReportChapterId":0, //排除章节内容
|
|
|
+ "ReportChapterId": 0, //排除章节内容
|
|
|
},
|
|
|
},
|
|
|
map[string]interface{}{
|
|
|
"term": map[string]interface{}{
|
|
|
- "ClassifyIdFirst":classifyIdFirst,
|
|
|
+ "ClassifyIdFirst": classifyIdFirst,
|
|
|
},
|
|
|
},
|
|
|
map[string]interface{}{
|
|
@@ -250,7 +257,7 @@ func ReportListSearch(keyWord string, classifyIdFirst int, classifyIdSeconds []i
|
|
|
source := map[string]interface{}{
|
|
|
"query": map[string]interface{}{
|
|
|
"bool": map[string]interface{}{
|
|
|
- "must": must,
|
|
|
+ "must": must,
|
|
|
"filter": filter,
|
|
|
},
|
|
|
},
|
|
@@ -260,29 +267,29 @@ func ReportListSearch(keyWord string, classifyIdFirst int, classifyIdSeconds []i
|
|
|
source["size"] = pageSize
|
|
|
source["highlight"] = map[string]interface{}{
|
|
|
"fields": map[string]interface{}{
|
|
|
- "Title":map[string]interface{}{},
|
|
|
- "Abstract":map[string]interface{}{},
|
|
|
- "StageStr":map[string]interface{}{},
|
|
|
- "ClassifyNameSecond":map[string]interface{}{},
|
|
|
+ "Title": map[string]interface{}{},
|
|
|
+ "Abstract": map[string]interface{}{},
|
|
|
+ "StageStr": map[string]interface{}{},
|
|
|
+ "ClassifyNameSecond": map[string]interface{}{},
|
|
|
},
|
|
|
- "pre_tags" : "<span style=\"color:#E3B377\">",
|
|
|
+ "pre_tags": "<span style=\"color:#E3B377\">",
|
|
|
"post_tags": "</span>",
|
|
|
}
|
|
|
|
|
|
source["sort"] = []map[string]interface{}{
|
|
|
map[string]interface{}{
|
|
|
- "PublishTime.keyword":map[string]interface{}{
|
|
|
- "order":"desc",
|
|
|
+ "PublishTime.keyword": map[string]interface{}{
|
|
|
+ "order": "desc",
|
|
|
},
|
|
|
},
|
|
|
map[string]interface{}{
|
|
|
- "_score":map[string]interface{}{
|
|
|
- "order":"desc",
|
|
|
+ "_score": map[string]interface{}{
|
|
|
+ "order": "desc",
|
|
|
},
|
|
|
},
|
|
|
}
|
|
|
jsonstr, err := json.Marshal(source)
|
|
|
- fmt.Printf("%s",jsonstr)
|
|
|
+ fmt.Printf("%s", jsonstr)
|
|
|
request := global.EsClient.Search(indexName).Source(source) // sets the JSON request
|
|
|
searchResp, err = request.Do(context.Background())
|
|
|
if err != nil {
|
|
@@ -298,4 +305,4 @@ func ReportListSearch(keyWord string, classifyIdFirst int, classifyIdSeconds []i
|
|
|
}
|
|
|
total = searchResp.TotalHits()
|
|
|
return
|
|
|
-}
|
|
|
+}
|