-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.html
92 lines (79 loc) · 2.3 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
<!DOCTYPE html>
<html lang="de-DE">
<head>
<title>MR DEAD & MRS FREE</title>
<meta charset="utf-8">
<meta name="theme-color" content="#000">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link href="search.css" rel="stylesheet" type="text/css">
<script src="lib/lunr.min.js"></script>
</head>
<body>
<main>
<input id="searchfield" placeholder="Suche..." type="text" onkeyup="search(this.value)" onchange="search(this.value)">
<p>Bitte geben Sie mind. 3 Zeichen ein.</p>
<table id="resultlist">
</table>
<div id="overlay">Loading & Indexing Database...</div>
</main>
<script>
var xmlhttp, db, index;
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
};
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
db = JSON.parse(xmlhttp.responseText).deadandfreeSQL;
index = lunr(function() {
this.field('ARTIST', {
boost: 10
})
this.field('TITLE', {
boost: 10
})
this.field('KOMMENTAR')
this.field('D1')
this.ref('ID')
});
for (var i = 0; i < db.length; i++) {
db[i].ID = i;
index.add(db[i]);
};
document.getElementById("overlay").classList.add("done");
document.getElementById("searchfield").focus();
};
};
xmlhttp.open("GET", "./db/DBimport.json", true);
xmlhttp.send();
function createresult(obj) {
var el = document.createElement("tr");
el.innerHTML = "<td>" + [
obj.ARTIST,
obj.TITLE,
obj.FMT,
obj.EUR + "€"
].join("</td><td>") + "</td>";
return el;
}
function search(keyword) {
var resultlist = document.getElementById("resultlist");
resultlist.innerHTML = "<tr><th>ARTIST</th><th>ALBUM</th><th>FORMAT</th><th>PREIS</th></tr>";
var results = [];
if(keyword.length > 2) {
results = index.search(keyword);
resultlist.style.display = "block";
resultlist.previousElementSibling.style.display = "none";
} else {
results = [];
resultlist.style.display = "none";
resultlist.previousElementSibling.style.display = "block";
}
for (var i = 0; i < results.length; i++) {
resultlist.appendChild(createresult(db[results[i].ref]));
}
}
</script>
</body>
</html>