summaryrefslogtreecommitdiff
path: root/search.html
blob: 2768f1a5d6b8beb56ad642a87de5404cb5a3f4d3 (plain)
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
---
title: Search
layout: page
in_navbar: true
lang: "en"
---

<p><i>Search requires JavaScript.</i></p>

<script src="/assets/js/lunr.min.js"></script>
<script src="/assets/js/search.js"></script>

<form id="searchForm">
  <p>
    <input id="input_qterm" type="text">
    <button id="qsubmit" type="submit">Search</button>
  </p>
</form>

<h2>Results for <span id="qterm"></span></h1>
<div id="results">
</div>


<script>
  // search
  function query(queryterm) {
      var result = do_search(queryterm);
      const rbase = document.getElementById("results");
      rbase.textContent = "";
      if (result.length) {
          var root = rbase.appendChild(document.createElement("ul"));
          result.forEach(function(p) {
              var li = document.createElement("li");
              var el = li.appendChild(document.createElement("a"));
              el.textContent = p.title;
              el.href = p.url;
              // converted to page, to more score
              /*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";
          rbase.appendChild(el);
      }
      document.getElementById("qterm").textContent = queryterm;
  }

  // Function to be called on submit
  function submitSearch() {
    console.log("Search submitted");
    const qbox = document.getElementById("input_qterm").value;
    if (qbox.length !== 0) {
      query(qbox);
    }
  }

  // Attach event handler to form submission
  document.getElementById("searchForm").onsubmit = function(ev) {
    ev.preventDefault(); // Prevent default form submission behavior
    submitSearch();
  };
</script>