-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathsolr_update.go
75 lines (67 loc) · 1.43 KB
/
solr_update.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package main
import (
"fmt"
"github.com/franela/goreq"
"time"
)
func main() {
// Add()
Del()
}
func Del() {
item := DelSolr{}
item.Del.Query = `title:cyeam.com`
item.Del.CommitWithin = 1000
req := goreq.Request{
Method: "POST",
Uri: "http:///solr/post/update?wt=json",
ContentType: "application/json",
Body: item,
// Proxy: "http://127.0.0.1:8888",
}
res, err := req.Do()
if err != nil {
fmt.Println(err, "*****")
return
}
str, _ := res.Body.ToString()
fmt.Println("del success", str)
}
func Add() {
item := AddSolr{}
item.Add.Doc.Link = time.Now().String()
item.Add.Doc.Title = "cyeam.com"
item.Add.Overwrite = true
item.Add.CommitWithin = 1000
req := goreq.Request{
Method: "POST",
Uri: "http:///solr/post/update?wt=json",
ContentType: "application/json",
Body: item,
// Proxy: "http://127.0.0.1:8888",
}
res, err := req.Do()
if err != nil {
fmt.Println(err, "*****")
return
}
str, _ := res.Body.ToString()
fmt.Println("add success", str)
}
type AddSolr struct {
Add struct {
Doc SolrModel `json:"doc"`
Overwrite bool `json:"overwrite"`
CommitWithin int `json:"commitWithin"`
} `json:"add"`
}
type SolrModel struct {
Link string `json:"link"`
Title string `json:"title"`
}
type DelSolr struct {
Del struct {
Query string `json:"query"`
CommitWithin int `json:"commitWithin"`
} `json:"delete"`
}