forked from vespa-engine/documentation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.html
64 lines (53 loc) · 2.17 KB
/
search.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
---
# Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
title: ""
index: false
---
<!-- Number of hits -->
<div id="hits"></div>
<!-- result div -->
<div id="result"></div>
<!-- powered by -->
<div style="margin-top:40px;">
<b><em>Powered by <img src="img/vespa-logo-small.png" /> Vespa</em></b>
</div>
<script>
(function() {
var params = {};
decodeURIComponent(window.location.search.substr(1)).split("&").forEach( function(item) { var key = item.split("=")[0]; var val = item.split("=")[1]; params[key] = val; });
var query = params["q"];
if (query) {
query = decodeURI(query).replace(/\+/g, " ");
}
if (query && query.length > 0) {
$("#search").attr("value", query);
$("#result").html("<p>Searching for '" + query + "' ...</p>");
var url = "{{site.search.endpoint}}/search/?jsoncallback=?"
$.getJSON(url, {
query: query,
hits: 400,
ranking: "documentation"
})
.done(function( data ) {
$("#result").html("");
var hits = data.root.children;
if (hits && hits.length > 0) {
$("<p>").text(hits.length + " hit(s)").appendTo("#hits");
var ul = $("<ul>").addClass("media-list").appendTo("#result");
$.each( data.root.children, function( i, item ) {
var modified_url = item.fields.path;
var modified_content = item.fields.content.replace("<sep />", " ... ").replace("<hi>", "<mark>").replace("</hi>", "</mark>");
var modified_title = item.fields.title == "null" ? "No title" : item.fields.title;
var link = "<h4><a href=\"" + modified_url + "\">" + modified_title + "</a></h4>";
var content = "<p>" + modified_content + "<br /><small class=\"text-success\">" + item.fields.path + "</small></p>";
$("<li>").addClass("media").html(link+content).appendTo(ul);
});
} else {
$("<p>").text("No hits found!").appendTo("#result");
}
});
}
})();
</script>
</body>
</html>