diff options
author | uvok cheetah | 2020-05-23 15:43:32 +0200 |
---|---|---|
committer | uvok cheetah | 2020-05-23 15:43:32 +0200 |
commit | 0150a1151cce7e278284667c11ad2e5e97a7f13d (patch) | |
tree | 8eb6522fa9d3f2983327bfdc012d23bc48f56754 /search.html | |
parent | def6b0ae49ffcacee91c33a55388b4083b95774d (diff) |
Create query function
Diffstat (limited to 'search.html')
-rw-r--r-- | search.html | 39 |
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); |