forked from cebe/js-search
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.html
60 lines (48 loc) · 1.55 KB
/
example.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
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="./jssearch.js"></script>
<script src="./jssearch.index.js"></script>
<script type="text/javascript">
$( document ).ready(function() {
$('#searchbox').on("keyup", function() {
var result = jssearch.search($(this).val());
$('#query').html(jssearch.queryWords.join(' '));
$('#results').html('');
var i = 0;
if (result.length === 0) {
$('#results').html('<li>No results</li>');
} else {
var i = 0;
var resHtml = '';
if (typeof result.forEach !== "undefined") {
result.forEach(function(item) {
if (i++ > 20) {
return;
}
resHtml = resHtml +
'<li><a href="http://example.com/' + item.file.url.substr(3) +'">' + item.file.title + '</a><br />' +
'Weight: ' + item.weight + '</li>';
});
}
$('#results').html(resHtml);
}
});
});
</script>
<title>Example</title>
</head>
<body>
<h1>Example</h1>
<label for="searchbox" style="display: inline-block; width: 160px;">Search: </label>
<input id="searchbox" type="text" value="">
<br/>
<label for="query" style="display: inline-block; width: 160px;">Actual query: </label>
<span id="query"></span>
<ul id="results">
<li>No results</li>
</ul>
</body>
</html>