wbrooks commited on
Commit
67e646a
·
1 Parent(s): b6127b6

adding the search page back #3

Browse files
Files changed (1) hide show
  1. docs/index.html +91 -0
docs/index.html ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <title>Search</title>
6
+
7
+ <style>
8
+ table {
9
+ border-collapse: collapse;
10
+ margin-top: 20px;
11
+ }
12
+ table, th, td {
13
+ border: 1px solid #aaa;
14
+ padding: 6px 12px;
15
+ }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <h2>Search</h2>
21
+
22
+ <input type="text" id="searchBox" size="80" placeholder="Search..."><br>
23
+ <button onclick="runSearch()" id="searchButton">Search</button>
24
+
25
+ <div id="result"></div>
26
+
27
+ <script>
28
+ async function runSearch() {
29
+ const q = document.getElementById("searchBox").value;
30
+ const resultDiv = document.getElementById("result");
31
+ resultDiv.innerHTML = "Searching...";
32
+
33
+ // Your FastAPI endpoint (example):
34
+ const url = `https://wbrooks-coul-document-search.hf.space/search?q=${encodeURIComponent(q)}`;
35
+
36
+ try {
37
+ const response = await fetch(url);
38
+ if (!response.ok) {
39
+ resultDiv.innerHTML = `Error: ${response.status}`;
40
+ return;
41
+ }
42
+
43
+ const data = await response.json();
44
+ resultDiv.innerHTML = jsonToTable(data);
45
+
46
+ } catch (err) {
47
+ resultDiv.innerHTML = "Request failed: " + err;
48
+ }
49
+ }
50
+
51
+ // Convert array of objects → HTML table
52
+ function jsonToTable(jsonData) {
53
+ if (!jsonData || jsonData.length === 0) {
54
+ return "<p>No results.</p>";
55
+ }
56
+
57
+ const cols = Object.keys(jsonData[0]);
58
+
59
+ let html = "<table><thead><tr>";
60
+ cols.forEach(col => html += `<th>${col}</th>`);
61
+ html += "</tr></thead><tbody>";
62
+
63
+ jsonData.forEach(row => {
64
+ html += "<tr>";
65
+ cols.forEach(col => html += `<td>${row[col]}</td>`);
66
+ html += "</tr>";
67
+ });
68
+
69
+ html += "</tbody></table>";
70
+ return html;
71
+ }
72
+
73
+ const input = document.getElementById("searchBox");
74
+ const button = document.getElementById("searchBtn");
75
+
76
+ input.addEventListener("keydown", function(event) {
77
+ if (event.key === "Enter") { // check if Enter/Return is pressed
78
+ event.preventDefault(); // prevent default form submission if any
79
+ button.click(); // trigger the button click
80
+ }
81
+ });
82
+
83
+ button.addEventListener("click", function() {
84
+ const value = input.value;
85
+ console.log("Search for:", value);
86
+ // Here you could call fetch() to your API
87
+ });
88
+ </script>
89
+
90
+ </body>
91
+ </html>