Skip to content

Commit 0714ca4

Browse files
karmikimchy
authored andcommitted
Added partial template with search input and logic
1 parent 04bfe68 commit 0714ca4

File tree

1 file changed

+115
-0
lines changed

1 file changed

+115
-0
lines changed

search.html

+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
<input id="search" class="ui-corner-all" autocomplete="off" placeholder="Search (Use Lucene query syntax)">
2+
3+
<style>
4+
#search-box {
5+
font-family: 'Helvetica Neue', 'Helvetica Neue', Helvetica, Arial, sans-serif !important;
6+
width: 35em;
7+
margin: 0 auto;
8+
}
9+
#search-box .ui-widget {
10+
font-family: 'Helvetica Neue', 'Helvetica Neue', Helvetica, Arial, sans-serif !important;
11+
}
12+
input#search {
13+
font-size: 105%;
14+
background: #ebfad4;
15+
padding: 0.25em 0.5em; margin: 0;
16+
border: 1px solid #fff; border-top: none;
17+
width: 100%;
18+
-moz-border-radius-topright: 0; -webkit-border-radius-top-right: 0; border-top-right-radius: 0;
19+
-moz-border-radius-topleft: 0; -webkit-border-radius-top-left: 0; border-top-left-radius: 0;
20+
}
21+
input#search:focus {
22+
outline: none;
23+
}
24+
ul.ui-autocomplete {
25+
background: #ebfad4 !important;
26+
font-size: 80%;
27+
border: 1px solid #fff;
28+
padding: 0 !important;
29+
-moz-border-radius-topright: 0; -webkit-border-radius-top-right: 0; border-top-right-radius: 0;
30+
-moz-border-radius-topleft: 0; -webkit-border-radius-top-left: 0; border-top-left-radius: 0;
31+
-moz-box-shadow: 0px 1px 2px #666;
32+
-webkit-box-shadow: 0px 1px 2px #666;
33+
box-shadow: 0px 1px 2px #666
34+
}
35+
ul.ui-autocomplete li.ui-menu-item {
36+
border-bottom: 1px solid #fff;
37+
}
38+
ul.ui-autocomplete li.ui-menu-item:last-child {
39+
border-bottom: none;
40+
}
41+
ul.ui-autocomplete li.ui-menu-item a {
42+
padding: 0.5em 0.5em;
43+
-moz-border-radius: 0 !important; -webkit-border-radius: 0 !important; border-radius: 0 !important;
44+
}
45+
ul.ui-autocomplete .ui-state-hover {
46+
color: #222;
47+
border-color: #fff !important;
48+
background: #c6fa78 !important;
49+
}
50+
ul.ui-autocomplete .ui-state-hover * {
51+
color: #222;
52+
cursor: pointer;
53+
}
54+
ul.ui-autocomplete li.ui-menu-item p {
55+
margin: 0 !important; padding: 0 !important; line-height: 1em !important;
56+
margin-bottom: 0;
57+
}
58+
ul.ui-autocomplete li.ui-menu-item p a {
59+
padding: 0 !important; margin: 0 !important; line-height: 1em !;
60+
display: inline !important;
61+
}
62+
ul.ui-autocomplete li.ui-menu-item em {
63+
font-style: normal;
64+
font-size: 85%;
65+
padding: 0.25em 0.5em;
66+
background-color: #C9D4B2;
67+
-moz-border-radius: 0.5em; -webkit-border-radius: 0.5em; border-radius: 0.5em;
68+
-moz-border-radius: 0.5em; -webkit-border-radius: 0.5em; border-radius: 0.5em;
69+
}
70+
ul.ui-autocomplete li.ui-menu-item small {
71+
font-size: 70%;
72+
}
73+
ul.ui-autocomplete li.ui-menu-item .ui-state-hover em {
74+
background-color: #A7D94C;
75+
}
76+
</style>
77+
78+
<script>
79+
80+
$(function() {
81+
var elastic_search_url = "http://localhost:9200/elastic-search-website/_search";
82+
83+
$( "#search" ).autocomplete({
84+
source: function( request, response ) {
85+
$.ajax({
86+
url: elastic_search_url+"?q="+request.term,
87+
dataType: "jsonp",
88+
success: function( data ) {
89+
response( $.map( data.hits.hits, function( item ) {
90+
return {
91+
label: '<p><strong>' + item._source.title + '</strong>' +
92+
' <em>' + item._source.category + '</em>' + '</p>' +
93+
'<p><small>' + item._source.url + '</small></p>',
94+
value: item._source.url
95+
}
96+
}));
97+
}
98+
});
99+
},
100+
minLength: 2,
101+
html: true,
102+
select: function( event, ui ) {
103+
event.preventDefault();
104+
ui.item ? document.location.href = ui.item.value : null;
105+
},
106+
open: function() {
107+
$( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" );
108+
},
109+
close: function() {
110+
$( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" );
111+
}
112+
});
113+
});
114+
115+
</script>

0 commit comments

Comments
 (0)