|
@@ -718,6 +718,7 @@ func EsMultiMatchFunctionScoreQuerySort(indexName, keyWord string, startSize, pa
|
|
|
boolquery := elastic.NewBoolQuery()
|
|
|
bodyFunctionQuery := elastic.NewFunctionScoreQuery()
|
|
|
bodyFunctionQuery2 := elastic.NewFunctionScoreQuery()
|
|
|
+ bodyFunctionQuery3 := elastic.NewFunctionScoreQuery()
|
|
|
|
|
|
//multiMatch := elastic.NewMultiMatchQuery(v, "Title", "BodyText").Analyzer("ik_smart")
|
|
|
multiMatch := elastic.NewMultiMatchQuery(v, "Title").Analyzer("ik_smart").Boost(10)
|
|
@@ -727,7 +728,12 @@ func EsMultiMatchFunctionScoreQuerySort(indexName, keyWord string, startSize, pa
|
|
|
multiMatch = elastic.NewMultiMatchQuery(v, "BodyText").Analyzer("ik_smart")
|
|
|
bodyFunctionQuery2.Query(multiMatch)
|
|
|
matchArr = append(matchArr, bodyFunctionQuery2)
|
|
|
- boolquery.Should(matchArr...)
|
|
|
+
|
|
|
+ multiMatch = elastic.NewMultiMatchQuery(1, "IsSummary")
|
|
|
+ bodyFunctionQuery3.Query(multiMatch)
|
|
|
+ matchArr = append(matchArr, bodyFunctionQuery3)
|
|
|
+
|
|
|
+ boolquery.Must(matchArr...)
|
|
|
|
|
|
//multiMatch = elastic.NewMultiMatchQuery(v, "BodyText").Analyzer("ik_smart")
|
|
|
//bodyFunctionQuery.Query(multiMatch)
|
|
@@ -805,6 +811,7 @@ func EsMultiMatchFunctionScoreQueryTimeSort(indexName, keyWord string, startSize
|
|
|
keyWordArr = RemoveDuplicatesAndEmpty(keyWordArr)
|
|
|
boolquery := elastic.NewBoolQuery()
|
|
|
matchArr := make([]elastic.Query, 0)
|
|
|
+ //matchArr2 := make([]elastic.Query, 0)
|
|
|
|
|
|
n := 0
|
|
|
keyWordLen := len(keyWordArr)
|
|
@@ -823,7 +830,14 @@ func EsMultiMatchFunctionScoreQueryTimeSort(indexName, keyWord string, startSize
|
|
|
}
|
|
|
n++
|
|
|
}
|
|
|
- boolquery.Should(matchArr...)
|
|
|
+ //boolquery.Should(matchArr...)
|
|
|
+
|
|
|
+ //multiMatch2 := elastic.NewMultiMatchQuery(1, "IsSummary")
|
|
|
+ //bodyFunctionQuery2 := elastic.NewFunctionScoreQuery()
|
|
|
+ //bodyFunctionQuery2.Query(multiMatch2)
|
|
|
+ //matchArr2 = append(matchArr2, bodyFunctionQuery2)
|
|
|
+ //boolquery.Must(matchArr2...).Should(matchArr...)
|
|
|
+
|
|
|
highlight := elastic.NewHighlight()
|
|
|
highlight = highlight.Fields(elastic.NewHighlighterField("Title"), elastic.NewHighlighterField("BodyText"))
|
|
|
highlight = highlight.PreTags("<font color='red'>").PostTags("</font>")
|
|
@@ -874,3 +888,85 @@ func EsMultiMatchFunctionScoreQueryTimeSort(indexName, keyWord string, startSize
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+func EsSearchReport(indexName, keyWord string, startSize, pageSize, userId int) (result []*models.SearchItem, total int64, err error) {
|
|
|
+ client, err := NewClient()
|
|
|
+ keyWordArr, err := GetIndustryMapNameSliceV3(keyWord)
|
|
|
+ keyWordArr = RemoveDuplicatesAndEmpty(keyWordArr)
|
|
|
+ n := 0
|
|
|
+ keyWordLen := len(keyWordArr)
|
|
|
+ if keyWordLen <= 0 {
|
|
|
+ keyWordArr = append(keyWordArr, keyWord)
|
|
|
+ keyWordLen = len(keyWordArr)
|
|
|
+ }
|
|
|
+ for _, v := range keyWordArr {
|
|
|
+ fmt.Println(v)
|
|
|
+ }
|
|
|
+
|
|
|
+ utils.FileLog.Info("SearchKeyWord:%s, userId:%s", keyWordArr, strconv.Itoa(userId))
|
|
|
+ for _, v := range keyWordArr {
|
|
|
+ if v != "" {
|
|
|
+ matchArr := make([]elastic.Query, 0)
|
|
|
+ boolquery := elastic.NewBoolQuery()
|
|
|
+ bodyFunctionQuery := elastic.NewFunctionScoreQuery()
|
|
|
+ bodyFunctionQuery2 := elastic.NewFunctionScoreQuery()
|
|
|
+
|
|
|
+ multiMatch := elastic.NewMultiMatchQuery(v, "Title").Analyzer("ik_smart")
|
|
|
+ bodyFunctionQuery.Query(multiMatch)
|
|
|
+ matchArr = append(matchArr, bodyFunctionQuery)
|
|
|
+
|
|
|
+ multiMatch = elastic.NewMultiMatchQuery(1, "IsReport")
|
|
|
+ bodyFunctionQuery2.Query(multiMatch)
|
|
|
+ matchArr = append(matchArr, bodyFunctionQuery2)
|
|
|
+ boolquery.Must(matchArr...)
|
|
|
+
|
|
|
+ highlight := elastic.NewHighlight()
|
|
|
+ highlight = highlight.PreTags("<font color='red'>").PostTags("</font>")
|
|
|
+ highlight = highlight.Fields(elastic.NewHighlighterField("Title"))
|
|
|
+ request := client.Search(indexName).Highlight(highlight).Sort("PublishDate", false).From(0).Size(pageSize).Query(boolquery)
|
|
|
+
|
|
|
+ searchByMatch, err := request.Do(context.Background())
|
|
|
+ if err != nil {
|
|
|
+ return nil, 0, err
|
|
|
+ }
|
|
|
+ if searchByMatch != nil {
|
|
|
+ if searchByMatch.Hits != nil {
|
|
|
+ for _, v := range searchByMatch.Hits.Hits {
|
|
|
+ var isAppend bool
|
|
|
+ articleJson, err := v.Source.MarshalJSON()
|
|
|
+ if err != nil {
|
|
|
+ return nil, 0, err
|
|
|
+ }
|
|
|
+ article := new(models.CygxArticle)
|
|
|
+ err = json.Unmarshal(articleJson, &article)
|
|
|
+ if err != nil {
|
|
|
+ return nil, 0, err
|
|
|
+ }
|
|
|
+ searchItem := new(models.SearchItem)
|
|
|
+ searchItem.ArticleId, _ = strconv.Atoi(v.Id)
|
|
|
+
|
|
|
+ var title string
|
|
|
+ if len(v.Highlight["Title"]) > 0 {
|
|
|
+ title = v.Highlight["Title"][0]
|
|
|
+ } else {
|
|
|
+ title = article.Title
|
|
|
+ }
|
|
|
+ searchItem.Title = title
|
|
|
+ searchItem.PublishDate = article.PublishDate
|
|
|
+ for _, v_result := range result {
|
|
|
+ if v_result.ArticleId == searchItem.ArticleId {
|
|
|
+ isAppend = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if !isAppend {
|
|
|
+ result = append(result, searchItem)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ n++
|
|
|
+ }
|
|
|
+ total = int64(len(result))
|
|
|
+ return
|
|
|
+}
|