sdsykes-ferret 0.11.6.19

Sign up to get free protection for your applications and to get access to all the features.
Files changed (195) hide show
  1. data/CHANGELOG +24 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README +102 -0
  4. data/Rakefile +338 -0
  5. data/TODO +17 -0
  6. data/TUTORIAL +231 -0
  7. data/bin/ferret-browser +79 -0
  8. data/ext/analysis.c +1555 -0
  9. data/ext/analysis.h +219 -0
  10. data/ext/api.c +69 -0
  11. data/ext/api.h +27 -0
  12. data/ext/array.c +123 -0
  13. data/ext/array.h +53 -0
  14. data/ext/bitvector.c +540 -0
  15. data/ext/bitvector.h +272 -0
  16. data/ext/compound_io.c +383 -0
  17. data/ext/config.h +42 -0
  18. data/ext/document.c +156 -0
  19. data/ext/document.h +53 -0
  20. data/ext/except.c +120 -0
  21. data/ext/except.h +168 -0
  22. data/ext/extconf.rb +14 -0
  23. data/ext/ferret.c +402 -0
  24. data/ext/ferret.h +91 -0
  25. data/ext/filter.c +156 -0
  26. data/ext/fs_store.c +483 -0
  27. data/ext/global.c +418 -0
  28. data/ext/global.h +117 -0
  29. data/ext/hash.c +567 -0
  30. data/ext/hash.h +473 -0
  31. data/ext/hashset.c +170 -0
  32. data/ext/hashset.h +187 -0
  33. data/ext/header.h +58 -0
  34. data/ext/helper.c +62 -0
  35. data/ext/helper.h +13 -0
  36. data/ext/inc/lang.h +48 -0
  37. data/ext/inc/threading.h +31 -0
  38. data/ext/index.c +6425 -0
  39. data/ext/index.h +961 -0
  40. data/ext/lang.h +66 -0
  41. data/ext/libstemmer.c +92 -0
  42. data/ext/libstemmer.h +79 -0
  43. data/ext/mempool.c +87 -0
  44. data/ext/mempool.h +35 -0
  45. data/ext/modules.h +162 -0
  46. data/ext/multimapper.c +310 -0
  47. data/ext/multimapper.h +51 -0
  48. data/ext/posh.c +1006 -0
  49. data/ext/posh.h +1007 -0
  50. data/ext/priorityqueue.c +151 -0
  51. data/ext/priorityqueue.h +143 -0
  52. data/ext/q_boolean.c +1608 -0
  53. data/ext/q_const_score.c +161 -0
  54. data/ext/q_filtered_query.c +209 -0
  55. data/ext/q_fuzzy.c +268 -0
  56. data/ext/q_match_all.c +148 -0
  57. data/ext/q_multi_term.c +677 -0
  58. data/ext/q_parser.c +2825 -0
  59. data/ext/q_phrase.c +1126 -0
  60. data/ext/q_prefix.c +100 -0
  61. data/ext/q_range.c +350 -0
  62. data/ext/q_span.c +2402 -0
  63. data/ext/q_term.c +337 -0
  64. data/ext/q_wildcard.c +171 -0
  65. data/ext/r_analysis.c +2575 -0
  66. data/ext/r_index.c +3472 -0
  67. data/ext/r_qparser.c +585 -0
  68. data/ext/r_search.c +4105 -0
  69. data/ext/r_store.c +513 -0
  70. data/ext/r_utils.c +963 -0
  71. data/ext/ram_store.c +471 -0
  72. data/ext/search.c +1741 -0
  73. data/ext/search.h +885 -0
  74. data/ext/similarity.c +150 -0
  75. data/ext/similarity.h +82 -0
  76. data/ext/sort.c +983 -0
  77. data/ext/stem_ISO_8859_1_danish.c +338 -0
  78. data/ext/stem_ISO_8859_1_danish.h +16 -0
  79. data/ext/stem_ISO_8859_1_dutch.c +635 -0
  80. data/ext/stem_ISO_8859_1_dutch.h +16 -0
  81. data/ext/stem_ISO_8859_1_english.c +1156 -0
  82. data/ext/stem_ISO_8859_1_english.h +16 -0
  83. data/ext/stem_ISO_8859_1_finnish.c +792 -0
  84. data/ext/stem_ISO_8859_1_finnish.h +16 -0
  85. data/ext/stem_ISO_8859_1_french.c +1276 -0
  86. data/ext/stem_ISO_8859_1_french.h +16 -0
  87. data/ext/stem_ISO_8859_1_german.c +512 -0
  88. data/ext/stem_ISO_8859_1_german.h +16 -0
  89. data/ext/stem_ISO_8859_1_italian.c +1091 -0
  90. data/ext/stem_ISO_8859_1_italian.h +16 -0
  91. data/ext/stem_ISO_8859_1_norwegian.c +296 -0
  92. data/ext/stem_ISO_8859_1_norwegian.h +16 -0
  93. data/ext/stem_ISO_8859_1_porter.c +776 -0
  94. data/ext/stem_ISO_8859_1_porter.h +16 -0
  95. data/ext/stem_ISO_8859_1_portuguese.c +1035 -0
  96. data/ext/stem_ISO_8859_1_portuguese.h +16 -0
  97. data/ext/stem_ISO_8859_1_spanish.c +1119 -0
  98. data/ext/stem_ISO_8859_1_spanish.h +16 -0
  99. data/ext/stem_ISO_8859_1_swedish.c +307 -0
  100. data/ext/stem_ISO_8859_1_swedish.h +16 -0
  101. data/ext/stem_KOI8_R_russian.c +701 -0
  102. data/ext/stem_KOI8_R_russian.h +16 -0
  103. data/ext/stem_UTF_8_danish.c +344 -0
  104. data/ext/stem_UTF_8_danish.h +16 -0
  105. data/ext/stem_UTF_8_dutch.c +653 -0
  106. data/ext/stem_UTF_8_dutch.h +16 -0
  107. data/ext/stem_UTF_8_english.c +1176 -0
  108. data/ext/stem_UTF_8_english.h +16 -0
  109. data/ext/stem_UTF_8_finnish.c +808 -0
  110. data/ext/stem_UTF_8_finnish.h +16 -0
  111. data/ext/stem_UTF_8_french.c +1296 -0
  112. data/ext/stem_UTF_8_french.h +16 -0
  113. data/ext/stem_UTF_8_german.c +526 -0
  114. data/ext/stem_UTF_8_german.h +16 -0
  115. data/ext/stem_UTF_8_italian.c +1113 -0
  116. data/ext/stem_UTF_8_italian.h +16 -0
  117. data/ext/stem_UTF_8_norwegian.c +302 -0
  118. data/ext/stem_UTF_8_norwegian.h +16 -0
  119. data/ext/stem_UTF_8_porter.c +794 -0
  120. data/ext/stem_UTF_8_porter.h +16 -0
  121. data/ext/stem_UTF_8_portuguese.c +1055 -0
  122. data/ext/stem_UTF_8_portuguese.h +16 -0
  123. data/ext/stem_UTF_8_russian.c +709 -0
  124. data/ext/stem_UTF_8_russian.h +16 -0
  125. data/ext/stem_UTF_8_spanish.c +1137 -0
  126. data/ext/stem_UTF_8_spanish.h +16 -0
  127. data/ext/stem_UTF_8_swedish.c +313 -0
  128. data/ext/stem_UTF_8_swedish.h +16 -0
  129. data/ext/stopwords.c +401 -0
  130. data/ext/store.c +692 -0
  131. data/ext/store.h +777 -0
  132. data/ext/term_vectors.c +352 -0
  133. data/ext/threading.h +31 -0
  134. data/ext/utilities.c +446 -0
  135. data/ext/win32.h +54 -0
  136. data/lib/ferret.rb +29 -0
  137. data/lib/ferret/browser.rb +246 -0
  138. data/lib/ferret/browser/s/global.js +192 -0
  139. data/lib/ferret/browser/s/style.css +148 -0
  140. data/lib/ferret/browser/views/document/list.rhtml +49 -0
  141. data/lib/ferret/browser/views/document/show.rhtml +27 -0
  142. data/lib/ferret/browser/views/error/index.rhtml +7 -0
  143. data/lib/ferret/browser/views/help/index.rhtml +8 -0
  144. data/lib/ferret/browser/views/home/index.rhtml +29 -0
  145. data/lib/ferret/browser/views/layout.rhtml +22 -0
  146. data/lib/ferret/browser/views/term-vector/index.rhtml +4 -0
  147. data/lib/ferret/browser/views/term/index.rhtml +199 -0
  148. data/lib/ferret/browser/views/term/termdocs.rhtml +1 -0
  149. data/lib/ferret/browser/webrick.rb +14 -0
  150. data/lib/ferret/document.rb +130 -0
  151. data/lib/ferret/field_infos.rb +44 -0
  152. data/lib/ferret/index.rb +786 -0
  153. data/lib/ferret/number_tools.rb +157 -0
  154. data/lib/ferret_version.rb +3 -0
  155. data/setup.rb +1555 -0
  156. data/test/test_all.rb +5 -0
  157. data/test/test_helper.rb +24 -0
  158. data/test/threading/number_to_spoken.rb +132 -0
  159. data/test/threading/thread_safety_index_test.rb +79 -0
  160. data/test/threading/thread_safety_read_write_test.rb +76 -0
  161. data/test/threading/thread_safety_test.rb +133 -0
  162. data/test/unit/analysis/tc_analyzer.rb +548 -0
  163. data/test/unit/analysis/tc_token_stream.rb +646 -0
  164. data/test/unit/index/tc_index.rb +762 -0
  165. data/test/unit/index/tc_index_reader.rb +699 -0
  166. data/test/unit/index/tc_index_writer.rb +437 -0
  167. data/test/unit/index/th_doc.rb +315 -0
  168. data/test/unit/largefile/tc_largefile.rb +46 -0
  169. data/test/unit/query_parser/tc_query_parser.rb +238 -0
  170. data/test/unit/search/tc_filter.rb +135 -0
  171. data/test/unit/search/tc_fuzzy_query.rb +147 -0
  172. data/test/unit/search/tc_index_searcher.rb +61 -0
  173. data/test/unit/search/tc_multi_searcher.rb +128 -0
  174. data/test/unit/search/tc_multiple_search_requests.rb +58 -0
  175. data/test/unit/search/tc_search_and_sort.rb +179 -0
  176. data/test/unit/search/tc_sort.rb +49 -0
  177. data/test/unit/search/tc_sort_field.rb +27 -0
  178. data/test/unit/search/tc_spans.rb +190 -0
  179. data/test/unit/search/tm_searcher.rb +384 -0
  180. data/test/unit/store/tc_fs_store.rb +77 -0
  181. data/test/unit/store/tc_ram_store.rb +35 -0
  182. data/test/unit/store/tm_store.rb +34 -0
  183. data/test/unit/store/tm_store_lock.rb +68 -0
  184. data/test/unit/tc_document.rb +81 -0
  185. data/test/unit/ts_analysis.rb +2 -0
  186. data/test/unit/ts_index.rb +2 -0
  187. data/test/unit/ts_largefile.rb +4 -0
  188. data/test/unit/ts_query_parser.rb +2 -0
  189. data/test/unit/ts_search.rb +2 -0
  190. data/test/unit/ts_store.rb +2 -0
  191. data/test/unit/ts_utils.rb +2 -0
  192. data/test/unit/utils/tc_bit_vector.rb +295 -0
  193. data/test/unit/utils/tc_number_tools.rb +117 -0
  194. data/test/unit/utils/tc_priority_queue.rb +106 -0
  195. metadata +285 -0
@@ -0,0 +1,148 @@
1
+ body {
2
+ padding: 10px 30px;
3
+ }
4
+ ul#top-menu {
5
+ margin: 0;
6
+ padding: 0;
7
+ padding-left: 20px;
8
+ border-bottom: 1px solid #000099;
9
+ }
10
+ ul#top-menu li {
11
+ display: inline;
12
+ padding: 0px;
13
+ }
14
+ ul#top-menu li a, ul#top-menu li a:visited {
15
+ background-color: #cce6ff;
16
+ padding: 0px 5px;
17
+ border: 1px solid #000099;
18
+ text-decoration: none;
19
+ color: #000099;
20
+ font-weight: bold;
21
+ }
22
+ body#home ul#top-menu li.home a,
23
+ body#document ul#top-menu li.document a,
24
+ body#term ul#top-menu li.term a,
25
+ body#term-vector ul#top-menu li.term-vector a,
26
+ body#help ul#top-menu li.help a {
27
+ background-color: #f0f8ff;
28
+ border-bottom: 1px solid #f0f8ff;
29
+ }
30
+ div#content {
31
+ padding: 10px;
32
+ margin: 0;
33
+ background-color: #f0f8ff;
34
+ }
35
+ div.display {background-color:#fff;padding:0 5px;}
36
+ dl {
37
+ width: 51.1em;
38
+ margin: 0;
39
+ padding: 0;
40
+ }
41
+ dl dt {
42
+ width: 15em;
43
+ float: left;
44
+ margin: 0;
45
+ padding: .5em;
46
+ border-top: 1px solid #999;
47
+ font-weight: bold;
48
+ color: #cc9900;
49
+ }
50
+ /* commented backslash hack for mac-ie5 \*/
51
+ dt { clear: both; }
52
+ /* end hack */
53
+ dl dd {
54
+ float: left;
55
+ width: 34em;
56
+ margin: 0 0 0 0;
57
+ padding: .5em;
58
+ border-top: 1px solid #999;
59
+ }
60
+ hr {clear:both;border:0;}
61
+ h1, h2, h3, h4, h5, h6 {color:#cc0033;}
62
+ th {
63
+ font-weight: bold;
64
+ background-color: #cc9900;
65
+ color: white;
66
+ padding: 3px;
67
+ font-size: 12px;
68
+ }
69
+ th.small, td.small {font-size:11px;}
70
+ th, td {
71
+ border-top: 1px solid #994400;
72
+ border-left: 1px solid #994400;
73
+ }
74
+ table {
75
+ border-bottom: 1px solid #994400;
76
+ border-right: 1px solid #994400;
77
+ }
78
+ table.left-headed th {width:80px;text-align:left;}
79
+ table.left-headed td {background-color: white;text-align:right;width:120px;}
80
+ td {padding:2px 6px;color:#555;}
81
+ tr.even {background-color:#cce6ff;}
82
+ tr.odd {background-color:white;}
83
+ td.center {text-align:center}
84
+ td.right {text-align:right}
85
+
86
+ label.check {width:150px;float:left;}
87
+ pre {
88
+ border-left: solid 1px #cccccc;
89
+ border-top: solid 1px #cccccc;
90
+ border-bottom: solid 1px #cccccc;
91
+ border-right: dashed 2px #cccccc;
92
+ margin: 1em;
93
+ padding: 0.7em;
94
+ display: block;
95
+ overflow: hidden;
96
+ color: white;
97
+ background-color: black;
98
+ }
99
+ pre:hover {
100
+ overflow: visible;
101
+ border-right: solid 1px #cccccc;
102
+ width: 1000px;
103
+ }
104
+ div.nav {color:#007777;font-size:11px;}
105
+ div.nav a, div.nav a:visited {
106
+ background-color: white;
107
+ color: #007777;
108
+ padding: 2px 4px;
109
+ border: 1px solid #bbd8ef;
110
+ margin-right: 1px;
111
+ text-decoration: none;
112
+ font-size: 11px;
113
+ }
114
+ div.nav a.deleted {
115
+ background-color: #fee;
116
+ }
117
+ div.nav a.deleted:hover {
118
+ background-color: #077;
119
+ color: #fee;
120
+ }
121
+ div.nav a.disabled, div.nav a.disabled:hover {
122
+ cursor: default;
123
+ color: #ccc;
124
+ border: 1px solid #ccc;
125
+ background-color: white;
126
+ }
127
+ div.nav a:hover {
128
+ background-color: #007777;
129
+ color: white;
130
+ }
131
+ /* Auto Suggest */
132
+ div.suggestions {
133
+ -moz-box-sizing: border-box;
134
+ box-sizing: border-box;
135
+ border: 1px solid black;
136
+ position: absolute;
137
+ }
138
+ div.suggestions div {
139
+ cursor: default;
140
+ padding: 0px 3px;
141
+ background-color: white;
142
+ opacity: 0.80;
143
+ filter:alpha(opacity=80);
144
+ }
145
+ div.suggestions div.current {
146
+ background-color: #3366cc;
147
+ color: white;
148
+ }
@@ -0,0 +1,49 @@
1
+ <h3>List Documents</h3>
2
+ <fieldset>
3
+ <legend>Show fields</legend>
4
+ <form method="get" action="">
5
+ <% fields = [];
6
+ field_settings = @params["field"]||{};
7
+ @reader.field_infos.each do |fi|
8
+ next unless fi.stored?
9
+ %>
10
+ <label class="check" for="field_<%= fi.name %>">
11
+ <input name="field[<%= fi.name %>]" type="checkbox" id="field_<%= fi.name %>"
12
+ <% if field_settings[fi.name.to_s] == "on"; fields << fi.name %>
13
+ checked="checked"
14
+ <% end %>
15
+ onchange="this.form.submit();" /><%= fi.name %>
16
+ </label>
17
+ <% end %>
18
+ </form>
19
+ </fieldset>
20
+ <hr/>
21
+ <%= paginate(@page, @reader.max_doc/@page_size, '/document/list/') %>
22
+ <hr/>
23
+ <table cellpadding="0" cellspacing="0">
24
+
25
+ <tr>
26
+ <th>Internal ID</th>
27
+ <% fields.each do |field| %>
28
+ <th><%= field %></th>
29
+ <% end %>
30
+ </tr>
31
+
32
+ <% even=false; (@first...@last).each do |i| %>
33
+ <% if @reader.deleted?(i) %>
34
+ <tr class="<%= (even = !even) ? 'even' : 'odd' %>">
35
+ <td colspan="<%= fields.size + 1 %>" class="center" style="color:#b00;"><%=i%> is deleted</td>
36
+ </tr>
37
+ <% else %>
38
+ <tr onclick="location.href='/document/show/<%=i%>';"
39
+ class="<%= (even = !even) ? 'even' : 'odd' %>">
40
+ <td class="left"><a href="/document/show/<%=i%>"><%= i %></a></td>
41
+ <% doc = @reader[i]; fields.each do |field| %>
42
+ <td class="small"><%= truncate(doc[field]) %></td>
43
+ <% end %>
44
+ </tr>
45
+ <% end %>
46
+ <% end %>
47
+ </table>
48
+ <hr/>
49
+ <%= choose_document(@doc_id) %>
@@ -0,0 +1,27 @@
1
+ <h3>View Document</h3>
2
+ <%= choose_document(@doc_id) %>
3
+ <hr/>
4
+ <%= paginate_docs %>
5
+ <% total_length = 0 %>
6
+ <div class="display">
7
+ <% if @doc %>
8
+ <h3>Fields</h3>
9
+ <dl>
10
+ <% @doc.each_pair do |field, value| %>
11
+ <% total_length += value.length %>
12
+ <dt><%= field %></dt>
13
+ <dd>
14
+ <% if value.length > 50 %>
15
+ <pre><%= value %></pre>
16
+ <% else %>
17
+ <%= value %>
18
+ <% end %>
19
+ </dd>
20
+ <% end %>
21
+ </dl>
22
+ <hr/>
23
+ <% else %>
24
+ <p style="color:#933;">Document has been deleted</p>
25
+ <% end %>
26
+ </div>
27
+ <%= (total_length > 1000) ? paginate_docs : '' %>
@@ -0,0 +1,7 @@
1
+ <h3><%= options[:status] %> Error</h3>
2
+ <% if @params[:error] %>
3
+ <pre>
4
+ <%= @params[:error] %>
5
+ <%= @params[:error].backtrace.join('<br/>') %>
6
+ </pre>
7
+ <% end %>
@@ -0,0 +1,8 @@
1
+ <h3>Ferret Browser Help</h3>
2
+ <p>
3
+ At the moment there is no help for the Ferret Browser. Everything should be
4
+ fairly self explanatory. If not, you can post a question on the
5
+ <a href="http://rubyforge.org/mailman/listinfo/ferret-talk">mailing list</a>
6
+ or you can edit the
7
+ <a href="http://ferret.davebalmain.com/trac/wiki/FerretBrowser" title="Ferret Browser Home Page">FerretBrowser wiki page</a>.
8
+ </p>
@@ -0,0 +1,29 @@
1
+ <h3>Index Info</h3>
2
+ <dl>
3
+ <dt>Number of Documents</dt> <dd><%= @reader.num_docs %></dd>
4
+ <dt>Maximum Document</dt> <dd><%= @reader.max_doc %></dd>
5
+ </dl>
6
+ <hr/>
7
+ <h3>Field Infos</h3>
8
+ <% field_props = [:stored?, :compressed?, :indexed?, :tokenized?, :omit_norms?, :store_term_vector?, :store_positions?, :store_offsets?, :has_norms?] %>
9
+ <table cellpadding="0" cellspacing="0">
10
+ <tr>
11
+ <th>Field Name</th>
12
+ <th class="small">Boost</th>
13
+ <% field_props.each do |prop| %>
14
+ <th class="small"><%= prop %></th>
15
+ <% end %>
16
+ </tr>
17
+ <%
18
+ even=false;
19
+ @reader.field_infos.each do |fi|
20
+ %>
21
+ <tr class="<%= (even = !even) ? 'even' : 'odd' %>">
22
+ <td><%= fi.name %></td>
23
+ <td style="text-align:right;"><%= fi.boost %></td>
24
+ <% field_props.each do |prop| %>
25
+ <td class="center"><%= tick_or_cross(fi.send(prop)) %></td>
26
+ <% end %>
27
+ </tr>
28
+ <% end %>
29
+ </table>
@@ -0,0 +1,22 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
3
+ <html xmlns="http://www.w3.org/1999/xhtml">
4
+ <head>
5
+ <title>Ferret-Browser:: <%= @path %></title>
6
+ <link rel="shortcut icon" type="image/x-icon" href="/s/i/favicon.ico" />
7
+ <link rel="stylesheet" type="text/css" href="/s/style.css" />
8
+ <script type="text/javascript" src="/s/global.js"></script>
9
+ </head>
10
+ <body id="<%= options[:controller] %>">
11
+ <ul id="top-menu">
12
+ <li class="home"><a href="/">Home</a></li>
13
+ <li class="document"><a href="/document">Documents</a></li>
14
+ <li class="term"><a href="/term">Terms</a></li>
15
+ <li class="term-vector"><a href="/term-vector">Term Vectors</a></li>
16
+ <li class="help"><a href="/help">Help</a></li>
17
+ </ul>
18
+ <div id="content">
19
+ <%= content %>
20
+ </div>
21
+ </body>
22
+ </html>
@@ -0,0 +1,4 @@
1
+ <h3>Term Vectors</h3>
2
+ <p>
3
+ Nothing to see here yet
4
+ </p>
@@ -0,0 +1,199 @@
1
+ <h3>Terms</h3>
2
+ <form action="" method="get">
3
+ <label for="field">Choose a field:
4
+ <select id="field" name="field" onchange="location.href='/term/show/' + this.value;">
5
+ <option value="">--</option>
6
+ <% @reader.field_infos.each do |fi| next unless fi.indexed? %>
7
+ <option value="<%=fi.name%>" <%= 'selected="selected"' if @field == fi.name %>><%=fi.name%></option>
8
+ <% end %>
9
+ </select>
10
+ </label>
11
+ </form>
12
+ <hr/>
13
+ <% if @terms %>
14
+ <div style="float:left; padding-right:30px;">
15
+ <h4>Field: <%= @field %></h4>
16
+ <form action="" onsubmit="return findTerm(document.getElementById('choose-term').value);">
17
+ <input id="choose-term" type="text"/></form>
18
+ <hr/>
19
+ <div id="terms">
20
+ </div>
21
+ <hr/>
22
+ <form action="">
23
+ <input type="submit" value="Previous" onclick="return prevTerm();"/>
24
+ <input type="submit" value="Next" onclick="return nextTerm();"/><br/>
25
+ </form>
26
+ </div>
27
+ <div style="float:left; padding-right:30px;">
28
+ <h4>Documents
29
+ <input name="show-documents" type="checkbox" id="show-documents" onchange="displayDoc();"/></h4>
30
+ <div id="doc-display">
31
+ <form action="" onsubmit="return findDoc(document.getElementById('choose-doc').value);">
32
+ <input id="choose-doc" type="text"/></form>
33
+ <hr/>
34
+ <div id="documents">
35
+ </div>
36
+ <hr/>
37
+ <form action="">
38
+ <input type="submit" value="Previous" onclick="return prevDoc();"/>
39
+ <input type="submit" value="Next" onclick="return nextDoc();"/><br/>
40
+ </form>
41
+ </div>
42
+ </div>
43
+ <script type="text/javascript"><!--
44
+ function createSideHeaderedTable(content) {
45
+ var table = document.createElement("table");
46
+ table.setAttribute('cellpadding', "0");
47
+ table.setAttribute('cellspacing', "0");
48
+ table.className = "left-headed";
49
+ for (var i = 0; i < content.length; i++) {
50
+ var tr = document.createElement("tr");
51
+ var th = document.createElement("th");
52
+ th.appendChild(document.createTextNode(content[i][0]));
53
+ tr.appendChild(th);
54
+ var td = document.createElement("td");
55
+ var c = content[i][1];
56
+ td.appendChild(c instanceof Object ? c : document.createTextNode(c));
57
+ tr.appendChild(td);
58
+ table.appendChild(tr);
59
+ }
60
+ return table;
61
+ }
62
+
63
+ var terms = <%= @terms %>;
64
+ var numTerms = terms.length;
65
+ var termI = 0;
66
+ var termDiv = document.getElementById("terms");
67
+ var termChooserTxt = document.getElementById('choose-term');
68
+
69
+ var docs = null;
70
+ var numDocs = 0;
71
+ var docI = 0;
72
+ var docDiv = document.getElementById("documents");
73
+ var showDocs = document.getElementById("show-documents");
74
+ var docChooserTxt = document.getElementById('choose-doc');
75
+ var docDisplayDiv = document.getElementById('doc-display');
76
+
77
+ function getDocs() {
78
+ var req = new XMLHttpRequest();
79
+ req.open('GET', '/term/termdocs/<%=@field%>/' + terms[termI][0], true);
80
+ req.onreadystatechange = function() {
81
+ if (req.readyState == 4) {
82
+ docs = eval(req.responseText);
83
+ numDocs = docs.length;
84
+ docI = 0;
85
+ displayDoc();
86
+ }
87
+ };
88
+ req.send(/*no params*/null);
89
+ return false;
90
+ }
91
+ function displayDoc() {
92
+ if (showDocs.checked) {
93
+ docDisplayDiv.style.display = 'block';
94
+ if (docs == null) {
95
+ getDocs();
96
+ } else {
97
+ docChooserTxt.value = docs[docI][0];
98
+ var docLink = document.createElement('a');
99
+ docLink.setAttribute('href', "/document/show/" + docs[docI][0]);
100
+ docLink.appendChild(document.createTextNode(docs[docI][0]));
101
+ var table = createSideHeaderedTable([
102
+ ['index', '' + (docI + 1) + ' of ' + numDocs],
103
+ ['document', docLink],
104
+ ['number of occurrences', docs[docI][1]],
105
+ ['positions', docs[docI][2].join(',')]
106
+ ]);
107
+ if (docDiv.firstChild) docDiv.replaceChild(table, docDiv.firstChild);
108
+ else docDiv.appendChild(table);
109
+ }
110
+ } else {
111
+ docDiv.innerHTML = '';
112
+ docDisplayDiv.style.display = 'none';
113
+ }
114
+ return false;
115
+ }
116
+ function nextDoc() {
117
+ if (docI < numDocs - 1) {
118
+ docI++;
119
+ displayDoc();
120
+ } else alert('No more docs. Already at the end.');
121
+ return false;
122
+ }
123
+ function prevDoc() {
124
+ if (docI > 0) {
125
+ docI -= 1;
126
+ displayDoc();
127
+ } else alert('No more docs. Already at the start.');
128
+ return false;
129
+ }
130
+ function findDoc(doc) {
131
+ if (docs && docs.length > 0) {
132
+ docI = bsearch(docs, doc, function(a, b) {return a[0] < b});
133
+ if (docI >= docs.length) docI -= 1;
134
+ displayDoc();
135
+ }
136
+ return false;
137
+ }
138
+ function displayTerm() {
139
+ docs = null;
140
+ termChooserTxt.value = terms[termI][0];
141
+ var table = createSideHeaderedTable([
142
+ ['index', '' + (termI + 1) + ' of ' + numTerms],
143
+ ['term', terms[termI][0]],
144
+ ['number of documents', terms[termI][1]],
145
+ ]);
146
+ termDiv.replaceChild(table, termDiv.firstChild);
147
+ displayDoc();
148
+ }
149
+ function nextTerm() {
150
+ if (termI < numTerms - 1) {
151
+ termI++;
152
+ displayTerm();
153
+ } else alert('No more terms. Already at the end.');
154
+ return false;
155
+ }
156
+ function prevTerm() {
157
+ if (termI > 0) {
158
+ termI -= 1;
159
+ displayTerm();
160
+ } else alert('No more terms. Already at the start.');
161
+ return false;
162
+ }
163
+ function findTerm(term) {
164
+ if (terms && terms.length > 0) {
165
+ termI = bsearch(terms, term, function(a, b) {return a[0] < b});
166
+ var match = (terms[termI]||[])[0];
167
+ if (term != match) {
168
+ alert('Term <%=@field%>:' + term + ' not found in index');
169
+ } else {
170
+ displayTerm();
171
+ }
172
+ }
173
+ return false;
174
+ }
175
+
176
+ function TermSuggestionProvider() {
177
+ }
178
+ TermSuggestionProvider.prototype.requestSuggestions = function(oAutoSuggestControl, bTypeAhead) {
179
+ var aSuggestions = new Array();
180
+ var sTextboxValue = oAutoSuggestControl.textbox.value;
181
+
182
+ if (sTextboxValue.length > 0) {
183
+ start = bsearch(terms, sTextboxValue, function(a, b) {return a[0] < b});
184
+ for (var i = start; i < terms.length
185
+ && terms[i][0].indexOf(sTextboxValue) == 0
186
+ && aSuggestions.length < 10; i++) {
187
+ aSuggestions.push(terms[i][0]);
188
+ }
189
+ oAutoSuggestControl.autosuggest(aSuggestions, bTypeAhead);
190
+ }
191
+ };
192
+ window.onload = function() {
193
+ var oTermTextbox = new AutoSuggestControl(termChooserTxt, new TermSuggestionProvider());
194
+ }
195
+ displayTerm();
196
+ //-->
197
+ </script>
198
+ <% end %>
199
+ <hr/>