|
@@ -70,8 +70,11 @@ func EsAddOrEditData(indexName, docId string, item *ElasticArticleDetail) (err e
|
|
|
}
|
|
|
if searchById != nil && searchById.Found {
|
|
|
resp, err := client.Update().Index(indexName).Id(docId).Doc(map[string]interface{}{
|
|
|
- "BodyText": item.BodyText,
|
|
|
- "Title": item.Title,
|
|
|
+ "BodyText": item.BodyText,
|
|
|
+ "Title": item.Title,
|
|
|
+ "PublishDate": item.PublishDate,
|
|
|
+ "TitleEn": item.TitleEn,
|
|
|
+ "CreateDate": item.CreateDate,
|
|
|
}).Do(context.Background())
|
|
|
if err != nil {
|
|
|
return err
|
|
@@ -85,7 +88,7 @@ func EsAddOrEditData(indexName, docId string, item *ElasticArticleDetail) (err e
|
|
|
} else {
|
|
|
resp, err := client.Index().Index(indexName).Id(docId).BodyJson(item).Do(context.Background())
|
|
|
if err != nil {
|
|
|
- fmt.Println("新增失败:",err.Error())
|
|
|
+ fmt.Println("新增失败:", err.Error())
|
|
|
return err
|
|
|
}
|
|
|
if resp.Status == 0 && resp.Result == "created" {
|
|
@@ -382,7 +385,6 @@ func EsMultiMatchFunctionScoreQuery(indexName, keyWord string, startSize, pageSi
|
|
|
keyWordArr, err := GetIndustryMapNameSliceV2(keyWord)
|
|
|
|
|
|
keyWordArr = RemoveDuplicatesAndEmpty(keyWordArr)
|
|
|
- searchMap := make(map[int]int)
|
|
|
boolquery := elastic.NewBoolQuery()
|
|
|
matchArr := make([]elastic.Query, 0)
|
|
|
|
|
@@ -424,32 +426,29 @@ func EsMultiMatchFunctionScoreQuery(indexName, keyWord string, startSize, pageSi
|
|
|
if err != nil {
|
|
|
return nil, 0, err
|
|
|
}
|
|
|
- if _, ok := searchMap[article.ArticleId]; !ok {
|
|
|
- searchItem := new(models.SearchItem)
|
|
|
- searchItem.ArticleId, _ = strconv.Atoi(v.Id)
|
|
|
- if len(v.Highlight["BodyText"]) > 0 {
|
|
|
- searchItem.Body = v.Highlight["BodyText"]
|
|
|
- } else {
|
|
|
- bodyRune := []rune(article.BodyText)
|
|
|
- bodyRuneLen := len(bodyRune)
|
|
|
- if bodyRuneLen > 100 {
|
|
|
- bodyRuneLen = 100
|
|
|
- }
|
|
|
- body := string(bodyRune[:bodyRuneLen])
|
|
|
- fmt.Println(body)
|
|
|
- searchItem.Body = []string{body}
|
|
|
- }
|
|
|
- var title string
|
|
|
- if len(v.Highlight["Title"]) > 0 {
|
|
|
- title = v.Highlight["Title"][0]
|
|
|
- } else {
|
|
|
- title = article.Title
|
|
|
+ searchItem := new(models.SearchItem)
|
|
|
+ searchItem.ArticleId, _ = strconv.Atoi(v.Id)
|
|
|
+ if len(v.Highlight["BodyText"]) > 0 {
|
|
|
+ searchItem.Body = v.Highlight["BodyText"]
|
|
|
+ } else {
|
|
|
+ bodyRune := []rune(article.BodyText)
|
|
|
+ bodyRuneLen := len(bodyRune)
|
|
|
+ if bodyRuneLen > 100 {
|
|
|
+ bodyRuneLen = 100
|
|
|
}
|
|
|
- searchItem.Title = title
|
|
|
- searchItem.PublishDate = article.PublishDate
|
|
|
- result = append(result, searchItem)
|
|
|
- searchMap[article.ArticleId] = article.ArticleId
|
|
|
+ body := string(bodyRune[:bodyRuneLen])
|
|
|
+ fmt.Println(body)
|
|
|
+ searchItem.Body = []string{body}
|
|
|
}
|
|
|
+ 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
|
|
|
+ result = append(result, searchItem)
|
|
|
}
|
|
|
}
|
|
|
}
|