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.

123 lines
3.2 KiB

12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
  1. <html>
  2. <head>
  3. <title>Tidx Test</title>
  4. <style type="text/css">
  5. td { vertical-align: top; }
  6. th { text-align: left; }
  7. </style>
  8. </head>
  9. <body>
  10. <table>
  11. <tr>
  12. <td><label for="or_search">Logical OR Search:</label></td>
  13. <td><input type="text" id="or_search" name="search" size="50" /></td>
  14. <td><input type="button" id="btn_or_search" value="Search"/></td>
  15. </tr>
  16. <tr>
  17. <td><label for="and_search">Logical AND Search:</label></td>
  18. <td><input type="text" id="and_search" name="search" size="50" /></td>
  19. <td><input type="button" id="btn_and_search" value="Search" /></td>
  20. </tr>
  21. <tr>
  22. <td>&nbsp;</td>
  23. <td colspan="2">
  24. <textarea name="output" id="output" rows="10" cols="45"></textarea>
  25. </td>
  26. </tr>
  27. </table>
  28. <br/>
  29. <table>
  30. <thead>
  31. <tr>
  32. <th>ID</th>
  33. <th>Name</th>
  34. <th>Email</th>
  35. <th>City</th>
  36. <th>State</th>
  37. <th>Country</th>
  38. <th>Rank</th>
  39. <th>Description</th>
  40. </tr>
  41. </thead>
  42. <tbody id="result_table"></tbody>
  43. </table>
  44. <script type="text/javascript" src="tidx.js"></script>
  45. <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
  46. <script type="text/javascript">
  47. var t = new Tidx();
  48. var json = null;
  49. $(function(){
  50. var output = $('#output');
  51. // Load test JSON
  52. output.val('Loading test.json .. ');
  53. $.getJSON('test.json', function(data){
  54. json = data;
  55. output.val(output.val() + "loaded\nIndexing test.json .. ");
  56. var s = new Date().getTime();
  57. for(var i = 0; i < json.length; i++){
  58. for(var f in json[i]){
  59. switch(f){
  60. case 'id': break;
  61. case 'email': t.index(false, i, f, json[i][f]); break;
  62. default: t.index(true, i, f, json[i][f]); break;
  63. }
  64. }
  65. }
  66. output.val(output.val() + 'indexed in ' + (new Date().getTime() - s) + "ms\n");
  67. });
  68. // Setup the search buttons
  69. $('#btn_or_search').click(function(){
  70. dosearch(false, $('#or_search').val());
  71. });
  72. $('#btn_and_search').click(function(){
  73. dosearch(true, $('#and_search').val());
  74. });
  75. // Enter should work to search, too
  76. $('#or_search').keydown(function(e){
  77. if(e.which == 13){ $('#btn_or_search').click(); }
  78. });
  79. $('#and_search').keydown(function(e){
  80. if(e.which == 13){ $('#btn_and_search').click(); }
  81. }).focus();
  82. });
  83. function dosearch(and_search, value){
  84. var output = $('#output');
  85. output.val(output.val() + 'Searching .. ');
  86. var s = new Date().getTime();
  87. var results = t.search(and_search, value);
  88. output.val(output.val() + 'completed in ' + (new Date().getTime() - s) + "ms\n");
  89. var rtbl = $('#result_table').empty();
  90. for(var idx in results){
  91. var i = results[idx];
  92. rtbl.append(
  93. '<tr>' +
  94. '<td>' + json[i]['id'] + '</td>' +
  95. '<td>' + json[i]['name'] + '</td>' +
  96. '<td>' + json[i]['email'] + '</td>' +
  97. '<td>' + json[i]['city'] + '</td>' +
  98. '<td>' + json[i]['state'] + '</td>' +
  99. '<td>' + json[i]['country'] + '</td>' +
  100. '<td>' + json[i]['rank'] + '</td>' +
  101. '<td>' + json[i]['desc'] + '</td>' +
  102. '</tr>'
  103. );
  104. }
  105. }
  106. </script>
  107. </body>
  108. </html>