2012-03-26 20:17:25 -08:00
|
|
|
<html>
|
|
|
|
<head>
|
2012-03-27 19:47:48 -08:00
|
|
|
<title>Tidx Test</title>
|
|
|
|
<style type="text/css">
|
|
|
|
td { vertical-align: top; }
|
|
|
|
th { text-align: left; }
|
|
|
|
</style>
|
2012-03-26 20:17:25 -08:00
|
|
|
</head>
|
2012-03-27 19:47:48 -08:00
|
|
|
<body>
|
2012-03-27 06:13:05 -08:00
|
|
|
<input type="text" id="search" name="search" size="50" />
|
|
|
|
<input type="button" id="btn_search" value="Search" />
|
|
|
|
<br/><br/>
|
2012-03-27 19:47:48 -08:00
|
|
|
<textarea name="output" id="output" rows="10" cols="40"></textarea>
|
|
|
|
<table>
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th>ID</th>
|
|
|
|
<th>Name</th>
|
|
|
|
<th>Email</th>
|
|
|
|
<th>City</th>
|
|
|
|
<th>State</th>
|
|
|
|
<th>Country</th>
|
|
|
|
<th>Rank</th>
|
|
|
|
<th>Description</th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody id="result_table"></tbody>
|
|
|
|
</table>
|
2012-03-27 17:40:51 -08:00
|
|
|
<script type="text/javascript" src="tidx.js"></script>
|
2012-03-27 19:47:48 -08:00
|
|
|
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
|
2012-03-26 20:17:25 -08:00
|
|
|
<script type="text/javascript">
|
|
|
|
var t = new Tidx();
|
2012-03-27 19:47:48 -08:00
|
|
|
var json = null;
|
2012-03-26 20:17:25 -08:00
|
|
|
|
2012-03-27 19:47:48 -08:00
|
|
|
$(function(){
|
|
|
|
var output = $('#output');
|
2012-03-27 06:13:05 -08:00
|
|
|
|
2012-03-27 19:47:48 -08:00
|
|
|
// Load test JSON
|
|
|
|
output.val('Loading test.json .. ');
|
|
|
|
$.getJSON('test.json', function(data){
|
|
|
|
json = data;
|
|
|
|
output.val(output.val() + "loaded\nIndexing test.json .. ");
|
2012-03-26 20:17:25 -08:00
|
|
|
|
2012-03-27 19:47:48 -08:00
|
|
|
var s = new Date().getTime();
|
|
|
|
for(var i = 0; i < json.length; i++){
|
|
|
|
for(var f in json[i]){
|
2012-04-01 14:13:09 -08:00
|
|
|
switch(f){
|
|
|
|
case 'id': break;
|
|
|
|
case 'email': t.index(false, i, f, json[i][f]); break;
|
|
|
|
default: t.index(true, i, f, json[i][f]); break;
|
|
|
|
}
|
2012-03-27 19:47:48 -08:00
|
|
|
}
|
2012-03-26 20:17:25 -08:00
|
|
|
}
|
2012-03-27 19:47:48 -08:00
|
|
|
|
|
|
|
output.val(output.val() + 'indexed in ' + (new Date().getTime() - s) + "ms\n");
|
|
|
|
});
|
|
|
|
|
|
|
|
// Setup the search button
|
|
|
|
$('#btn_search').click(function(){
|
|
|
|
output.val(output.val() + 'Searching .. ');
|
|
|
|
|
|
|
|
var s = new Date().getTime();
|
|
|
|
var results = t.search($('#search').val());
|
|
|
|
output.val(output.val() + 'completed in ' + (new Date().getTime() - s) + "ms\n");
|
|
|
|
|
|
|
|
var rtbl = $('#result_table').empty();
|
|
|
|
for(var idx in results){
|
|
|
|
var i = results[idx];
|
|
|
|
|
|
|
|
rtbl.append(
|
|
|
|
'<tr>' +
|
|
|
|
'<td>' + json[i]['id'] + '</td>' +
|
|
|
|
'<td>' + json[i]['name'] + '</td>' +
|
|
|
|
'<td>' + json[i]['email'] + '</td>' +
|
|
|
|
'<td>' + json[i]['city'] + '</td>' +
|
|
|
|
'<td>' + json[i]['state'] + '</td>' +
|
|
|
|
'<td>' + json[i]['country'] + '</td>' +
|
|
|
|
'<td>' + json[i]['rank'] + '</td>' +
|
|
|
|
'<td>' + json[i]['desc'] + '</td>' +
|
|
|
|
'</tr>'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Enter should work to search, too
|
|
|
|
$('#search').keydown(function(e){
|
|
|
|
if(e.which == 13){ $('#btn_search').click(); }
|
|
|
|
}).focus();
|
|
|
|
});
|
2012-03-26 20:17:25 -08:00
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|