-
Notifications
You must be signed in to change notification settings - Fork 1
/
querybuilder.go
114 lines (92 loc) · 2.84 KB
/
querybuilder.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
package main
import (
"fmt"
"net/url"
"time"
)
var ARCHIVE_GRID_URL_TEMPLATE []string = []string{
"https://researchworks.oclc.org/archivegrid/?q=%s&limit=100",
//"https://researchworks.oclc.org/archivegrid/?q=%s&limit=10",
}
type QUERYDEBUG int
const (
TOOMANYRESULTS = iota
NORESULTS
ACCEPTABLERESULTS
)
type MusicianQuery struct {
Id HashSum `json:"query_id"` // for now init to same as MusicianId one musician one query
//MusicianId HashSum `json:"musician_id"`
Url string `json:"url"`
Timestamp time.Time `json:"timestamp"` // should be initialized to a NEVERQUERIED value
ResultSize int `json:"result_size"` // should be initialized to a NEVERQUERIED value
Matches int `json:"Matches"`
DebugNotes QUERYDEBUG `json:"debug_notes"`
}
func (mq *MusicianQuery) String() string {
return string(mq.Url)
}
func NewMusicianQuery(id HashSum, url string) (newMusicianQuery *MusicianQuery) {
newMusicianQuery = new(MusicianQuery)
newMusicianQuery = &MusicianQuery{
Id: id,
//MusicianId: m.Id,
Url: url,
// Timestamp should be initialized to a NEVERQUERIED value
ResultSize: -1, //should be initialized to a NEVERQUERIED value
Matches: -1,
}
return newMusicianQuery
//return &MusicianQuery{
// Id: id,
// //MusicianId: m.Id,
// Url: url,
// // Timestamp should be initialized to a NEVERQUERIED value
// ResultSize: -1, //should be initialized to a NEVERQUERIED value
//}
}
func (mq *MusicianQuery) SetResultCount(count int) {
mq.Timestamp = time.Now()
mq.ResultSize = count
}
func (mq *MusicianQuery) Destroy() {
mq.Id = ""
//mq.MusicianId
mq.Url = ""
mq.Timestamp = time.Time{}
mq.ResultSize = 0
mq.DebugNotes = QUERYDEBUG(0)
return
}
//type MusiciansQueries map[HashSum][]MusicianQuery
type MusiciansQueries map[HashSum]*MusicianQuery
func BuildQueries(ms MusiciansMap) (mq MusiciansQueries) {
mq = MusiciansQueries{}
for _, m := range ms {
query := buildQuery(m, ARCHIVE_GRID_URL_TEMPLATE[0], MusicianNamesVariation(FULL))
mq[m.Id] = query
}
return mq
}
func buildQuery(m *Musician, template string, variation MusicianNamesVariation) *MusicianQuery {
querydata := url.QueryEscape(m.QueryFragment(variation))
fullquery := fmt.Sprintf(template, querydata)
return NewMusicianQuery(m.Id, fullquery)
//return MusicianQuery{
// Id: m.Id,
// //MusicianId: m.Id,
// Url: fullquery,
// // Timestamp should be initialized to a NEVERQUERIED value
// ResultSize: -1, //should be initialized to a NEVERQUERIED value
//}
}
//func BuildQuery(m Musician, template string) MusicianQuery {
// query := url.QueryEscape(fmt.Sprintf(ARCHIVE_GRID_URL_TEMPLATE[0], m.FullName()))
// queries := []string{query}
// return MusicianQueries{m.id: queries}
//}
///////////
// var ARCHIVE_GRID_URL_PATTERNS []string = []string{
// "https://researchworks.oclc.org/archivegrid/?q=%s&limit=100",
// }
///////////////