solrium 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. data/LICENSE.txt +712 -0
  2. data/README.markdown +51 -0
  3. data/Rakefile +24 -0
  4. data/VERSION.yml +4 -0
  5. data/bin/solr +9 -0
  6. data/lib/jars/jetty/ant-1.6.5.jar +0 -0
  7. data/lib/jars/jetty/commons-codec-1.3.jar +0 -0
  8. data/lib/jars/jetty/commons-fileupload-1.2.jar +0 -0
  9. data/lib/jars/jetty/jetty-7.0.0.pre5.jar +0 -0
  10. data/lib/jars/jetty/jetty-util-7.0.0.pre5.jar +0 -0
  11. data/lib/jars/jetty/jsp-2.1.jar +0 -0
  12. data/lib/jars/jetty/jsp-api-2.1.jar +0 -0
  13. data/lib/jars/jetty/servlet-api-3.0.pre4.jar +0 -0
  14. data/lib/jars/lucene/lucene-analyzers-2.4-dev.jar +0 -0
  15. data/lib/jars/lucene/lucene-core-2.4-dev.jar +0 -0
  16. data/lib/jars/lucene/lucene-highlighter-2.4-dev.jar +0 -0
  17. data/lib/jars/lucene/lucene-memory-2.4-dev.jar +0 -0
  18. data/lib/jars/lucene/lucene-queries-2.4-dev.jar +0 -0
  19. data/lib/jars/lucene/lucene-snowball-2.4-dev.jar +0 -0
  20. data/lib/jars/lucene/lucene-spellchecker-2.4-dev.jar +0 -0
  21. data/lib/jars/solr/apache-solr-common-1.3.0.jar +0 -0
  22. data/lib/jars/solr/apache-solr-core-1.3.0.jar +0 -0
  23. data/lib/jars/solr/commons-io-1.2.jar +0 -0
  24. data/lib/jars/solr/stax-1.2.0-dev.jar +0 -0
  25. data/lib/jars/solr/stax-api-1.0.jar +0 -0
  26. data/lib/jars/solr/stax-utils.jar +0 -0
  27. data/lib/jars/solr/xpp3-1.1.3.4.O.jar +0 -0
  28. data/lib/jetty.rb +83 -0
  29. data/lib/lucene.rb +33 -0
  30. data/lib/queries.rb +60 -0
  31. data/lib/remote.rb +22 -0
  32. data/lib/solr.rb +69 -0
  33. data/lib/solr_ext.rb +81 -0
  34. data/lib/webapp/admin/_info.jsp +110 -0
  35. data/lib/webapp/admin/action.jsp +116 -0
  36. data/lib/webapp/admin/analysis.jsp +456 -0
  37. data/lib/webapp/admin/analysis.xsl +179 -0
  38. data/lib/webapp/admin/distributiondump.jsp +158 -0
  39. data/lib/webapp/admin/favicon.ico +0 -0
  40. data/lib/webapp/admin/form.jsp +129 -0
  41. data/lib/webapp/admin/get-file.jsp +72 -0
  42. data/lib/webapp/admin/get-properties.jsp +24 -0
  43. data/lib/webapp/admin/header.jsp +41 -0
  44. data/lib/webapp/admin/index.jsp +154 -0
  45. data/lib/webapp/admin/jquery-1.2.3.min.js +32 -0
  46. data/lib/webapp/admin/logging.jsp +50 -0
  47. data/lib/webapp/admin/logging.xsl +91 -0
  48. data/lib/webapp/admin/meta.xsl +34 -0
  49. data/lib/webapp/admin/ping.jsp +65 -0
  50. data/lib/webapp/admin/ping.xsl +71 -0
  51. data/lib/webapp/admin/raw-schema.jsp +38 -0
  52. data/lib/webapp/admin/registry.jsp +107 -0
  53. data/lib/webapp/admin/registry.xsl +287 -0
  54. data/lib/webapp/admin/schema.jsp +661 -0
  55. data/lib/webapp/admin/solr-admin.css +206 -0
  56. data/lib/webapp/admin/solr-head.gif +0 -0
  57. data/lib/webapp/admin/solr-head.png +0 -0
  58. data/lib/webapp/admin/solr-lowercase.gif +0 -0
  59. data/lib/webapp/admin/solr-lowercase.png +0 -0
  60. data/lib/webapp/admin/stats.jsp +94 -0
  61. data/lib/webapp/admin/stats.xsl +220 -0
  62. data/lib/webapp/admin/tabular.xsl +141 -0
  63. data/lib/webapp/admin/threaddump.jsp +110 -0
  64. data/lib/webapp/admin/threaddump.xsl +103 -0
  65. data/lib/webapp/favicon.ico +0 -0
  66. data/lib/webapp/index.jsp +42 -0
  67. metadata +120 -0
@@ -0,0 +1,110 @@
1
+ <%--
2
+ Licensed to the Apache Software Foundation (ASF) under one or more
3
+ contributor license agreements. See the NOTICE file distributed with
4
+ this work for additional information regarding copyright ownership.
5
+ The ASF licenses this file to You under the Apache License, Version 2.0
6
+ (the "License"); you may not use this file except in compliance with
7
+ the License. You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
16
+ --%>
17
+ <%@ page import="org.apache.solr.core.SolrConfig,
18
+ org.apache.solr.core.SolrCore,
19
+ org.apache.solr.schema.IndexSchema,
20
+ java.io.File"%>
21
+ <%@ page import="java.net.InetAddress"%>
22
+ <%@ page import="java.io.StringWriter"%>
23
+ <%@ page import="org.apache.solr.core.Config"%>
24
+ <%@ page import="org.apache.solr.common.util.XML"%>
25
+ <%@ page import="org.apache.solr.common.SolrException"%>
26
+ <%@ page import="org.apache.lucene.LucenePackage"%>
27
+ <%@ page import="java.net.UnknownHostException" %>
28
+ <%
29
+ //
30
+ SolrCore core = (SolrCore) request.getAttribute("org.apache.solr.SolrCore");
31
+ if (core == null) {
32
+ response.sendError( 404, "missing core name in path" );
33
+ return;
34
+ }
35
+
36
+ SolrConfig solrConfig = core.getSolrConfig();
37
+ int port = request.getServerPort();
38
+ IndexSchema schema = core.getSchema();
39
+
40
+ // enabled/disabled is purely from the point of a load-balancer
41
+ // and has no effect on local server function. If there is no healthcheck
42
+ // configured, don't put any status on the admin pages.
43
+ String enabledStatus = null;
44
+ String enabledFile = solrConfig.get("admin/healthcheck/text()",null);
45
+ boolean isEnabled = false;
46
+ if (enabledFile!=null) {
47
+ isEnabled = new File(enabledFile).exists();
48
+ }
49
+
50
+ String collectionName = schema!=null ? schema.getName():"unknown";
51
+ InetAddress addr = null;
52
+ String hostname = "unknown";
53
+ try {
54
+ addr = InetAddress.getLocalHost();
55
+ hostname = addr.getCanonicalHostName();
56
+ } catch (UnknownHostException e) {
57
+ //default to unknown
58
+ }
59
+
60
+ String defaultSearch = "";
61
+ {
62
+ StringWriter tmp = new StringWriter();
63
+ XML.escapeCharData
64
+ (solrConfig.get("admin/defaultQuery/text()", null), tmp);
65
+ defaultSearch = tmp.toString();
66
+ }
67
+
68
+ String solrImplVersion = "";
69
+ String solrSpecVersion = "";
70
+ String luceneImplVersion = "";
71
+ String luceneSpecVersion = "";
72
+
73
+ {
74
+ Package p;
75
+ StringWriter tmp;
76
+
77
+ p = SolrCore.class.getPackage();
78
+
79
+ tmp = new StringWriter();
80
+ solrImplVersion = p.getImplementationVersion();
81
+ if (null != solrImplVersion) {
82
+ XML.escapeCharData(solrImplVersion, tmp);
83
+ solrImplVersion = tmp.toString();
84
+ }
85
+ tmp = new StringWriter();
86
+ solrSpecVersion = p.getSpecificationVersion() ;
87
+ if (null != solrSpecVersion) {
88
+ XML.escapeCharData(solrSpecVersion, tmp);
89
+ solrSpecVersion = tmp.toString();
90
+ }
91
+
92
+ p = LucenePackage.class.getPackage();
93
+
94
+ tmp = new StringWriter();
95
+ luceneImplVersion = p.getImplementationVersion();
96
+ if (null != luceneImplVersion) {
97
+ XML.escapeCharData(luceneImplVersion, tmp);
98
+ luceneImplVersion = tmp.toString();
99
+ }
100
+ tmp = new StringWriter();
101
+ luceneSpecVersion = p.getSpecificationVersion() ;
102
+ if (null != luceneSpecVersion) {
103
+ XML.escapeCharData(luceneSpecVersion, tmp);
104
+ luceneSpecVersion = tmp.toString();
105
+ }
106
+ }
107
+
108
+ String cwd=System.getProperty("user.dir");
109
+ String solrHome= solrConfig.getInstanceDir();
110
+ %>
@@ -0,0 +1,116 @@
1
+ <%@ page contentType="text/html; charset=utf-8" pageEncoding="UTF-8"%>
2
+ <%--
3
+ Licensed to the Apache Software Foundation (ASF) under one or more
4
+ contributor license agreements. See the NOTICE file distributed with
5
+ this work for additional information regarding copyright ownership.
6
+ The ASF licenses this file to You under the Apache License, Version 2.0
7
+ (the "License"); you may not use this file except in compliance with
8
+ the License. You may obtain a copy of the License at
9
+
10
+ http://www.apache.org/licenses/LICENSE-2.0
11
+
12
+ Unless required by applicable law or agreed to in writing, software
13
+ distributed under the License is distributed on an "AS IS" BASIS,
14
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ See the License for the specific language governing permissions and
16
+ limitations under the License.
17
+ --%>
18
+ <%@ page import="org.apache.solr.common.util.XML"%>
19
+ <%@ page import="org.apache.solr.core.SolrCore,
20
+ org.apache.solr.schema.IndexSchema,
21
+ java.io.File,
22
+ java.net.InetAddress,
23
+ java.net.UnknownHostException"%>
24
+ <%@ page import="java.util.Date"%>
25
+ <%@ page import="java.util.logging.Level"%>
26
+ <%@ page import="java.util.logging.Logger"%>
27
+ <%@include file="header.jsp" %>
28
+ <%
29
+
30
+ String action = request.getParameter("action");
31
+ String logging = request.getParameter("log");
32
+ String enableActionStatus = "";
33
+ boolean isValid = false;
34
+
35
+ if (action != null) {
36
+ // Validate fname
37
+ if ("Enable".compareTo(action) == 0) isValid = true;
38
+ if ("Disable".compareTo(action) == 0) isValid = true;
39
+ }
40
+ if (logging != null) {
41
+ action = "Set Log Level";
42
+ isValid = true;
43
+ }
44
+ if (isValid) {
45
+ if ("Enable".compareTo(action) == 0) {
46
+ try {
47
+ File enableFile = new File(enabledFile);
48
+ if (enableFile.createNewFile()) {
49
+ enableActionStatus += "Enable Succeeded (enable file ";
50
+ enableActionStatus += enabledFile;
51
+ enableActionStatus += " created)";
52
+ } else {
53
+ enableActionStatus += "Already Enabled";
54
+ }
55
+ } catch(Exception e) {
56
+ enableActionStatus += "Enable Failed: " + e.toString();
57
+ }
58
+ }
59
+ if ("Disable".compareTo(action) == 0) {
60
+ try {
61
+ File enableFile = new File(enabledFile);
62
+ if (enableFile.delete()) {
63
+ enableActionStatus = "Disable Succeeded (enable file ";
64
+ enableActionStatus += enabledFile;
65
+ enableActionStatus += " removed)";
66
+ } else {
67
+ enableActionStatus = "Already Disabled";
68
+ }
69
+ } catch(Exception e) {
70
+ enableActionStatus += "Disable Failed: " + e.toString();
71
+ }
72
+ }
73
+ if (logging != null) {
74
+ try {
75
+ Logger log = SolrCore.log;
76
+ Logger parent = log.getParent();
77
+ while (parent != null) {
78
+ log = parent;
79
+ parent = log.getParent();
80
+ }
81
+ log.setLevel(Level.parse(logging));
82
+ enableActionStatus = "Set Log Level (" + logging + ") Succeeded";
83
+ } catch(Exception e) {
84
+ enableActionStatus += "Set Log Level (" + logging + ") Failed: "
85
+ + e.toString();
86
+ }
87
+ }
88
+ } else {
89
+ enableActionStatus = "Illegal Action";
90
+ }
91
+ // :TODO: might want to rework this so any logging change happens *after*
92
+ SolrCore.log.log(Level.INFO, enableActionStatus);
93
+ %>
94
+ <br clear="all">
95
+ <table>
96
+ <tr>
97
+ <td>
98
+ <H3>Action:</H3>
99
+ </td>
100
+ <td>
101
+ <% XML.escapeCharData(action, out); %><br>
102
+ </td>
103
+ </tr>
104
+ <tr>
105
+ <td>
106
+ <H4>Result:</H4>
107
+ </td>
108
+ <td>
109
+ <% XML.escapeCharData(enableActionStatus, out); %><br>
110
+ </td>
111
+ </tr>
112
+ </table>
113
+ <br><br>
114
+ <a href=".">Return to Admin Page</a>
115
+ </body>
116
+ </html>
@@ -0,0 +1,456 @@
1
+ <%@ page contentType="text/html; charset=utf-8" pageEncoding="UTF-8"%>
2
+ <%--
3
+ Licensed to the Apache Software Foundation (ASF) under one or more
4
+ contributor license agreements. See the NOTICE file distributed with
5
+ this work for additional information regarding copyright ownership.
6
+ The ASF licenses this file to You under the Apache License, Version 2.0
7
+ (the "License"); you may not use this file except in compliance with
8
+ the License. You may obtain a copy of the License at
9
+
10
+ http://www.apache.org/licenses/LICENSE-2.0
11
+
12
+ Unless required by applicable law or agreed to in writing, software
13
+ distributed under the License is distributed on an "AS IS" BASIS,
14
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ See the License for the specific language governing permissions and
16
+ limitations under the License.
17
+ --%>
18
+ <%@ page import="org.apache.lucene.analysis.Analyzer,
19
+ org.apache.lucene.analysis.Token,
20
+ org.apache.lucene.analysis.TokenStream,
21
+ org.apache.lucene.index.Payload,
22
+ org.apache.solr.analysis.TokenFilterFactory,
23
+ org.apache.solr.analysis.TokenizerChain,
24
+ org.apache.solr.analysis.TokenizerFactory,
25
+ org.apache.solr.schema.FieldType,
26
+ org.apache.solr.schema.SchemaField,
27
+ org.apache.solr.common.util.XML,
28
+ javax.servlet.jsp.JspWriter,java.io.IOException
29
+ "%>
30
+ <%@ page import="java.io.Reader"%>
31
+ <%@ page import="java.io.StringReader"%>
32
+ <%@ page import="java.util.*"%>
33
+ <%@ page import="java.math.BigInteger" %>
34
+
35
+ <%-- $Id: analysis.jsp 677047 2008-07-15 21:30:37Z hossman $ --%>
36
+ <%-- $Source: /cvs/main/searching/org.apache.solrolarServer/resources/admin/analysis.jsp,v $ --%>
37
+ <%-- $Name: $ --%>
38
+
39
+ <%@include file="header.jsp" %>
40
+
41
+ <%
42
+ // is name a field name or a type name?
43
+ String nt = request.getParameter("nt");
44
+ if (nt==null || nt.length()==0) nt="name"; // assume field name
45
+ nt = nt.toLowerCase().trim();
46
+ String name = request.getParameter("name");
47
+ if (name==null || name.length()==0) name="";
48
+ String val = request.getParameter("val");
49
+ if (val==null || val.length()==0) val="";
50
+ String qval = request.getParameter("qval");
51
+ if (qval==null || qval.length()==0) qval="";
52
+ String verboseS = request.getParameter("verbose");
53
+ boolean verbose = verboseS!=null && verboseS.equalsIgnoreCase("on");
54
+ String qverboseS = request.getParameter("qverbose");
55
+ boolean qverbose = qverboseS!=null && qverboseS.equalsIgnoreCase("on");
56
+ String highlightS = request.getParameter("highlight");
57
+ boolean highlight = highlightS!=null && highlightS.equalsIgnoreCase("on");
58
+ %>
59
+
60
+ <br clear="all">
61
+
62
+ <h2>Field Analysis</h2>
63
+
64
+ <form method="POST" action="analysis.jsp" accept-charset="UTF-8">
65
+ <table>
66
+ <tr>
67
+ <td>
68
+ <strong>Field
69
+ <select name="nt">
70
+ <option <%= nt.equals("name") ? "selected=\"selected\"" : "" %> >name</option>
71
+ <option <%= nt.equals("type") ? "selected=\"selected\"" : "" %>>type</option>
72
+ </select></strong>
73
+ </td>
74
+ <td>
75
+ <input class="std" name="name" type="text" value="<% XML.escapeCharData(name, out); %>">
76
+ </td>
77
+ </tr>
78
+ <tr>
79
+ <td>
80
+ <strong>Field value (Index)</strong>
81
+ <br/>
82
+ verbose output
83
+ <input name="verbose" type="checkbox"
84
+ <%= verbose ? "checked=\"true\"" : "" %> >
85
+ <br/>
86
+ highlight matches
87
+ <input name="highlight" type="checkbox"
88
+ <%= highlight ? "checked=\"true\"" : "" %> >
89
+ </td>
90
+ <td>
91
+ <textarea class="std" rows="8" cols="70" name="val"><% XML.escapeCharData(val,out); %></textarea>
92
+ </td>
93
+ </tr>
94
+ <tr>
95
+ <td>
96
+ <strong>Field value (Query)</strong>
97
+ <br/>
98
+ verbose output
99
+ <input name="qverbose" type="checkbox"
100
+ <%= qverbose ? "checked=\"true\"" : "" %> >
101
+ </td>
102
+ <td>
103
+ <textarea class="std" rows="1" cols="70" name="qval"><% XML.escapeCharData(qval,out); %></textarea>
104
+ </td>
105
+ </tr>
106
+ <tr>
107
+
108
+ <td>
109
+ </td>
110
+
111
+ <td>
112
+ <input class="stdbutton" type="submit" value="analyze">
113
+ </td>
114
+
115
+ </tr>
116
+ </table>
117
+ </form>
118
+
119
+
120
+ <%
121
+ SchemaField field=null;
122
+
123
+ if (name!="") {
124
+ if (nt.equals("name")) {
125
+ try {
126
+ field = schema.getField(name);
127
+ } catch (Exception e) {
128
+ out.print("<strong>Unknown Field: ");
129
+ XML.escapeCharData(name, out);
130
+ out.println("</strong>");
131
+ }
132
+ } else {
133
+ FieldType t = schema.getFieldTypes().get(name);
134
+ if (null == t) {
135
+ out.print("<strong>Unknown Field Type: ");
136
+ XML.escapeCharData(name, out);
137
+ out.println("</strong>");
138
+ } else {
139
+ field = new SchemaField("fakefieldoftype:"+name, t);
140
+ }
141
+ }
142
+ }
143
+
144
+ if (field!=null) {
145
+ HashSet<Tok> matches = null;
146
+ if (qval!="" && highlight) {
147
+ Reader reader = new StringReader(qval);
148
+ Analyzer analyzer = field.getType().getQueryAnalyzer();
149
+ TokenStream tstream = analyzer.tokenStream(field.getName(),reader);
150
+ List<Token> tokens = getTokens(tstream);
151
+ matches = new HashSet<Tok>();
152
+ for (Token t : tokens) { matches.add( new Tok(t,0)); }
153
+ }
154
+
155
+ if (val!="") {
156
+ out.println("<h3>Index Analyzer</h3>");
157
+ doAnalyzer(out, field, val, false, verbose,matches);
158
+ }
159
+ if (qval!="") {
160
+ out.println("<h3>Query Analyzer</h3>");
161
+ doAnalyzer(out, field, qval, true, qverbose,null);
162
+ }
163
+ }
164
+
165
+ %>
166
+
167
+
168
+ </body>
169
+ </html>
170
+
171
+
172
+ <%!
173
+ private static void doAnalyzer(JspWriter out, SchemaField field, String val, boolean queryAnalyser, boolean verbose, Set<Tok> match) throws Exception {
174
+ Reader reader = new StringReader(val);
175
+
176
+ FieldType ft = field.getType();
177
+ Analyzer analyzer = queryAnalyser ?
178
+ ft.getQueryAnalyzer() : ft.getAnalyzer();
179
+ if (analyzer instanceof TokenizerChain) {
180
+ TokenizerChain tchain = (TokenizerChain)analyzer;
181
+ TokenizerFactory tfac = tchain.getTokenizerFactory();
182
+ TokenFilterFactory[] filtfacs = tchain.getTokenFilterFactories();
183
+
184
+ TokenStream tstream = tfac.create(reader);
185
+ List<Token> tokens = getTokens(tstream);
186
+ tstream = tfac.create(reader);
187
+ if (verbose) {
188
+ writeHeader(out, tfac.getClass(), tfac.getArgs());
189
+ }
190
+
191
+ writeTokens(out, tokens, ft, verbose, match);
192
+
193
+ for (TokenFilterFactory filtfac : filtfacs) {
194
+ if (verbose) {
195
+ writeHeader(out, filtfac.getClass(), filtfac.getArgs());
196
+ }
197
+
198
+ final Iterator<Token> iter = tokens.iterator();
199
+ tstream = filtfac.create( new TokenStream() {
200
+ public Token next() throws IOException {
201
+ return iter.hasNext() ? iter.next() : null;
202
+ }
203
+ }
204
+ );
205
+ tokens = getTokens(tstream);
206
+
207
+ writeTokens(out, tokens, ft, verbose, match);
208
+ }
209
+
210
+ } else {
211
+ TokenStream tstream = analyzer.tokenStream(field.getName(),reader);
212
+ List<Token> tokens = getTokens(tstream);
213
+ if (verbose) {
214
+ writeHeader(out, analyzer.getClass(), new HashMap<String,String>());
215
+ }
216
+ writeTokens(out, tokens, ft, verbose, match);
217
+ }
218
+ }
219
+
220
+
221
+ static List<Token> getTokens(TokenStream tstream) throws IOException {
222
+ List<Token> tokens = new ArrayList<Token>();
223
+ while (true) {
224
+ Token t = tstream.next();
225
+ if (t==null) break;
226
+ tokens.add(t);
227
+ }
228
+ return tokens;
229
+ }
230
+
231
+
232
+ private static class Tok {
233
+ Token token;
234
+ int pos;
235
+ Tok(Token token, int pos) {
236
+ this.token=token;
237
+ this.pos=pos;
238
+ }
239
+
240
+ public boolean equals(Object o) {
241
+ return ((Tok)o).token.termText().equals(token.termText());
242
+ }
243
+ public int hashCode() {
244
+ return token.termText().hashCode();
245
+ }
246
+ public String toString() {
247
+ return token.termText();
248
+ }
249
+ }
250
+
251
+ private static interface ToStr {
252
+ public String toStr(Object o);
253
+ }
254
+
255
+ private static void printRow(JspWriter out, String header, List[] arrLst, ToStr converter, boolean multival, boolean verbose, Set<Tok> match) throws IOException {
256
+ // find the maximum number of terms for any position
257
+ int maxSz=1;
258
+ if (multival) {
259
+ for (List lst : arrLst) {
260
+ maxSz = Math.max(lst.size(), maxSz);
261
+ }
262
+ }
263
+
264
+
265
+ for (int idx=0; idx<maxSz; idx++) {
266
+ out.println("<tr>");
267
+ if (idx==0 && verbose) {
268
+ if (header != null) {
269
+ out.print("<th NOWRAP rowspan=\""+maxSz+"\">");
270
+ XML.escapeCharData(header,out);
271
+ out.println("</th>");
272
+ }
273
+ }
274
+
275
+ for (int posIndex=0; posIndex<arrLst.length; posIndex++) {
276
+ List<Tok> lst = arrLst[posIndex];
277
+ if (lst.size() <= idx) continue;
278
+ if (match!=null && match.contains(lst.get(idx))) {
279
+ out.print("<td class=\"highlight\"");
280
+ } else {
281
+ out.print("<td class=\"debugdata\"");
282
+ }
283
+
284
+ // if the last value in the column, use up
285
+ // the rest of the space via rowspan.
286
+ if (lst.size() == idx+1 && lst.size() < maxSz) {
287
+ out.print("rowspan=\""+(maxSz-lst.size()+1)+'"');
288
+ }
289
+
290
+ out.print('>');
291
+
292
+ XML.escapeCharData(converter.toStr(lst.get(idx)), out);
293
+ out.print("</td>");
294
+ }
295
+
296
+ out.println("</tr>");
297
+ }
298
+
299
+ }
300
+
301
+ static String isPayloadString( Payload p ) {
302
+ String sp = new String( p.getData() );
303
+ for( int i=0; i < sp.length(); i++ ) {
304
+ if( !Character.isDefined( sp.charAt(i) ) || Character.isISOControl( sp.charAt(i) ) )
305
+ return "";
306
+ }
307
+ return "(" + sp + ")";
308
+ }
309
+
310
+ static void writeHeader(JspWriter out, Class clazz, Map<String,String> args) throws IOException {
311
+ out.print("<h4>");
312
+ out.print(clazz.getName());
313
+ XML.escapeCharData(" "+args,out);
314
+ out.println("</h4>");
315
+ }
316
+
317
+
318
+
319
+ // readable, raw, pos, type, start/end
320
+ static void writeTokens(JspWriter out, List<Token> tokens, final FieldType ft, boolean verbose, Set<Tok> match) throws IOException {
321
+
322
+ // Use a map to tell what tokens are in what positions
323
+ // because some tokenizers/filters may do funky stuff with
324
+ // very large increments, or negative increments.
325
+ HashMap<Integer,List<Tok>> map = new HashMap<Integer,List<Tok>>();
326
+ boolean needRaw=false;
327
+ int pos=0;
328
+ for (Token t : tokens) {
329
+ if (!t.termText().equals(ft.indexedToReadable(t.termText()))) {
330
+ needRaw=true;
331
+ }
332
+
333
+ pos += t.getPositionIncrement();
334
+ List lst = map.get(pos);
335
+ if (lst==null) {
336
+ lst = new ArrayList(1);
337
+ map.put(pos,lst);
338
+ }
339
+ Tok tok = new Tok(t,pos);
340
+ lst.add(tok);
341
+ }
342
+
343
+ List<Tok>[] arr = (List<Tok>[])map.values().toArray(new ArrayList[map.size()]);
344
+
345
+ /* Jetty 6.1.3 miscompiles this generics version...
346
+ Arrays.sort(arr, new Comparator<List<Tok>>() {
347
+ public int compare(List<Tok> toks, List<Tok> toks1) {
348
+ return toks.get(0).pos - toks1.get(0).pos;
349
+ }
350
+ }
351
+ */
352
+
353
+ Arrays.sort(arr, new Comparator() {
354
+ public int compare(Object toks, Object toks1) {
355
+ return ((List<Tok>)toks).get(0).pos - ((List<Tok>)toks1).get(0).pos;
356
+ }
357
+ }
358
+
359
+
360
+ );
361
+
362
+ out.println("<table width=\"auto\" class=\"analysis\" border=\"1\">");
363
+
364
+ if (verbose) {
365
+ printRow(out,"term position", arr, new ToStr() {
366
+ public String toStr(Object o) {
367
+ return Integer.toString(((Tok)o).pos);
368
+ }
369
+ }
370
+ ,false
371
+ ,verbose
372
+ ,null);
373
+ }
374
+
375
+
376
+ printRow(out,"term text", arr, new ToStr() {
377
+ public String toStr(Object o) {
378
+ return ft.indexedToReadable( ((Tok)o).token.termText() );
379
+ }
380
+ }
381
+ ,true
382
+ ,verbose
383
+ ,match
384
+ );
385
+
386
+ if (needRaw) {
387
+ printRow(out,"raw text", arr, new ToStr() {
388
+ public String toStr(Object o) {
389
+ // page is UTF-8, so anything goes.
390
+ return ((Tok)o).token.termText();
391
+ }
392
+ }
393
+ ,true
394
+ ,verbose
395
+ ,match
396
+ );
397
+ }
398
+
399
+ if (verbose) {
400
+ printRow(out,"term type", arr, new ToStr() {
401
+ public String toStr(Object o) {
402
+ String tt = ((Tok)o).token.type();
403
+ if (tt == null) {
404
+ return "null";
405
+ } else {
406
+ return tt;
407
+ }
408
+ }
409
+ }
410
+ ,true
411
+ ,verbose,
412
+ null
413
+ );
414
+ }
415
+
416
+ if (verbose) {
417
+ printRow(out,"source start,end", arr, new ToStr() {
418
+ public String toStr(Object o) {
419
+ Token t = ((Tok)o).token;
420
+ return Integer.toString(t.startOffset()) + ',' + t.endOffset() ;
421
+ }
422
+ }
423
+ ,true
424
+ ,verbose
425
+ ,null
426
+ );
427
+ }
428
+
429
+ if (verbose) {
430
+ printRow(out,"payload", arr, new ToStr() {
431
+ public String toStr(Object o) {
432
+ Token t = ((Tok)o).token;
433
+ Payload p = t.getPayload();
434
+ if( null != p ) {
435
+ BigInteger bi = new BigInteger( p.getData() );
436
+ String ret = bi.toString( 16 );
437
+ if (ret.length() % 2 != 0) {
438
+ // Pad with 0
439
+ ret = "0"+ret;
440
+ }
441
+ ret += isPayloadString( p );
442
+ return ret;
443
+ }
444
+ return "";
445
+ }
446
+ }
447
+ ,true
448
+ ,verbose
449
+ ,null
450
+ );
451
+ }
452
+
453
+ out.println("</table>");
454
+ }
455
+
456
+ %>