|
@@ -69,9 +69,6 @@ func EsAddOrEditData(indexName, docId string, item *ElasticTestArticleDetail) (e
|
|
|
}
|
|
|
}()
|
|
|
client := utils.Client
|
|
|
- //if err != nil {
|
|
|
- // return
|
|
|
- //}
|
|
|
searchById, err := client.Get().Index(indexName).Id(docId).Do(context.Background())
|
|
|
if err != nil && !strings.Contains(err.Error(), "404") {
|
|
|
fmt.Println("Get Err" + err.Error())
|
|
@@ -79,14 +76,15 @@ func EsAddOrEditData(indexName, docId string, item *ElasticTestArticleDetail) (e
|
|
|
}
|
|
|
if searchById != nil && searchById.Found {
|
|
|
resp, err := client.Update().Index(indexName).Id(docId).Doc(map[string]interface{}{
|
|
|
- "BodyText": item.BodyText,
|
|
|
- "Title": item.Title,
|
|
|
- "PublishDate": item.PublishDate,
|
|
|
+ "BodyText": item.BodyText,
|
|
|
+ "Title": item.Title,
|
|
|
+ "PublishDate": item.PublishDate,
|
|
|
+ "CategoryId": item.CategoryId,
|
|
|
+ "ExpertBackground": item.ExpertBackground,
|
|
|
}).Do(context.Background())
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
- fmt.Println(resp.Status, resp.Result)
|
|
|
if resp.Status == 0 {
|
|
|
fmt.Println("修改成功")
|
|
|
} else {
|
|
@@ -763,7 +761,7 @@ func EsMultiMatchFunctionScoreQuerySort(indexName, keyWord string, startSize, pa
|
|
|
if err != nil {
|
|
|
return nil, 0, err
|
|
|
}
|
|
|
- article := new(models.CygxArticle)
|
|
|
+ article := new(models.CygxArticleEs)
|
|
|
err = json.Unmarshal(articleJson, &article)
|
|
|
if err != nil {
|
|
|
return nil, 0, err
|
|
@@ -790,6 +788,7 @@ func EsMultiMatchFunctionScoreQuerySort(indexName, keyWord string, startSize, pa
|
|
|
searchItem.Title = title
|
|
|
searchItem.PublishDate = article.PublishDate
|
|
|
searchItem.ExpertBackground = article.ExpertBackground
|
|
|
+ searchItem.CategoryId = article.CategoryId
|
|
|
for _, v_result := range result {
|
|
|
if v_result.ArticleId == searchItem.ArticleId {
|
|
|
isAppend = true
|
|
@@ -836,19 +835,11 @@ func EsMultiMatchFunctionScoreQueryTimeSort(indexName, keyWord string, startSize
|
|
|
n++
|
|
|
}
|
|
|
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>")
|
|
|
request := client.Search(indexName).Highlight(highlight).Sort("PublishDate", false).Size(pageSize).Query(boolquery)
|
|
|
searchByMatch, err := request.Do(context.Background())
|
|
|
-
|
|
|
if searchByMatch != nil {
|
|
|
matchResult, _ := json.Marshal(searchByMatch)
|
|
|
utils.FileLog.Info("%s", string(matchResult))
|
|
@@ -860,7 +851,7 @@ func EsMultiMatchFunctionScoreQueryTimeSort(indexName, keyWord string, startSize
|
|
|
if err != nil {
|
|
|
return nil, 0, err
|
|
|
}
|
|
|
- article := new(models.CygxArticle)
|
|
|
+ article := new(models.CygxArticleEs)
|
|
|
err = json.Unmarshal(articleJson, &article)
|
|
|
if err != nil {
|
|
|
return nil, 0, err
|
|
@@ -887,6 +878,7 @@ func EsMultiMatchFunctionScoreQueryTimeSort(indexName, keyWord string, startSize
|
|
|
searchItem.Title = title
|
|
|
searchItem.PublishDate = article.PublishDate
|
|
|
searchItem.ExpertBackground = article.ExpertBackground
|
|
|
+ searchItem.CategoryId = article.CategoryId
|
|
|
result = append(result, searchItem)
|
|
|
}
|
|
|
}
|
|
@@ -943,14 +935,13 @@ func EsSearchReport(indexName, keyWord string, startSize, pageSize, userId int)
|
|
|
if err != nil {
|
|
|
return nil, 0, err
|
|
|
}
|
|
|
- article := new(models.CygxArticle)
|
|
|
+ article := new(models.CygxArticleEs)
|
|
|
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]
|