-
Notifications
You must be signed in to change notification settings - Fork 58
/
custom.html
56 lines (53 loc) · 2.07 KB
/
custom.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
<!DOCTYPE html>
<html>
<head>
<style>
span.st-snippet em {
font-style: normal;
font-weight: bold;
background: yellow;
}
</style>
<script type='text/javascript' src="https://cdnjs.cloudflare.com/ajax/libs/hogan.js/3.0.2/hogan.min.js"></script>
<script type='text/javascript' src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script type='text/javascript' src='jquery.swiftype.search.js'></script>
<link type='text/css' rel='stylesheet' href='search.css' media='all' />
<script type='text/javascript'>
var resultTemplate = Hogan.compile('<div class="st-result"><h3 class="title"><a href="{{url}}" class="st-search-result-link">{{title}}</a></h3><div class="st-metadata"><span class="st-snippet">{{{body}}}</span></div></div>');
var customRenderer = function(documentType, item) {
var data = {
title: item['title'],
url: item['url'],
body: item.highlight['body']
};
return resultTemplate.render(data);
};
$(function() {
$('#st-search-input').swiftypeSearch({
resultContainingElement: '#st-results-container',
engineKey: '5jZG1gmmCTFYbSSDjpqq',
renderFunction: customRenderer,
highlightFields: {
'page': {'body': {'size': 300, 'fallback': true}}
},
perPage: 3,
sortField: function() {
return {page: $('#st-sort-field').val()};
}
});
});
</script>
</head>
<body>
<h1>Example Swiftype Search installation (custom renderer)</h1>
<p>
This is a search engine for the Swiftype documentation (<a href="https://swiftype.com/documentation">see it in action</a>).
Try searches like "crawler", "index" or "robots".
</p>
<form>
Search your site: <input type='text' id='st-search-input' class='st-search-input' />
</form>
Sort by: <input type='text' id='st-sort-field' value="external_id" />
<div id="st-results-container" class="st-result-listing"></div>
</body>
</html>