Sfoglia il codice sorgente

Merge branch 'master' of http://8.136.199.33:3000/hongze/hongze_cygx into cygx_v2

xingzai 3 anni fa
parent
commit
bbd9b34b2a
2 ha cambiato i file con 69 aggiunte e 39 eliminazioni
  1. 1 1
      models/article.go
  2. 68 38
      services/task.go

+ 1 - 1
models/article.go

@@ -173,7 +173,7 @@ func GetArticleDetailTestById(articleId int) (item *ArticleDetailTest, err error
 
 func GetArticleAll() (item []*ArticleDetail, err error) {
 	o := orm.NewOrm()
-	sql := `SELECT * FROM cygx_article `
+	sql := `SELECT * FROM cygx_article WHERE is_summary=1 `
 	_, err = o.Raw(sql).QueryRows(&item)
 	return
 }

+ 68 - 38
services/task.go

@@ -40,7 +40,6 @@ func Task() {
 	//toolbox.StartTask()
 
 	fmt.Println("end")
-
 }
 
 func ElasticOption() {
@@ -195,43 +194,74 @@ searchItem.Body = v.Highlight["BodyText"]
 searchItem.Title = title
 searchItem.PublishDate = article.PublishDate
 */
-func CreateIndex() {
-	indexName := "cygx_article_test" //utils.IndexName
-	mappingJson := `{
-  "mappings": {
-    "dynamic": true,
-    "properties": {
-      "ArticleId": {
-        "type": "integer"
-      },
-      "BodyText": {
-        "type": "text",
-        "term_vector": "with_positions_offsets"
-      },
-      "PublishDate": {
-        "type": "text"
-      },
-      "SubCategoryName": {
-        "type": "text",
-        "term_vector": "with_positions_offsets"
-      },
-      "Title": {
-        "type": "text",
-        "term_vector": "with_positions_offsets"
-      },
-      "TitleEn": {
-        "type": "text",
-        "term_vector": "with_positions_offsets"
-      },
-      "UpdateFrequency": {
-        "type": "text",
-        "term_vector": "with_positions_offsets"
-      }
-    }
-  }
-}`
-	EsCreateIndex(indexName, mappingJson)
-}
+//func CreateIndex() {
+//	indexName := "cygx_article_v4" //utils.IndexName
+//	mappingJson := `{
+//  "mappings": {
+//    "dynamic": true,
+//    "properties": {
+//      "ArticleId": {
+//        "type": "integer"
+//      },
+//      "BodyText": {
+//        "type": "text",
+//        "term_vector": "with_positions_offsets",
+//		"analyzer": "ik_smart"
+//      },
+//      "PublishDate": {
+//        "type": "keyword"
+//      },
+//      "SubCategoryName": {
+//        "type": "text",
+//        "term_vector": "with_positions_offsets",
+//		"analyzer": "ik_smart"
+//      },
+//      "Title": {
+//        "type": "text",
+//        "term_vector": "with_positions_offsets",
+//		"analyzer": "ik_smart"
+//      },
+//      "TitleEn": {
+//        "type": "text",
+//        "term_vector": "with_positions_offsets"
+//      },
+//      "UpdateFrequency": {
+//        "type": "text",
+//        "term_vector": "with_positions_offsets"
+//      }
+//    }
+//  }
+//}`
+//	EsCreateIndex(indexName, mappingJson)
+//}
+//
+//func AddAllArticle() {
+//	allList, err := models.GetArticleAll()
+//	if err != nil {
+//		fmt.Println("GetArticleAll Err:", err.Error())
+//		return
+//	}
+//
+//	indexName := "cygx_article_v4"
+//
+//	for _, v := range allList {
+//		content := html.UnescapeString(v.Body)
+//		doc, err := goquery.NewDocumentFromReader(strings.NewReader(content))
+//		if err != nil {
+//			fmt.Println("create doc err:", err.Error())
+//			return
+//		}
+//		bodyText := doc.Text()
+//
+//		item := new(ElasticTestArticleDetail)
+//		item.ArticleId = v.ArticleId
+//		item.Title = v.Title
+//		item.PublishDate = v.PublishDate
+//		item.BodyText = bodyText
+//		EsAddOrEditData(indexName, strconv.Itoa(v.ArticleId), item)
+//		fmt.Println(v.ArticleId)
+//	}
+//}
 
 // "term_vector": "with_positions_offsets"