This repository has been archived by the owner on May 9, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbatchsearch.tag
170 lines (126 loc) · 3.79 KB
/
batchsearch.tag
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<batchsearch>
<form>
<div class="row">
<div class="col-sm-3">
<h1>Hoover</h1>
</div>
<div class="col-sm-8">
<div class="form-group">
<textarea
placeholder="search terms, one per line ..."
class="form-control"
name="terms"
>{termsArg}</textarea>
</div>
<div class="form-inline">
<div class="form-group">
<label for="search-size">Results per term</label>
<select class="form-control" id="search-size" name="size">
<option
each={size in sizeOptions}
selected={size==this.parent.size}
>{size}</option>
</select>
</div>
<button type="submit" class="btn btn-primary btn-sm">search</button>
<p class="pull-sm-right">
<a href="/">simple search</a>
</p>
</div>
</div>
<div class="col-sm-1">
<navbar></navbar>
</div>
</div>
<div class="row">
<div id="collections-box" class="col-sm-3">
<p if={!collections}>loading collections ...</p>
<div each={collections} class="checkbox">
<label>
<input type="checkbox" value="{name}"
checked={selectedCollections.indexOf(name) > -1}
onchange={onSelectCollection}>
{title}
</label>
</div>
<em if={!collections.length}>none available</em>
<input id="collections-input" type="hidden">
</div>
<div class="col-sm-9">
<div each={query in queries}>
<h3>{query.q}</h3>
<search query={query}></search>
</div>
</div>
</div>
</form>
<script>
function getCollections(callback) {
$.ajax({
url: '/collections',
success: callback,
})
}
function saveCollections() {
var checkboxes = $('#collections-box input[type=checkbox]')
var collectionsInput = $('#collections-input')
if(checkboxes.filter(':not(:checked)').length > 0) {
var selected = ''+(
checkboxes
.filter(':checked')
.get()
.map(function(c) { return c.value })
.join(' ')
)
collectionsInput.attr('name', 'collections').val(selected)
}
else {
collectionsInput.attr('name', null).val('')
}
}
function parseQuery(url) {
var rv = {}
if(url.indexOf('?') > -1) {
url.match(/\?(.*)/)[1].split('&').forEach(function(pair) {
var kv = pair.split('=').map(decodeURIComponent)
var k = kv[0], v = kv[1]
if(! rv[k]) { rv[k] = [] }
rv[k].push(v)
})
}
return rv
}
onSelectCollection(evt) {
saveCollections()
}
var args = parseQuery(window.location.href)
this.sizeOptions = [5, 10, 20]
this.size = args.size ? +args.size : 5
getCollections(function(resp) {
this.collections = resp
if(args.collections) {
var sel = ''+args.collections
this.selectedCollections = sel ? sel.split('+') : []
}
else {
this.selectedCollections = resp.map(function(c) { return c.name })
}
this.termsArg = args.terms ? ("" + args.terms).replace(/\+/g, ' ') : ""
if(this.termsArg) {
this.queries = this.termsArg.split('\n')
.map(function(line) { return line.trim() })
.filter(function(line) { return !! line })
.map(function(line) {
return {
q: line.trim(),
collections: this.selectedCollections,
page: 1,
size: this.size,
}
}.bind(this))
}
this.update()
saveCollections()
}.bind(this))
</script>
</batchsearch>