forked from QLeelulu/ohlala
/
AddHistoryLinkForSearch.go
77 lines (48 loc) · 1.36 KB
/
AddHistoryLinkForSearch.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"github.com/QLeelulu/goku"
"github.com/QLeelulu/ohlala/golink/utils"
"github.com/QLeelulu/ohlala/golink/models"
"fmt"
)
func main() {
//ls := utils.LinkSearch{}
//ls.SearchLink("名次", 1, 30)
//return
var db *goku.MysqlDB = models.GetDB()
defer db.Close()
rows, _ := db.Query("SELECT l.id,l.title,l.context,l.topics,u.Name,l.context_type FROM `link` l INNER JOIN `user` u ON l.user_id=u.id")
var linkId int64
var title string
var context string
var topics string
var userName string
var contextType int
for rows.Next() {
rows.Scan(&linkId, &title, &context, &topics, &userName, &contextType)
addLinkForSearch(contextType, linkId, title, context, topics, userName)
}
fmt.Println("执行完成")
}
//添加link到es搜索; contextType:0: url, 1:文本
func addLinkForSearch(contextType int, linkId int64, title string, context string, topics string, userName string) {
m := make(map[string]interface{})
m["id"] = linkId
m["title"] = title
m["context"] = context
m["topics"] = topics
m["username"] = userName
if contextType == 0 {
m["host"] = utils.GetUrlHost(m["context"].(string))
m["context"] = ""
} else {
m["host"] = ""
}
ls := utils.LinkSearch{}
_, err := ls.AddLink(m)
if err != nil {
fmt.Println("失败: ", m)
} else {
fmt.Println("成功: ", m)
}
}