forked from Azure-Samples/AzSearch.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
realestate.html
293 lines (270 loc) · 12.1 KB
/
realestate.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
<!DOCTYPE html>
<head>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
crossorigin="anonymous">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp"
crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/AzSearch.css">
<title>Real Estate</title>
<style>
.searchResults__result h4 {
margin-top: 0px;
text-transform: uppercase;
}
.searchResults__result .resultDescription {
margin: 0.5em 0 0 0;
}
.searchResults__result ul.resultProperties {
margin: 1em 0 0 0;
padding: 0;
}
.searchResults__result ul.resultProperties li {
display: inline-block;
font-size: 1.2em;
padding: 0px;
}
.searchResults__result ul.resultProperties i.fa {
color: #bbb;
}
.searchResults__result ul.resultProperties li span {
padding-left: 0.3em;
}
.searchResults__result ul.resultProperties li.resultProperties__money {
width: 8em;
}
.searchResults__result ul.resultProperties li.resultProperties__home {
width: 7em;
}
.searchResults__result ul.resultProperties li.resultProperties__bed,
.searchResults__result ul.resultProperties li.resultProperties__bath {
width: 4em;
}
.sk-bounce1,
.sk-bounce2,
.sk-bounce3,
.sk-spinner {
float: right;
}
@media (max-width: 850px) {
.searchResults__result ul.resultProperties li {
font-size: 1.1em;
}
}
@media (max-width: 767px) {
.searchResults__result h4 {
margin-top: 0.5em;
}
.searchResults__result ul.resultProperties {
margin: 0.5em 0 0 0;
}
.searchResults__result ul.resultProperties li {
font-size: 1em;
padding: 0 0.5em 0 0;
}
.searchResults__result ul.resultProperties li.resultProperties__money {
width: inherit;
}
.searchResults__result ul.resultProperties li.resultProperties__home {
width: inherit;
}
.searchResults__result ul.resultProperties li.resultProperties__bed,
.searchResults__result ul.resultProperties li.resultProperties__bath {
width: inherit;
}
}
</style>
</head>
<body>
<div id="app">
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#facetPanel" aria-expanded="false"
aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<div class="row">
<div class="col-md-2 pagelabel">
<a class="navbar-brand pagelabel" href="https://github.com/Azure-Samples/AzSearch.js">AzSearch.js</a>
</div>
<div id="searchBox" class="col-mid-8 col-sm-8 col-xs-6"></div>
<div id="navbar" class="navbar-collapse collapse">
</div>
</div>
</div>
</div>
</nav>
<div class="container-fluid">
<div class="row">
<div id="facetPanel" class="col-sm-3 col-md-3 sidebar collapse">
<div id="facetHeader"></div>
<div className="panel panel-primary behclick-panel">
<ul class="nav nav-sidebar">
<li>
<div id="sortBy">
</div>
</li>
<li>
<div id="typeFilter">
</div>
</li>
<li>
<div id="priceFacet">
</div>
</li>
<li>
<div id="sqftFacet">
</div>
</li>
<li>
<div id="bedsFacet">
</div>
</li>
<li>
<div id="bathsFacet">
</div>
</li>
<li>
<div id="tagsFacet">
</div>
</li>
</ul>
</div>
<div id="facetFooter"></div>
</div>
<div class="col-sm-9 col-sm-offset-3 col-md-9 col-md-offset-3 results_section">
<div id="loading"></div>
<div id="results" class="row placeholders">
</div>
<div id="pager" class="row">
</div>
</div>
</div>
</div>
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"
crossorigin="anonymous"></script>
</body>
<!-- Dependencies -->
<script src="https://cdn.jsdelivr.net/react/15.5.4/react.min.js"></script>
<script src="https://cdn.jsdelivr.net/react/15.5.4/react-dom.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/redux/3.6.0/redux.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/numeral.js/2.0.6/numeral.min.js"></script>
<script src="https://use.fontawesome.com/f07430bcbd.js"></script>
<!-- Main -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/AzSearch.bundle.js"></script>
<script>
// Initialize
var automagic = new AzSearch.Automagic({ index: "realestate-us-sample", queryKey: "D1CD08C7AC6A1886024E0F23B1824417", service: "azs-playground" });
// Set some processors to format results for display
var suggestionsProcessor = function (results) {
return results.map(function (result) {
result.displayText = result.number + " " + result.street + " " + result.city + ", " + result.region + " " + result.countryCode;
result.searchText = result["@search.text"];
return result;
});
};
var resultsProcessor = function (results) {
return results.map(function (result) {
result.displayText = result.number + " " + result.street + " " + result.city + ", " + result.region + " " + result.countryCode;
var summary = result.description;
result.summary = summary.length < 200 ? summary : summary.substring(0, 200) + "...";
result.sqft = numeral(result.sqft).format("0,0");
result.price = numeral(result.price).format("$0,0");
return result;
});
};
automagic.store.setSuggestionsProcessor(suggestionsProcessor);
automagic.store.setResultsProcessor(resultsProcessor);
// Create some mustache templates to customize result/suggestion display. Default is JSON.stringify(result,null,4) rendered in <pre> and <code>.
var resultTemplate =
`<div class="col-xs-12 col-sm-3 col-md-3 result_img">
<img class="img-responsive result_img" src={{thumbnail}} alt="image not found" />
</div>
<div class="col-xs-12 col-sm-9 col-md-9">
<h4>{{displayText}}</h4>
<div class="resultDescription">
{{{summary}}}
</div>
<ul class="resultProperties">
<li class="resultProperties__money"><i class="fa fa-money" aria-hidden="true"></i><span>{{price}}</span></li>
<li class="resultProperties__home"><i class="fa fa-home" aria-hidden="true"></i><span>{{sqft}}ft<sup>2</sup></span></li>
<li class="resultProperties__bed"><i class="fa fa-bed" aria-hidden="true"></i><span>{{beds}}</span></li>
<li class="resultProperties__bath"><i class="fa fa-bath" aria-hidden="true"></i><span>{{baths}}</span></li>
</ul>
</div>`;
var suggestionsTemplate = "{{displayText}} <br/> {{{searchText}}}";
// Add a search box that uses suggester "sg", grabbing some additional fields to display during suggestions. Use the template defined above
automagic.addSearchBox("searchBox",
{
highlightPreTag: "<b>",
highlightPostTag: "</b>",
suggesterName: "sg",
select: "number,street,city,region,countryCode"
},
"displayText",
suggestionsTemplate);
// add a results view using the template defined above
automagic.addResults("results", { count: true }, resultTemplate);
// Add a loading indicator above the results view
automagic.addLoadingIndicator("loading");
// Adds a pager control << 1 2 3 ... >>
automagic.addPager("pager");
// range facet for price
automagic.addRangeFacet("priceFacet", "price", "number", 0, 2000000);
// range facet for sqft
automagic.addRangeFacet("sqftFacet", "sqft", "number", 0, 17000);
// checkbox facet for numeric field beds
automagic.addCheckboxFacet("bedsFacet", "beds", "number");
// checkbox facet for numeric field baths
automagic.addCheckboxFacet("bathsFacet", "baths", "number");
// checkbox facet for collection field tags
automagic.addCheckboxFacet("tagsFacet", "tags", "collection");
// filter header & footer options
automagic.addClearFiltersButton("facetHeader");
automagic.addClearFiltersButton("facetFooter");
// add sorting options
var fields = [
{ displayName: "Relevance", fieldName: "" },
{ displayName: "Price", fieldName: "price" },
{ displayName: "Size", fieldName: "sqft" },
{ displayName: "Beds", fieldName: "beds" },
{ displayName: "Baths", fieldName: "baths" }
];
// ask for users location and add a geo sorting option
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function (position) {
fields.push({
displayName: "Distance",
fieldName: "location",
latitude: position.coords.latitude,
longitude: position.coords.longitude
});
automagic.addSortBy("sortBy", fields, "beds");
},
function () {
// on rejection from user
automagic.addSortBy("sortBy", fields, "beds");
});
} else {
automagic.addSortBy("sortBy", fields, "beds");
}
// static filter for home type
var filters = [
{ displayName: "Any", filter: "" },
{ displayName: "House", filter: "type eq 'House'" },
{ displayName: "Apartment", filter: "type eq 'Apartment'" }
];
var defaultFilter = "";
var title = "Home Type";
automagic.addStaticFilter("typeFilter", "type", filters, defaultFilter, title);
</script>
</html>