summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--search.html39
1 files changed, 18 insertions, 21 deletions
diff --git a/search.html b/search.html
index ed9efab..38f17b3 100644
--- a/search.html
+++ b/search.html
@@ -2,17 +2,6 @@
layout: page
---
<script src="/assets/js/lunr.min.js"></script>
-
-<p>
-<input id="input_qterm"></input>
-<button id="qsubmit">Submit</button>
-</p>
-
-<h1>Search results for <span id="qterm"></span></h1>
-<div id="results">
-</div>
-
-
<script>
// data
var pages = [
@@ -36,16 +25,26 @@ layout: page
this.add(doc);
}, this);
});
+</script>
+<p>
+<input id="input_qterm"></input>
+<button id="qsubmit">Submit</button>
+</p>
+
+<h1>Search results for <span id="qterm"></span></h1>
+<div id="results">
+</div>
+
+
+<script>
// search
- var queryterm = "zeit";
+ function query(queryterm) {
var result = idx.search(queryterm);
+ const rbase = document.getElementById("results")
+ rbase.textContent = "";
if(result.length) {
- var root = document.getElementById("results").appendChild(
- document.createElement("ul")
- );
-
-
+ var root = rbase.appendChild(document.createElement("ul"));
result.forEach(r => {
const p = pages.find(p => p.id == r.ref);
var li = document.createElement("li")
@@ -55,16 +54,14 @@ layout: page
el = li.appendChild(document.createElement("span"));
el.textContent = " [score: " + r.score.toString() + "]";
root.appendChild(li);
-
});
-
} else {
var el = document.createElement("p");
el.textContent = "No results";
- document.getElementById("results").appendChild(el);
+ rbase.appendChild(el);
}
document.getElementById("qterm").textContent = queryterm;
-
+ };
const qbox = document.getElementById("input_qterm");
document.getElementById("qsubmit").onclick = ev => {
alert(qbox.value);