a full text indexing library for javascript
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

96 lines
2.4 KiB

  1. <html>
  2. <head>
  3. <title>Tidx Test</title>
  4. <style type="text/css">
  5. #result_table td { vertical-align: top; }
  6. td { vertical-align: bottom; }
  7. th { text-align: left; }
  8. #output { font-style: italic; }
  9. </style>
  10. </head>
  11. <body>
  12. <table>
  13. <tr>
  14. <td><label for="search">Multiterm search:</label></td>
  15. <td><input type="text" id="search" name="search" size="50" /></td>
  16. <td><input type="button" id="btn_search" value="Search"/></td>
  17. <td><div id="output"></div></td>
  18. </tr>
  19. </table>
  20. <br/>
  21. <table id="result_table">
  22. <thead>
  23. <tr>
  24. <th>ID</th>
  25. <th>Name</th>
  26. <th>Email</th>
  27. <th>City</th>
  28. <th>State</th>
  29. <th>Country</th>
  30. <th>Rank</th>
  31. <th>Description</th>
  32. </tr>
  33. </thead>
  34. <tbody id="result_tbody"></tbody>
  35. </table>
  36. <script type="text/javascript" src="../tidx.js"></script>
  37. <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
  38. <script type="text/javascript">
  39. var idx = new Tidx();
  40. var json = null;
  41. $(function(){
  42. var output = $('#output');
  43. // Load test JSON
  44. output.html('Loading .. ');
  45. $.getJSON('test.json', function(data){
  46. json = data;
  47. var s = new Date().getTime();
  48. for(var i = 0; i < json.length; i++){
  49. for(var f in json[i]){
  50. // Index all the fields in json except ID
  51. if(f != 'id'){ idx.index(true, i, f, json[i][f]); }
  52. }
  53. }
  54. output.html('test.json indexed in ' + (new Date().getTime() - s) + "ms\n");
  55. });
  56. // Setup the search button
  57. $('#btn_search').click(function(){
  58. var s = new Date().getTime();
  59. var results = idx.search(true, $('#search').val());
  60. output.html('Search completed in ' + (new Date().getTime() - s) + "ms\n");
  61. var rtbl = $('#result_tbody').empty();
  62. for(var i in results){
  63. var row = json[results[i]];
  64. rtbl.append(
  65. '<tr>' +
  66. '<td>' + row['id'] + '</td>' +
  67. '<td>' + row['name'] + '</td>' +
  68. '<td>' + row['email'] + '</td>' +
  69. '<td>' + row['city'] + '</td>' +
  70. '<td>' + row['state'] + '</td>' +
  71. '<td>' + row['country'] + '</td>' +
  72. '<td>' + row['rank'] + '</td>' +
  73. '<td>' + row['desc'] + '</td>' +
  74. '</tr>'
  75. );
  76. }
  77. });
  78. // Enter should work to search, too
  79. $('#search').keydown(function(e){
  80. if(e.which == 13){ $('#btn_search').click(); }
  81. }).focus();
  82. });
  83. </script>
  84. </body>
  85. </html>