-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindexer.go
More file actions
51 lines (43 loc) · 862 Bytes
/
Copy pathindexer.go
File metadata and controls
51 lines (43 loc) · 862 Bytes
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
package blevedemo
import (
"encoding/csv"
"fmt"
"io"
"os"
"strconv"
"github.com/PuerkitoBio/goquery"
)
func Index(filePath string) error {
file, fileError := os.Open(filePath)
if fileError != nil {
return fileError
}
defer file.Close()
reader := csv.NewReader(file)
count := 0
for {
data, dataErr := reader.Read()
if dataErr != nil {
if dataErr != io.EOF {
return dataErr
}
return nil
}
if len(data) != 2 {
continue
}
doc, docErr := goquery.NewDocument("http://" + data[0])
if docErr != nil {
fmt.Println("Error: ", data[0], docErr.Error())
continue
}
if indexErr := indexer.Index(strconv.Itoa(count), Page{
Title: doc.Find("title").Text(),
Content: doc.Find("body").Find("script").Remove().End().Text(),
Tags: data[1],
}); indexErr != nil {
return indexErr
}
count += 1
}
}