|
@@ -60,7 +60,7 @@ func SaveData() {
|
|
|
3161,3190,3226,3244,3264,3285,3310,3334,3370,3397,3418,3446,3477,3497,3526,3554
|
|
|
*/
|
|
|
|
|
|
- idStr := `3161,3190,3226,3244,3264,3285,3310,3334,3370,3397,3418,3446,3477,3497,3526,3554`
|
|
|
+ idStr := `3584,3644`
|
|
|
idArr := strings.Split(idStr, ",")
|
|
|
for _, v := range idArr {
|
|
|
id, _ := strconv.Atoi(v)
|
|
@@ -77,7 +77,7 @@ func SaveData() {
|
|
|
}
|
|
|
bodyText := doc.Text()
|
|
|
item.BodyText = bodyText
|
|
|
- //删除
|
|
|
+ //新增
|
|
|
resp, err := client.Index().Index(esIndex).Id(strconv.Itoa(item.ArticleId)).BodyJson(item).Do(context.Background())
|
|
|
if err != nil {
|
|
|
fmt.Println("insert es failed", err.Error())
|
|
@@ -150,7 +150,7 @@ func SaveData() {
|
|
|
fmt.Println("end")
|
|
|
}
|
|
|
|
|
|
-func SearchByKeyWord(keyWord string, pageSize int) (result []*models.SearchItem, err error) {
|
|
|
+func SearchByKeyWord(keyWord,categoryName string, pageSize int) (result []*models.SearchItem, err error) {
|
|
|
if pageSize == 0 {
|
|
|
pageSize = 20
|
|
|
}
|
|
@@ -167,6 +167,9 @@ func SearchByKeyWord(keyWord string, pageSize int) (result []*models.SearchItem,
|
|
|
return
|
|
|
}
|
|
|
var esIndex = "cygx_article"
|
|
|
+
|
|
|
+ termsQuery:=elastic.NewTermsQuery("category_name",categoryName)
|
|
|
+
|
|
|
boolquery := elastic.NewBoolQuery()
|
|
|
|
|
|
boolquery.Must(elastic.NewMatchQuery("Title", keyWord), elastic.NewMatchQuery("BodyText", keyWord))
|
|
@@ -175,7 +178,7 @@ func SearchByKeyWord(keyWord string, pageSize int) (result []*models.SearchItem,
|
|
|
highlight = highlight.Fields(elastic.NewHighlighterField("Title"), elastic.NewHighlighterField("BodyText"))
|
|
|
highlight = highlight.PreTags("<font color='red'>").PostTags("</font>")
|
|
|
|
|
|
- searchByMatch, err := client.Search(esIndex).Highlight(highlight).Size(pageSize).Query(boolquery).Do(context.Background())
|
|
|
+ searchByMatch, err := client.Search(esIndex).Highlight(highlight).Size(pageSize).Query(termsQuery).Query(boolquery).Do(context.Background())
|
|
|
|
|
|
if err != nil {
|
|
|
return
|