forked from rhec/elasticsearch.github.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.html
140 lines (135 loc) · 4.29 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
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
<input id="search" class="ui-corner-all" autocomplete="off" placeholder="Search" accesskey="s">
<style>
#search-box {
font-family: 'Helvetica Neue', 'Helvetica Neue', Helvetica, Arial, sans-serif !important;
width: 35em;
margin: 0 auto;
}
#search-box .ui-widget {
font-family: 'Helvetica Neue', 'Helvetica Neue', Helvetica, Arial, sans-serif !important;
}
input#search {
color: #444;
font-size: 105%;
background: #ebfad4;
padding: 0.25em 0.5em; margin: 0;
border: 1px solid #fff; border-top: none;
width: 100%;
-moz-border-radius-topright: 0; -webkit-border-radius-top-right: 0; border-top-right-radius: 0;
-moz-border-radius-topleft: 0; -webkit-border-radius-top-left: 0; border-top-left-radius: 0;
}
input#search:focus {
outline: none;
}
input#search.placeholder {
color: #aaa;
}
ul.ui-autocomplete {
background: #ebfad4 !important;
font-size: 80%;
border: 1px solid #fff;
padding: 0 !important;
-moz-border-radius-topright: 0; -webkit-border-radius-top-right: 0; border-top-right-radius: 0;
-moz-border-radius-topleft: 0; -webkit-border-radius-top-left: 0; border-top-left-radius: 0;
-moz-box-shadow: 0px 1px 2px #666;
-webkit-box-shadow: 0px 1px 2px #666;
box-shadow: 0px 1px 2px #666
}
ul.ui-autocomplete li.ui-menu-item {
border-bottom: 1px solid #fff;
}
ul.ui-autocomplete li.ui-menu-item:last-child {
border-bottom: none;
}
ul.ui-autocomplete li.ui-menu-item a {
padding: 0.5em 0.5em;
-moz-border-radius: 0 !important; -webkit-border-radius: 0 !important; border-radius: 0 !important;
}
ul.ui-autocomplete .ui-state-hover {
color: #222;
border-color: #fff !important;
background: #c6fa78 !important;
}
ul.ui-autocomplete .ui-state-hover * {
color: #222;
cursor: pointer;
}
ul.ui-autocomplete li.ui-menu-item p {
margin: 0 !important; padding: 0 !important; line-height: 1em !important;
margin-bottom: 0;
}
ul.ui-autocomplete li.ui-menu-item p a {
padding: 0 !important; margin: 0 !important; line-height: 1em !;
display: inline !important;
}
ul.ui-autocomplete li.ui-menu-item em {
font-style: normal;
font-size: 85%;
padding: 0.25em 0.5em;
background-color: #C9D4B2;
-moz-border-radius: 0.5em; -webkit-border-radius: 0.5em; border-radius: 0.5em;
-moz-border-radius: 0.5em; -webkit-border-radius: 0.5em; border-radius: 0.5em;
}
ul.ui-autocomplete li.ui-menu-item small {
font-size: 70%;
}
ul.ui-autocomplete li.ui-menu-item .ui-state-hover em {
background-color: #A7D94C;
}
</style>
<script>
$(function() {
$.placeholder();
var elastic_search_url = "http://search.elasticsearch.org/elastic-search-website/guide,blog/_search";
var searchRequest = undefined;
var previousQueryString = "";
$( "#search" ).autocomplete({
search: function() {
if ( this.value.trim() != previousQueryString ) {
previousQueryString = this.value.trim();
return true;
}
return false;
},
source: function( request, response ) {
if ( searchRequest && searchRequest.readyState < 4 ) {
searchRequest.abort();
}
var q = request.term;
var re = /[^ *]/;
searchRequest = $.ajax({
url: [ elastic_search_url, $.param( {
fields : "title,category,url",
size : 25,
q : q,
default_operator: "AND"
} )].join("?"),
dataType: "jsonp",
success: function( data ) {
response( $.map( data.hits.hits, function( item ) {
return {
label: '<p><strong>' + item.fields.title + '</strong>' +
' <em>' + item.fields.category + '</em>' + '</p>' +
'<p><small>' + item.fields.url + '</small></p>',
value: item.fields.title,
url : item.fields.url
}
}));
}
});
},
minLength: 2,
html: true,
select: function( event, ui ) {
event.preventDefault();
ui.item ? document.location.href = ui.item.url : null;
},
open: function() {
$( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" );
},
close: function() {
$( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" );
}
});
});
</script>