-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
144 lines (129 loc) · 4.78 KB
/
main.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package main
import (
"bufio"
"fmt"
"net/url"
"os"
"strconv"
"strings"
"time"
"github.com/ashik112/goimdb/decompresser"
"github.com/ashik112/goimdb/downloader"
"github.com/ashik112/goimdb/gosolr"
"github.com/ashik112/goimdb/model"
)
var FilePath = "./files/"
var ArchivePath = FilePath + "archive/"
var DecompressedPath = FilePath + "decompressed/"
var JsonPath = FilePath + "json/"
var GzipFile = model.Files{"title.basics.tsv.gz", "title.ratings.tsv.gz", "title.principals.tsv.gz", "name.basics.tsv.gz", "title.crew.tsv.gz", "title.episode.tsv.gz"}
var TsvFile = model.Files{"title.basics.tsv", "title.ratings.tsv", "title.principals.tsv", "name.basics.tsv", "title.crew.tsv", "title.episode.tsv"}
var SolrConfig = model.Solr{"localhost", 8983, "imdb"}
var Imdb = model.Imdb{"https://datasets.imdbws.com/"}
/*DownloadFiles does..*/
func DownloadFiles() {
downloader.Download(ArchivePath, Imdb.URL+GzipFile.Title)
downloader.Download(ArchivePath, Imdb.URL+GzipFile.Ratings)
downloader.Download(ArchivePath, Imdb.URL+GzipFile.Persons)
downloader.Download(ArchivePath, Imdb.URL+GzipFile.Crew)
downloader.Download(ArchivePath, Imdb.URL+GzipFile.People)
downloader.Download(ArchivePath, Imdb.URL+GzipFile.Episode)
}
/*GetFiles does ...*/
func GetFiles() {
startDecompress := time.Now()
doneRatings := make(chan int)
donePrincipals := make(chan int)
doneEpisode := make(chan int)
doneCrew := make(chan int)
doneTitleBasics := make(chan int)
doneNameBasics := make(chan int)
go decompresser.UnGzip(ArchivePath+GzipFile.Title, DecompressedPath+GzipFile.Title, doneTitleBasics)
go decompresser.UnGzip(ArchivePath+GzipFile.Ratings, DecompressedPath+GzipFile.Ratings, doneRatings)
go decompresser.UnGzip(ArchivePath+GzipFile.People, DecompressedPath+GzipFile.People, donePrincipals)
go decompresser.UnGzip(ArchivePath+GzipFile.Persons, DecompressedPath+GzipFile.Persons, doneNameBasics)
go decompresser.UnGzip(ArchivePath+GzipFile.Crew, DecompressedPath+GzipFile.Crew, doneCrew)
go decompresser.UnGzip(ArchivePath+GzipFile.Episode, DecompressedPath+GzipFile.Episode, doneEpisode)
<-doneRatings
<-donePrincipals
<-doneEpisode
<-doneCrew
<-doneTitleBasics
<-doneNameBasics
elsapsedDecompress := time.Since(startDecompress)
fmt.Println("Decompression Process took ", elsapsedDecompress)
}
func CreateSolrFields() {
doneTitles := make(chan bool)
go gosolr.CreateSolrFields(SolrConfig.Hostname, SolrConfig.Port, SolrConfig.Core, JsonPath+"all_fields.json", doneTitles)
<-doneTitles
}
func UploadSolrData() {
start := time.Now()
donePrincipals := make(chan bool)
go gosolr.UploadDoc(SolrConfig.Hostname, SolrConfig.Port, SolrConfig.Core, DecompressedPath+TsvFile.People, donePrincipals)
<-donePrincipals
fmt.Println("Uploading Principals took ", time.Since(start))
donePersons := make(chan bool)
go gosolr.UploadDoc(SolrConfig.Hostname, SolrConfig.Port, SolrConfig.Core, DecompressedPath+TsvFile.Persons, donePersons)
<-donePersons
doneRatings := make(chan bool)
go gosolr.UploadDoc(SolrConfig.Hostname, SolrConfig.Port, SolrConfig.Core, DecompressedPath+TsvFile.Ratings, doneRatings)
doneCrew := make(chan bool)
go gosolr.UploadDoc(SolrConfig.Hostname, SolrConfig.Port, SolrConfig.Core, DecompressedPath+TsvFile.Crew, doneCrew)
<-doneRatings
<-doneCrew
doneTitles := make(chan bool)
go gosolr.UploadDoc(SolrConfig.Hostname, SolrConfig.Port, SolrConfig.Core, DecompressedPath+TsvFile.Title, doneTitles)
doneEpisodes := make(chan bool)
go gosolr.UploadDoc(SolrConfig.Hostname, SolrConfig.Port, SolrConfig.Core, DecompressedPath+TsvFile.Episode, doneEpisodes)
<-doneTitles
<-doneEpisodes
}
func contains(arr []string, str string) bool {
for _, a := range arr {
if a == str {
return true
}
}
return false
}
func CMD(args []string) {
switch {
case contains(os.Args[1:], "update"):
gosolr.DeleteAll(SolrConfig.Hostname, SolrConfig.Port, SolrConfig.Core)
UploadSolrData()
case contains(os.Args[1:], "insert"):
UploadSolrData()
case contains(os.Args[1:], "init"):
DownloadFiles()
GetFiles()
CreateSolrFields()
UploadSolrData()
default:
fmt.Println("No valid param found")
}
}
func SearchMovie() {
start := time.Now()
fmt.Print("Enter Movie title: ")
reader := bufio.NewReader(os.Stdin)
title, _ := reader.ReadString('\n')
title = strings.Trim(title, "\n")
title = `"` + title + `"`
titleType := `"` + "movie" + `"`
q := "primaryTitle:" + title + "AND titleType:" + titleType
t := &url.URL{Fragment: q}
q = strings.Trim(t.String(), "#")
url := "http://" + SolrConfig.Hostname + ":" + strconv.Itoa(SolrConfig.Port) + "/solr/" + SolrConfig.Core + "/select?q=" + q+"&rows=5"
fmt.Println(url)
gosolr.GetTitle(url)
fmt.Println("... took ", time.Since(start))
}
func main() {
// gosolr.DeleteAll("localhost", 8983, "imdb")
// UploadSolrData()
// DownloadFiles()
// GetFiles()
SearchMovie()
}