-
Notifications
You must be signed in to change notification settings - Fork 5
/
search.html
232 lines (231 loc) · 6.34 KB
/
search.html
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Search</title>
<script src="js/jquery-3.3.1.min.js"></script>
<style>
.row { display: flex; }
.col { flex: 50%; margin: 5px; }
#sample { white-space: pre-wrap; }
</style>
<script type="application/json" class="js-hypothesis-config">
{ "openSidebar": true }
</script>
<script src="js/hypothesis.js" async></script>
<link rel="canonical" href="https://hbz.github.io/swib18-workshop/search.html"/>
</head>
<body>
<div class='row'>
<div class='col'>
<h3 style='margin-top:0px'>Document structure:</h3>
<div ><code><pre id='sample'>
{
"@context": "http://localhost:3000/context.json",
"id": "http://id.loc.gov/resources/works/c000000026",
"type": [
"Work",
"Text"
],
"adminMetadata": {
"type": "AdminMetadata",
"encodingLevel": [
{
"type": "EncodingLevel",
"code": "f"
}
],
"changeDate": "2013-04-08T08:09:51",
"creationDate": "1998-07-08",
"descriptionConventions": [
{
"type": "DescriptionConventions",
"code": "aacr"
}
],
"generationProcess": [
{
"type": "GenerationProcess",
"label": "DLC marc2bibframe2 v1.3.0-SNAPSHOT"
}
],
"identifiedBy": [
{
"type": "Local",
"http://www.w3.org/1999/02/22-rdf-syntax-ns#value": "26"
}
],
"source": [
{
"type": [
"Source",
"Agent"
],
"label": "DLC"
},
{
"type": [
"Source",
"Agent"
],
"label": "DLC"
}
],
"status": [
{
"type": "Status",
"code": "c"
}
]
},
"classification": [
{
"type": "ClassificationLcc",
"classificationPortion": "KF223.R93",
"itemPortion": "R93 1811",
"source": [
{
"id": "http://id.loc.gov/vocabulary/organizations/dlc",
"type": "Source"
}
]
}
],
"contribution": [
{
"type": [
"Contribution",
"PrimaryContribution"
],
"agent": {
"id": "http://id.loc.gov/resources/works/26#Agent100-12",
"type": [
"Agent",
"Person"
],
"name00MarcKey": "1001 $aRyan, George,$dactive 1811.",
"name00MatchKey": "Ryan, George, active 1811.",
"primaryContributorName00MatchKey": "Ryan, George, active 1811.",
"label": "Ryan, George, active 1811."
},
"role": {
"id": "http://id.loc.gov/vocabulary/relators/ctb",
"type": "Role"
}
},
{
"type": "Contribution",
"agent": {
"id": "http://id.loc.gov/resources/works/26#Agent710-20",
"type": [
"Agent",
"Jurisdiction"
],
"name10MarcKey": "7101 $aNew Hampshire.$bSuperior Court of Judicature.",
"name10MatchKey": "New Hampshire. Superior Court of Judicature.",
"label": "New Hampshire. Superior Court of Judicature."
},
"role": {
"id": "http://id.loc.gov/vocabulary/relators/ctb",
"type": "Role"
}
}
],
"geographicCoverage": [
{
"id": "http://id.loc.gov/vocabulary/geographicAreas/n-us-nh",
"type": "GeographicCoverage"
}
],
"language": [
{
"id": "http://id.loc.gov/vocabulary/languages/eng",
"type": "Language"
}
],
"subject": [
{
"id": "http://id.loc.gov/resources/works/26#Agent600-18",
"type": [
"Agent",
"Person",
"ComplexSubject"
],
"name00MarcKey": "60010$aRyan, George,$dactive 1811$xTrials, litigation, etc.",
"name00MatchKey": "Ryan, George, active 1811",
"authoritativeLabel": "Ryan, George, active 1811--Trials, litigation, etc.",
"label": "Ryan, George, active 1811"
},
{
"id": "http://id.loc.gov/resources/works/26#Topic650-19",
"type": [
"Topic",
"ComplexSubject"
],
"authoritativeLabel": "Trials (Robbery)--New Hampshire--Charlestown.",
"componentList": [
{
"type": "Topical",
"authoritativeLabel": "Trials (Robbery)"
},
{
"type": "Geographic",
"authoritativeLabel": "New Hampshire"
},
{
"type": "Geographic",
"authoritativeLabel": "Charlestown"
}
],
"label": "Trials (Robbery)--New Hampshire--Charlestown."
}
],
"title": {
"type": "Title",
"titleSortKey": "Report of the trial of George Ryan : before the Superior Court at Charlestown, N.H., in the county of Cheshire, May term 1811, for highway robbery.",
"mainTitle": "Report of the trial of George Ryan",
"subtitle": "before the Superior Court at Charlestown, N.H., in the county of Cheshire, May term 1811, for highway robbery",
"label": "Report of the trial of George Ryan : before the Superior Court at Charlestown, N.H., in the county of Cheshire, May term 1811, for highway robbery."
},
"label": "Report of the trial of George Ryan : before the Superior Court at Charlestown, N.H., in the county of Cheshire, May term 1811, for highway robbery."
}</pre></code></div>
</div>
<div class='col'>
<input id='search' type='text' style='width: 99%' placeholder='Search query... (e.g. label:letters, wildcards with *)' autofocus/>
<div id='result'></div>
</div>
</div>
<script>
$.ajax({
url: 'http://localhost:9200/loc/work/c000000026/_source',
success: function(result) {
console.log(JSON.stringify(result));
$("#sample").html(JSON.stringify(result, null, 2));
},
error: function(jqXHR, textStatus, errorThrown) {
console.log(textStatus, ': ', errorThrown);
}
});
$('#search').keyup(
function() {
var query = encodeURIComponent($('#search').val());
var url = `http://localhost:9200/loc/work/_search?size=100&q=${query}`;
$.ajax({
url: url,
success: function(result) {
console.log(JSON.stringify(result));
$("#result").html(`<br/>Hits: ${result.hits.total} <hr/>`);
var hits = result.hits.hits;
for (let hit of hits) {
var link = `<a href='http://localhost:9200/loc/work/${hit._id}/_source'>${hit._source.label}</a>`;
$("#result").append(link + '<hr/>');
}
},
error: function(jqXHR, textStatus, errorThrown) {
console.log(textStatus, ': ', errorThrown, ': ', url);
}
});
});
</script>
</body>
</html>