Archived
1
0
This repository has been archived on 2021-02-02. You can view files and clone it, but cannot push or open issues or pull requests.
tidx/test.html

124 lines
3.2 KiB
HTML
Raw Normal View History

2012-03-26 20:17:25 -08:00
<html>
<head>
<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>
<body>
<table>
<tr>
<td><label for="or_search">Logical OR Search:</label></td>
<td><input type="text" id="or_search" name="search" size="50" /></td>
<td><input type="button" id="btn_or_search" value="Search"/></td>
</tr>
<tr>
<td><label for="and_search">Logical AND Search:</label></td>
<td><input type="text" id="and_search" name="search" size="50" /></td>
<td><input type="button" id="btn_and_search" value="Search" /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td colspan="2">
<textarea name="output" id="output" rows="10" cols="45"></textarea>
</td>
</tr>
</table>
<br/>
<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>
<script type="text/javascript" src="tidx.js"></script>
<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();
var json = null;
2012-03-26 20:17:25 -08:00
$(function(){
var output = $('#output');
// 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
var s = new Date().getTime();
for(var i = 0; i < json.length; i++){
for(var f in json[i]){
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-26 20:17:25 -08:00
}
output.val(output.val() + 'indexed in ' + (new Date().getTime() - s) + "ms\n");
});
// Setup the search buttons
$('#btn_or_search').click(function(){
dosearch(false, $('#or_search').val());
});
$('#btn_and_search').click(function(){
dosearch(true, $('#and_search').val());
});
// Enter should work to search, too
$('#or_search').keydown(function(e){
if(e.which == 13){ $('#btn_or_search').click(); }
});
$('#and_search').keydown(function(e){
if(e.which == 13){ $('#btn_and_search').click(); }
}).focus();
});
function dosearch(and_search, value){
var output = $('#output');
output.val(output.val() + 'Searching .. ');
var s = new Date().getTime();
var results = t.search(and_search, value);
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>'
);
}
}
2012-03-26 20:17:25 -08:00
</script>
</body>
</html>