Commit 6249c39b by davidstark

根据海亮意见,修改部分代码

parent 2ff355ac
...@@ -44,9 +44,6 @@ type Word struct { ...@@ -44,9 +44,6 @@ type Word struct {
WordRank float64 `json:"wordRank"` WordRank float64 `json:"wordRank"`
KeywordVersion string `json:"keywordVersion"` KeywordVersion string `json:"keywordVersion"`
} }
const BRAND_TYPE = "1"
const CATEGORY_TYPE = "2"
const MANUAL_TYPE = "3"
var wordMap sync.Map var wordMap sync.Map
var brandMap = make(map[string]int) var brandMap = make(map[string]int)
...@@ -118,30 +115,25 @@ func main() { ...@@ -118,30 +115,25 @@ func main() {
} }
func checkUnusedData(bulkProcessor *elastic.BulkProcessor) { func checkUnusedData(bulkProcessor *elastic.BulkProcessor) {
var tmpMap = make(map[string]bool)
for brand := range brandMap { for brand := range brandMap {
if _, exist := usedMap.Load(brand + BRAND_TYPE); !exist { tmpMap[brand] = true;
addWord(brand,bulkProcessor,BRAND_TYPE)
}
} }
for category := range categoryMap { for category := range categoryMap {
if _, exist := usedMap.Load(category + CATEGORY_TYPE); !exist { tmpMap[category] = true
addWord(category,bulkProcessor,CATEGORY_TYPE)
}
} }
for manual := range manualMap { for manual := range manualMap {
if _, exist := usedMap.Load(manual + MANUAL_TYPE); !exist { tmpMap[manual] = true
addWord(manual,bulkProcessor,MANUAL_TYPE) }
for word := range tmpMap {
if _, exist := usedMap.Load(word); !exist {
addWord(word, bulkProcessor)
} }
} }
} }
func addWord(keyword string, processor *elastic.BulkProcessor, wordType string) { func addWord(keyword string, processor *elastic.BulkProcessor) {
var w = new(Word) var w = new(Word)
switch wordType {
case BRAND_TYPE: w.IsBrand = true
case CATEGORY_TYPE: w.IsCategory = true
case MANUAL_TYPE: { w.IsManual = true; w.ManualValue = manualMap[keyword]}
}
w.Keyword = keyword w.Keyword = keyword
w.KeywordVersion = dateStr w.KeywordVersion = dateStr
processWord(w) processWord(w)
...@@ -344,18 +336,18 @@ func processWord(w *Word) { ...@@ -344,18 +336,18 @@ func processWord(w *Word) {
if _, isExist := brandMap[w.Keyword]; isExist { if _, isExist := brandMap[w.Keyword]; isExist {
w.IsBrand = true w.IsBrand = true
usedMap.Store(w.Keyword + BRAND_TYPE, true) usedMap.Store(w.Keyword, true)
} }
if _, isExist := manualMap[w.Keyword]; isExist { if _, isExist := manualMap[w.Keyword]; isExist {
w.IsManual = true w.IsManual = true
w.ManualValue = manualMap[w.Keyword] w.ManualValue = manualMap[w.Keyword]
usedMap.Store(w.Keyword + MANUAL_TYPE,true) usedMap.Store(w.Keyword,true)
} }
if _, isExist := categoryMap[w.Keyword]; isExist { if _, isExist := categoryMap[w.Keyword]; isExist {
w.IsCategory = true w.IsCategory = true
usedMap.Store(w.Keyword + CATEGORY_TYPE, true) usedMap.Store(w.Keyword, true)
} }
if _, isExist := sensitiveMap[w.Keyword]; isExist { if _, isExist := sensitiveMap[w.Keyword]; isExist {
......
...@@ -44,10 +44,6 @@ type Word struct { ...@@ -44,10 +44,6 @@ type Word struct {
WordRank float64 `json:"wordRank"` WordRank float64 `json:"wordRank"`
KeywordVersion string `json:"keywordVersion"` KeywordVersion string `json:"keywordVersion"`
} }
const BRAND_TYPE = "1"
const CATEGORY_TYPE = "2"
const MANUAL_TYPE = "3"
var wordMap sync.Map var wordMap sync.Map
var brandMap = make(map[string]int) var brandMap = make(map[string]int)
var categoryMap = make(map[string]int) var categoryMap = make(map[string]int)
...@@ -109,30 +105,25 @@ func main() { ...@@ -109,30 +105,25 @@ func main() {
} }
func checkUnusedData(bulkProcessor *elastic.BulkProcessor) { func checkUnusedData(bulkProcessor *elastic.BulkProcessor) {
var tmpMap = make(map[string]bool)
for brand := range brandMap { for brand := range brandMap {
if _, exist := usedMap.Load(brand + BRAND_TYPE); !exist { tmpMap[brand] = true;
addWord(brand,bulkProcessor,BRAND_TYPE)
}
} }
for category := range categoryMap { for category := range categoryMap {
if _, exist := usedMap.Load(category + CATEGORY_TYPE); !exist { tmpMap[category] = true
addWord(category,bulkProcessor,CATEGORY_TYPE)
}
} }
for manual := range manualMap { for manual := range manualMap {
if _, exist := usedMap.Load(manual + MANUAL_TYPE); !exist { tmpMap[manual] = true
addWord(manual,bulkProcessor,MANUAL_TYPE) }
for word := range tmpMap {
if _, exist := usedMap.Load(word); !exist {
addWord(word, bulkProcessor)
} }
} }
} }
func addWord(keyword string, processor *elastic.BulkProcessor, wordType string) { func addWord(keyword string, processor *elastic.BulkProcessor, wordType string) {
var w = new(Word) var w = new(Word)
switch wordType {
case BRAND_TYPE: w.IsBrand = true
case CATEGORY_TYPE: w.IsCategory = true
case MANUAL_TYPE: { w.IsManual = true; w.ManualValue = manualMap[keyword]}
}
w.Keyword = keyword w.Keyword = keyword
w.KeywordVersion = dateStr w.KeywordVersion = dateStr
processWord(w) processWord(w)
...@@ -322,18 +313,18 @@ func processWord(w *Word) { ...@@ -322,18 +313,18 @@ func processWord(w *Word) {
if _, isExist := brandMap[w.Keyword]; isExist { if _, isExist := brandMap[w.Keyword]; isExist {
w.IsBrand = true w.IsBrand = true
usedMap.Store(w.Keyword + BRAND_TYPE, true) usedMap.Store(w.Keyword, true)
} }
if _, isExist := manualMap[w.Keyword]; isExist { if _, isExist := manualMap[w.Keyword]; isExist {
w.IsManual = true w.IsManual = true
w.ManualValue = manualMap[w.Keyword] w.ManualValue = manualMap[w.Keyword]
usedMap.Store(w.Keyword + MANUAL_TYPE,true) usedMap.Store(w.Keyword,true)
} }
if _, isExist := categoryMap[w.Keyword]; isExist { if _, isExist := categoryMap[w.Keyword]; isExist {
w.IsCategory = true w.IsCategory = true
usedMap.Store(w.Keyword + CATEGORY_TYPE, true) usedMap.Store(w.Keyword, true)
} }
if _, isExist := sensitiveMap[w.Keyword]; isExist { if _, isExist := sensitiveMap[w.Keyword]; isExist {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment