-
Notifications
You must be signed in to change notification settings - Fork 0
/
fuseSearch.html
250 lines (235 loc) · 7.86 KB
/
fuseSearch.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>JSON File Search</title>
<!-- Add Bootstrap CSS link -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
</head>
<body>
<div class="container mt-4">
<h1>JSON File Search</h1>
<!-- No file input, using test JSON data directly in the script -->
<div class="form-group mt-3">
<div id="searchData" class="input-group">
<input type="text" class="form-control" id="searchInput" placeholder="Enter text to search">
<div class="input-group-append">
<button class="btn btn-primary" onclick="searchJson()">Search</button>
</div>
<div class="form-check"><input name="trainCheck" id="gis" class="form-check-input" type="checkbox"
value="apprenticeship" /> <label class="form-check-label" for="gis">Apprenticeship</label></div>
<div class="form-check"><input name="trainCheck" id="training" class="form-check-input" type="checkbox"
value="training" /> <label class="form-check-label" for="internship">Internship</label>
</div>
<div class="form-check"><input name="trainCheck" id="drone" class="form-check-input" type="checkbox"
value="drone" />
<label class="form-check-label" for="certificate">Certificate Program</label></div>
<div class="form-check"><input name="trainCheck" id="research" class="form-check-input" type="checkbox"
value="research" /> <label class="form-check-label" for="associate">Associate's Degree</label>
</div>
</div>
</div>
<!-- Display search terms as pills inside the search input -->
<div class="form-group mt-3" id="searchTermsContainer"></div>
<!-- Display type-ahead suggestions as Bootstrap pills -->
<div class="mt-3" id="typeAhead"></div>
<!-- Display search results as Bootstrap list -->
<ul class="list-group mt-3" id="searchResults"></ul>
</div>
<!-- Add Bootstrap JS script -->
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
<script>
const list = [{
"title": "Old Man's War",
"author": {
"firstName": "John",
"lastName": "Scalzi"
}
},
{
"title": "The Lock Artist",
"author": {
"firstName": "Steve",
"lastName": "Hamilton"
}
},
{
"title": "HTML5",
"author": {
"firstName": "Remy",
"lastName": "Sharp"
}
},
{
"title": "Right Ho Jeeves",
"author": {
"firstName": "P.D",
"lastName": "Woodhouse"
}
},
{
"title": "The Code of the Wooster",
"author": {
"firstName": "P.D",
"lastName": "Woodhouse"
}
},
{
"title": "Thank You Jeeves",
"author": {
"firstName": "P.D",
"lastName": "Woodhouse"
}
},
{
"title": "The DaVinci Code",
"author": {
"firstName": "Dan",
"lastName": "Brown"
}
},
{
"title": "Angels & Demons",
"author": {
"firstName": "Dan",
"lastName": "Brown"
}
},
{
"title": "The Silmarillion",
"author": {
"firstName": "J.R.R",
"lastName": "Tolkien"
}
},
{
"title": "Syrup",
"author": {
"firstName": "Max",
"lastName": "Barry"
}
},
{
"title": "The Lost Symbol",
"author": {
"firstName": "Dan",
"lastName": "Brown"
}
},
{
"title": "The Book of Lies",
"author": {
"firstName": "Brad",
"lastName": "Meltzer"
}
},
{
"title": "Lamb",
"author": {
"firstName": "Christopher",
"lastName": "Moore"
}
},
{
"title": "Fool",
"author": {
"firstName": "Christopher",
"lastName": "Moore"
}
},
{
"title": "Incompetence",
"author": {
"firstName": "Rob",
"lastName": "Grant"
}
},
{
"title": "Fat",
"author": {
"firstName": "Rob",
"lastName": "Grant"
}
},
{
"title": "Colony",
"author": {
"firstName": "Rob",
"lastName": "Grant"
}
},
{
"title": "Backwards, Red Dwarf",
"author": {
"firstName": "Rob",
"lastName": "Grant"
}
},
{
"title": "The Grand Design",
"author": {
"firstName": "Stephen",
"lastName": "Hawking"
}
},
{
"title": "The Book of Samson",
"author": {
"firstName": "David",
"lastName": "Maine"
}
},
{
"title": "The Preservationist",
"author": {
"firstName": "David",
"lastName": "Maine"
}
},
{
"title": "Fallen",
"author": {
"firstName": "David",
"lastName": "Maine"
}
},
{
"title": "Monster 1959",
"author": {
"firstName": "David",
"lastName": "Maine"
}
}
]
//const Fuse = require('fuse.js');
const fuseOptions = {
// isCaseSensitive: false,
// includeScore: false,
// shouldSort: true,
// includeMatches: false,
// findAllMatches: false,
// minMatchCharLength: 1,
// location: 0,
// threshold: 0.6,
// distance: 100,
// useExtendedSearch: false,
// ignoreLocation: false,
// ignoreFieldNorm: false,
// fieldNormWeight: 1,
keys: [
"title",
"author.firstName"
]
};
const fuse = new Fuse(list, fuseOptions);
// Change the pattern
const searchPattern = "tr"
function search() {
return fuse.search(searchPattern)
}
</script>
</body>
</html>