rjack-solr 3.6.0.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. data/History.rdoc +2 -0
  2. data/Manifest.txt +62 -0
  3. data/NOTICE.txt +7 -0
  4. data/README.rdoc +71 -0
  5. data/Rakefile +12 -0
  6. data/assembly.xml +20 -0
  7. data/bin/rjack-solr-fg +53 -0
  8. data/config/config.rb +9 -0
  9. data/init/rjack-solr +44 -0
  10. data/lib/rjack-solr.rb +30 -0
  11. data/lib/rjack-solr/base.rb +28 -0
  12. data/lib/rjack-solr/commons-fileupload-1.2.1.jar +0 -0
  13. data/lib/rjack-solr/commons-io-2.1.jar +0 -0
  14. data/lib/rjack-solr/commons-lang-2.6.jar +0 -0
  15. data/lib/rjack-solr/config.rb +24 -0
  16. data/lib/rjack-solr/server.rb +70 -0
  17. data/lib/rjack-solr/solr-core-3.6.0.jar +0 -0
  18. data/lib/rjack-solr/solr-solrj-3.6.0.jar +0 -0
  19. data/pom.xml +96 -0
  20. data/test/test_solr.rb +43 -0
  21. data/webapp/META-INF/LICENSE.txt +1166 -0
  22. data/webapp/META-INF/MANIFEST.MF +13 -0
  23. data/webapp/META-INF/NOTICE.txt +438 -0
  24. data/webapp/WEB-INF/web.xml +153 -0
  25. data/webapp/WEB-INF/weblogic.xml +12 -0
  26. data/webapp/admin/_info.jsp +120 -0
  27. data/webapp/admin/action.jsp +94 -0
  28. data/webapp/admin/analysis.jsp +496 -0
  29. data/webapp/admin/analysis.xsl +179 -0
  30. data/webapp/admin/dataimport.jsp +53 -0
  31. data/webapp/admin/debug.jsp +103 -0
  32. data/webapp/admin/distributiondump.jsp +160 -0
  33. data/webapp/admin/favicon.ico +0 -0
  34. data/webapp/admin/form.jsp +152 -0
  35. data/webapp/admin/get-file.jsp +72 -0
  36. data/webapp/admin/get-properties.jsp +24 -0
  37. data/webapp/admin/header.jsp +44 -0
  38. data/webapp/admin/index.jsp +162 -0
  39. data/webapp/admin/jquery-1.4.3.min.js +166 -0
  40. data/webapp/admin/meta.xsl +34 -0
  41. data/webapp/admin/ping.jsp +52 -0
  42. data/webapp/admin/ping.xsl +71 -0
  43. data/webapp/admin/raw-schema.jsp +38 -0
  44. data/webapp/admin/registry.jsp +107 -0
  45. data/webapp/admin/registry.xsl +321 -0
  46. data/webapp/admin/replication/header.jsp +89 -0
  47. data/webapp/admin/replication/index.jsp +378 -0
  48. data/webapp/admin/schema.jsp +690 -0
  49. data/webapp/admin/solr-admin.css +215 -0
  50. data/webapp/admin/solr_small.png +0 -0
  51. data/webapp/admin/stats.jsp +92 -0
  52. data/webapp/admin/stats.xsl +220 -0
  53. data/webapp/admin/tabular.xsl +141 -0
  54. data/webapp/admin/threaddump.jsp +110 -0
  55. data/webapp/admin/threaddump.xsl +103 -0
  56. data/webapp/favicon.ico +0 -0
  57. data/webapp/index.jsp +49 -0
  58. metadata +217 -0
@@ -0,0 +1,153 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
3
+ <!--
4
+ Licensed to the Apache Software Foundation (ASF) under one or more
5
+ contributor license agreements. See the NOTICE file distributed with
6
+ this work for additional information regarding copyright ownership.
7
+ The ASF licenses this file to You under the Apache License, Version 2.0
8
+ (the "License"); you may not use this file except in compliance with
9
+ the License. You may obtain a copy of the License at
10
+
11
+ http://www.apache.org/licenses/LICENSE-2.0
12
+
13
+ Unless required by applicable law or agreed to in writing, software
14
+ distributed under the License is distributed on an "AS IS" BASIS,
15
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ See the License for the specific language governing permissions and
17
+ limitations under the License.
18
+ -->
19
+
20
+ <web-app>
21
+
22
+ <!-- Uncomment if you are trying to use a Resin version before 3.0.19.
23
+ Their XML implementation isn't entirely compatible with Xerces.
24
+ Below are the implementations to use with Sun's JVM.
25
+ <system-property javax.xml.xpath.XPathFactory=
26
+ "com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl"/>
27
+ <system-property javax.xml.parsers.DocumentBuilderFactory=
28
+ "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl"/>
29
+ <system-property javax.xml.parsers.SAXParserFactory=
30
+ "com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl"/>
31
+ -->
32
+
33
+ <!-- People who want to hardcode their "Solr Home" directly into the
34
+ WAR File can set the JNDI property here...
35
+ -->
36
+ <!--
37
+ <env-entry>
38
+ <env-entry-name>solr/home</env-entry-name>
39
+ <env-entry-value>/put/your/solr/home/here</env-entry-value>
40
+ <env-entry-type>java.lang.String</env-entry-type>
41
+ </env-entry>
42
+ -->
43
+
44
+ <!-- Any path (name) registered in solrconfig.xml will be sent to that filter -->
45
+ <filter>
46
+ <filter-name>SolrRequestFilter</filter-name>
47
+ <filter-class>org.apache.solr.servlet.SolrDispatchFilter</filter-class>
48
+ <!-- If you are wiring Solr into a larger web application which controls
49
+ the web context root, you will probably want to mount Solr under
50
+ a path prefix (app.war with /app/solr mounted into it, for example).
51
+ You will need to put this prefix in front of the SolrDispatchFilter
52
+ url-pattern mapping too (/solr/*), and also on any paths for
53
+ legacy Solr servlet mappings you may be using.
54
+ For the admin JSP's to work properly in a path-prefixed configuration,
55
+ the admin folder containing the JSPs needs to be under the app context root
56
+ named to match the path-prefix. For example:
57
+
58
+ .war
59
+ xxx
60
+ admin
61
+ stats.jsp
62
+ -->
63
+ <!--
64
+ <init-param>
65
+ <param-name>path-prefix</param-name>
66
+ <param-value>/xxx</param-value>
67
+ </init-param>
68
+ -->
69
+ </filter>
70
+
71
+ <filter-mapping>
72
+ <!--
73
+ NOTE: When using multicore, /admin JSP URLs with a core specified
74
+ such as /solr/coreName/admin/stats.jsp get forwarded by a
75
+ RequestDispatcher to /solr/admin/stats.jsp with the specified core
76
+ put into request scope keyed as "org.apache.solr.SolrCore".
77
+
78
+ It is unnecessary, and potentially problematic, to have the SolrDispatchFilter
79
+ configured to also filter on forwards. Do not configure
80
+ this dispatcher as <dispatcher>FORWARD</dispatcher>.
81
+ -->
82
+ <filter-name>SolrRequestFilter</filter-name>
83
+ <url-pattern>/*</url-pattern>
84
+ </filter-mapping>
85
+
86
+ <!-- Otherwise it will continue to the old servlets -->
87
+
88
+ <servlet>
89
+ <servlet-name>SolrServer</servlet-name>
90
+ <display-name>Solr</display-name>
91
+ <description>Solr Server</description>
92
+ <servlet-class>org.apache.solr.servlet.SolrServlet</servlet-class>
93
+ <load-on-startup>1</load-on-startup>
94
+ </servlet>
95
+
96
+ <servlet>
97
+ <servlet-name>SolrUpdate</servlet-name>
98
+ <display-name>SolrUpdate</display-name>
99
+ <description>Solr Update Handler</description>
100
+ <servlet-class>org.apache.solr.servlet.SolrUpdateServlet</servlet-class>
101
+ <load-on-startup>2</load-on-startup>
102
+ </servlet>
103
+
104
+ <servlet>
105
+ <servlet-name>Logging</servlet-name>
106
+ <servlet-class>org.apache.solr.servlet.LogLevelSelection</servlet-class>
107
+ </servlet>
108
+
109
+ <!-- @Deprecated -->
110
+ <servlet>
111
+ <servlet-name>ping</servlet-name>
112
+ <jsp-file>/admin/ping.jsp</jsp-file>
113
+ </servlet>
114
+
115
+ <servlet-mapping>
116
+ <servlet-name>SolrServer</servlet-name>
117
+ <url-pattern>/select/*</url-pattern>
118
+ </servlet-mapping>
119
+
120
+ <servlet-mapping>
121
+ <servlet-name>SolrUpdate</servlet-name>
122
+ <url-pattern>/update/*</url-pattern>
123
+ </servlet-mapping>
124
+
125
+ <servlet-mapping>
126
+ <servlet-name>Logging</servlet-name>
127
+ <url-pattern>/admin/logging</url-pattern>
128
+ </servlet-mapping>
129
+
130
+ <!-- @Deprecated -->
131
+ <servlet-mapping>
132
+ <servlet-name>ping</servlet-name>
133
+ <url-pattern>/admin/ping</url-pattern>
134
+ </servlet-mapping>
135
+
136
+ <!-- @Deprecated -->
137
+ <servlet-mapping>
138
+ <servlet-name>Logging</servlet-name>
139
+ <url-pattern>/admin/logging.jsp</url-pattern>
140
+ </servlet-mapping>
141
+
142
+ <mime-mapping>
143
+ <extension>.xsl</extension>
144
+ <!-- per http://www.w3.org/TR/2006/PR-xslt20-20061121/ -->
145
+ <mime-type>application/xslt+xml</mime-type>
146
+ </mime-mapping>
147
+
148
+ <welcome-file-list>
149
+ <welcome-file>index.jsp</welcome-file>
150
+ <welcome-file>index.html</welcome-file>
151
+ </welcome-file-list>
152
+
153
+ </web-app>
@@ -0,0 +1,12 @@
1
+ <?xml version='1.0' encoding='UTF-8'?>
2
+ <weblogic-web-app
3
+ xmlns="http://www.bea.com/ns/weblogic/90"
4
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5
+ xsi:schemaLocation="http://www.bea.com/ns/weblogic/90 http://www.bea.com/ns/weblogic/90/weblogic-web-app.xsd">
6
+
7
+ <container-descriptor>
8
+ <filter-dispatched-requests-enabled>false</filter-dispatched-requests-enabled>
9
+ </container-descriptor>
10
+
11
+ </weblogic-web-app>
12
+
@@ -0,0 +1,120 @@
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
+ // only try to figure out the hostname once in a static block so
31
+ // we don't have a potentially slow DNS lookup on every admin request
32
+ static InetAddress addr = null;
33
+ static String hostname = "unknown";
34
+ static {
35
+ try {
36
+ addr = InetAddress.getLocalHost();
37
+ hostname = addr.getCanonicalHostName();
38
+ } catch (UnknownHostException e) {
39
+ //default to unknown
40
+ }
41
+ }
42
+ %>
43
+
44
+ <%
45
+ //
46
+ SolrCore core = (SolrCore) request.getAttribute("org.apache.solr.SolrCore");
47
+ if (core == null) {
48
+ response.sendError( 404, "missing core name in path" );
49
+ return;
50
+ }
51
+
52
+ SolrConfig solrConfig = core.getSolrConfig();
53
+ int port = request.getServerPort();
54
+ IndexSchema schema = core.getSchema();
55
+
56
+ // enabled/disabled is purely from the point of a load-balancer
57
+ // and has no effect on local server function. If there is no healthcheck
58
+ // configured, don't put any status on the admin pages.
59
+ String enabledStatus = null;
60
+ String enabledFile = solrConfig.get("admin/healthcheck/text()",null);
61
+ boolean isEnabled = false;
62
+ if (enabledFile!=null) {
63
+ isEnabled = new File(enabledFile).exists();
64
+ }
65
+
66
+ String collectionName = schema!=null ? schema.getName():"unknown";
67
+
68
+ String defaultSearch = "";
69
+ {
70
+ StringWriter tmp = new StringWriter();
71
+ XML.escapeCharData
72
+ (solrConfig.get("admin/defaultQuery/text()", ""), tmp);
73
+ defaultSearch = tmp.toString();
74
+ }
75
+
76
+ String solrImplVersion = "";
77
+ String solrSpecVersion = "";
78
+ String luceneImplVersion = "";
79
+ String luceneSpecVersion = "";
80
+
81
+ {
82
+ Package p;
83
+ StringWriter tmp;
84
+
85
+ p = SolrCore.class.getPackage();
86
+
87
+ tmp = new StringWriter();
88
+ solrImplVersion = p.getImplementationVersion();
89
+ if (null != solrImplVersion) {
90
+ XML.escapeCharData(solrImplVersion, tmp);
91
+ solrImplVersion = tmp.toString();
92
+ }
93
+ tmp = new StringWriter();
94
+ solrSpecVersion = p.getSpecificationVersion() ;
95
+ if (null != solrSpecVersion) {
96
+ XML.escapeCharData(solrSpecVersion, tmp);
97
+ solrSpecVersion = tmp.toString();
98
+ }
99
+
100
+ p = LucenePackage.class.getPackage();
101
+
102
+ tmp = new StringWriter();
103
+ luceneImplVersion = p.getImplementationVersion();
104
+ if (null != luceneImplVersion) {
105
+ XML.escapeCharData(luceneImplVersion, tmp);
106
+ luceneImplVersion = tmp.toString();
107
+ }
108
+ tmp = new StringWriter();
109
+ luceneSpecVersion = p.getSpecificationVersion() ;
110
+ if (null != luceneSpecVersion) {
111
+ XML.escapeCharData(luceneSpecVersion, tmp);
112
+ luceneSpecVersion = tmp.toString();
113
+ }
114
+ }
115
+
116
+ String cwd=System.getProperty("user.dir");
117
+ String solrHome= solrConfig.getInstanceDir();
118
+
119
+ boolean cachingEnabled = !solrConfig.getHttpCachingConfig().isNever304();
120
+ %>
@@ -0,0 +1,94 @@
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
+ <%@include file="header.jsp" %>
26
+ <%
27
+
28
+ String action = request.getParameter("action");
29
+ String enableActionStatus = "";
30
+ boolean isValid = false;
31
+
32
+ if (action != null) {
33
+ // Validate fname
34
+ if ("Enable".compareTo(action) == 0) isValid = true;
35
+ if ("Disable".compareTo(action) == 0) isValid = true;
36
+ }
37
+ if (isValid) {
38
+ if ("Enable".compareTo(action) == 0) {
39
+ try {
40
+ File enableFile = new File(enabledFile);
41
+ if (enableFile.createNewFile()) {
42
+ enableActionStatus += "Enable Succeeded (enable file ";
43
+ enableActionStatus += enabledFile;
44
+ enableActionStatus += " created)";
45
+ } else {
46
+ enableActionStatus += "Already Enabled";
47
+ }
48
+ } catch(Exception e) {
49
+ enableActionStatus += "Enable Failed: " + e.toString();
50
+ }
51
+ }
52
+ if ("Disable".compareTo(action) == 0) {
53
+ try {
54
+ File enableFile = new File(enabledFile);
55
+ if (enableFile.delete()) {
56
+ enableActionStatus = "Disable Succeeded (enable file ";
57
+ enableActionStatus += enabledFile;
58
+ enableActionStatus += " removed)";
59
+ } else {
60
+ enableActionStatus = "Already Disabled";
61
+ }
62
+ } catch(Exception e) {
63
+ enableActionStatus += "Disable Failed: " + e.toString();
64
+ }
65
+ }
66
+ } else {
67
+ enableActionStatus = "Illegal Action";
68
+ }
69
+ // :TODO: might want to rework this so any logging change happens *after*
70
+ SolrCore.log.info(enableActionStatus);
71
+ %>
72
+ <br clear="all">
73
+ <table>
74
+ <tr>
75
+ <td>
76
+ <H3>Action:</H3>
77
+ </td>
78
+ <td>
79
+ <% XML.escapeCharData(action, out); %><br>
80
+ </td>
81
+ </tr>
82
+ <tr>
83
+ <td>
84
+ <H4>Result:</H4>
85
+ </td>
86
+ <td>
87
+ <% XML.escapeCharData(enableActionStatus, out); %><br>
88
+ </td>
89
+ </tr>
90
+ </table>
91
+ <br><br>
92
+ <a href=".">Return to Admin Page</a>
93
+ </body>
94
+ </html>
@@ -0,0 +1,496 @@
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.util.AttributeSource,
20
+ org.apache.lucene.util.Attribute,
21
+ org.apache.lucene.analysis.TokenStream,
22
+ org.apache.lucene.index.Payload,
23
+ org.apache.lucene.analysis.CharReader,
24
+ org.apache.lucene.analysis.CharStream,
25
+ org.apache.lucene.analysis.tokenattributes.*,
26
+ org.apache.lucene.util.AttributeReflector,
27
+ org.apache.solr.analysis.CharFilterFactory,
28
+ org.apache.solr.analysis.TokenFilterFactory,
29
+ org.apache.solr.analysis.TokenizerChain,
30
+ org.apache.solr.analysis.TokenizerFactory,
31
+ org.apache.solr.schema.FieldType,
32
+ org.apache.solr.schema.SchemaField,
33
+ org.apache.solr.common.util.XML,
34
+ javax.servlet.jsp.JspWriter,java.io.IOException
35
+ "%>
36
+ <%@ page import="java.io.Reader"%>
37
+ <%@ page import="java.io.StringReader"%>
38
+ <%@ page import="java.util.*"%>
39
+ <%@ page import="java.math.BigInteger" %>
40
+
41
+ <%-- $Id: analysis.jsp 1095519 2011-04-20 21:30:47Z uschindler $ --%>
42
+ <%-- $Source: /cvs/main/searching/org.apache.solrolarServer/resources/admin/analysis.jsp,v $ --%>
43
+ <%-- $Name: $ --%>
44
+
45
+ <%@include file="header.jsp" %>
46
+
47
+ <%
48
+ // is name a field name or a type name?
49
+ String nt = request.getParameter("nt");
50
+ if (nt==null || nt.length()==0) nt="name"; // assume field name
51
+ nt = nt.toLowerCase(Locale.ENGLISH).trim();
52
+ String name = request.getParameter("name");
53
+ if (name==null || name.length()==0) name="";
54
+ String val = request.getParameter("val");
55
+ if (val==null || val.length()==0) val="";
56
+ String qval = request.getParameter("qval");
57
+ if (qval==null || qval.length()==0) qval="";
58
+ String verboseS = request.getParameter("verbose");
59
+ boolean verbose = verboseS!=null && verboseS.equalsIgnoreCase("on");
60
+ String qverboseS = request.getParameter("qverbose");
61
+ boolean qverbose = qverboseS!=null && qverboseS.equalsIgnoreCase("on");
62
+ String highlightS = request.getParameter("highlight");
63
+ boolean highlight = highlightS!=null && highlightS.equalsIgnoreCase("on");
64
+ %>
65
+
66
+ <br clear="all">
67
+
68
+ <h2>Field Analysis</h2>
69
+
70
+ <form method="POST" action="analysis.jsp" accept-charset="UTF-8">
71
+ <table>
72
+ <tr>
73
+ <td>
74
+ <strong>Field
75
+ <select name="nt">
76
+ <option <%= nt.equals("name") ? "selected=\"selected\"" : "" %> >name</option>
77
+ <option <%= nt.equals("type") ? "selected=\"selected\"" : "" %>>type</option>
78
+ </select></strong>
79
+ </td>
80
+ <td>
81
+ <input class="std" name="name" type="text" value="<% XML.escapeCharData(name, out); %>">
82
+ </td>
83
+ </tr>
84
+ <tr>
85
+ <td>
86
+ <strong>Field value (Index)</strong>
87
+ <br/>
88
+ verbose output
89
+ <input name="verbose" type="checkbox"
90
+ <%= verbose ? "checked=\"true\"" : "" %> >
91
+ <br/>
92
+ highlight matches
93
+ <input name="highlight" type="checkbox"
94
+ <%= highlight ? "checked=\"true\"" : "" %> >
95
+ </td>
96
+ <td>
97
+ <textarea class="std" rows="8" cols="70" name="val"><% XML.escapeCharData(val,out); %></textarea>
98
+ </td>
99
+ </tr>
100
+ <tr>
101
+ <td>
102
+ <strong>Field value (Query)</strong>
103
+ <br/>
104
+ verbose output
105
+ <input name="qverbose" type="checkbox"
106
+ <%= qverbose ? "checked=\"true\"" : "" %> >
107
+ </td>
108
+ <td>
109
+ <textarea class="std" rows="1" cols="70" name="qval"><% XML.escapeCharData(qval,out); %></textarea>
110
+ </td>
111
+ </tr>
112
+ <tr>
113
+
114
+ <td>
115
+ </td>
116
+
117
+ <td>
118
+ <input class="stdbutton" type="submit" value="analyze">
119
+ </td>
120
+
121
+ </tr>
122
+ </table>
123
+ </form>
124
+
125
+
126
+ <%
127
+ SchemaField field=null;
128
+
129
+ if (name!="") {
130
+ if (nt.equals("name")) {
131
+ try {
132
+ field = schema.getField(name);
133
+ } catch (Exception e) {
134
+ out.print("<strong>Unknown Field: ");
135
+ XML.escapeCharData(name, out);
136
+ out.println("</strong>");
137
+ }
138
+ } else {
139
+ FieldType t = schema.getFieldTypes().get(name);
140
+ if (null == t) {
141
+ out.print("<strong>Unknown Field Type: ");
142
+ XML.escapeCharData(name, out);
143
+ out.println("</strong>");
144
+ } else {
145
+ field = new SchemaField("fakefieldoftype:"+name, t);
146
+ }
147
+ }
148
+ }
149
+
150
+ if (field!=null) {
151
+ HashSet<String> matches = null;
152
+ if (qval!="" && highlight) {
153
+ Reader reader = new StringReader(qval);
154
+ Analyzer analyzer = field.getType().getQueryAnalyzer();
155
+ TokenStream tstream = analyzer.reusableTokenStream(field.getName(),reader);
156
+ CharTermAttribute termAtt = tstream.addAttribute(CharTermAttribute.class);
157
+ tstream.reset();
158
+ matches = new HashSet<String>();
159
+ while (tstream.incrementToken()) {
160
+ matches.add(termAtt.toString());
161
+ }
162
+ }
163
+
164
+ if (val!="") {
165
+ out.println("<h3>Index Analyzer</h3>");
166
+ doAnalyzer(out, field, val, false, verbose, matches);
167
+ }
168
+ if (qval!="") {
169
+ out.println("<h3>Query Analyzer</h3>");
170
+ doAnalyzer(out, field, qval, true, qverbose, null);
171
+ }
172
+ }
173
+
174
+ %>
175
+
176
+
177
+ </body>
178
+ </html>
179
+
180
+
181
+ <%!
182
+ private static void doAnalyzer(JspWriter out, SchemaField field, String val, boolean queryAnalyser, boolean verbose, Set<String> match) throws Exception {
183
+
184
+ FieldType ft = field.getType();
185
+ Analyzer analyzer = queryAnalyser ?
186
+ ft.getQueryAnalyzer() : ft.getAnalyzer();
187
+ if (analyzer instanceof TokenizerChain) {
188
+ TokenizerChain tchain = (TokenizerChain)analyzer;
189
+ CharFilterFactory[] cfiltfacs = tchain.getCharFilterFactories();
190
+ TokenizerFactory tfac = tchain.getTokenizerFactory();
191
+ TokenFilterFactory[] filtfacs = tchain.getTokenFilterFactories();
192
+
193
+ if( cfiltfacs != null ){
194
+ String source = val;
195
+ for(CharFilterFactory cfiltfac : cfiltfacs ){
196
+ CharStream reader = CharReader.get(new StringReader(source));
197
+ reader = cfiltfac.create(reader);
198
+ if(verbose){
199
+ writeHeader(out, cfiltfac.getClass(), cfiltfac.getArgs());
200
+ source = writeCharStream(out, reader);
201
+ }
202
+ }
203
+ }
204
+
205
+ TokenStream tstream = tfac.create(tchain.charStream(new StringReader(val)));
206
+ List<AttributeSource> tokens = getTokens(tstream);
207
+ if (verbose) {
208
+ writeHeader(out, tfac.getClass(), tfac.getArgs());
209
+ }
210
+
211
+ writeTokens(out, tokens, ft, verbose, match);
212
+
213
+ for (TokenFilterFactory filtfac : filtfacs) {
214
+ if (verbose) {
215
+ writeHeader(out, filtfac.getClass(), filtfac.getArgs());
216
+ }
217
+
218
+ final Iterator<AttributeSource> iter = tokens.iterator();
219
+ tstream = filtfac.create( new TokenStream(tstream.getAttributeFactory()) {
220
+
221
+ public boolean incrementToken() throws IOException {
222
+ if (iter.hasNext()) {
223
+ clearAttributes();
224
+ AttributeSource token = iter.next();
225
+ Iterator<Class<? extends Attribute>> atts = token.getAttributeClassesIterator();
226
+ while (atts.hasNext()) // make sure all att impls in the token exist here
227
+ addAttribute(atts.next());
228
+ token.copyTo(this);
229
+ return true;
230
+ } else {
231
+ return false;
232
+ }
233
+ }
234
+ }
235
+ );
236
+ tokens = getTokens(tstream);
237
+
238
+ writeTokens(out, tokens, ft, verbose, match);
239
+ }
240
+
241
+ } else {
242
+ TokenStream tstream = analyzer.reusableTokenStream(field.getName(),new StringReader(val));
243
+ tstream.reset();
244
+ List<AttributeSource> tokens = getTokens(tstream);
245
+ if (verbose) {
246
+ writeHeader(out, analyzer.getClass(), Collections.EMPTY_MAP);
247
+ }
248
+ writeTokens(out, tokens, ft, verbose, match);
249
+ }
250
+ }
251
+
252
+
253
+ static List<AttributeSource> getTokens(TokenStream tstream) throws IOException {
254
+ List<AttributeSource> tokens = new ArrayList<AttributeSource>();
255
+ tstream.reset();
256
+ while (tstream.incrementToken()) {
257
+ tokens.add(tstream.cloneAttributes());
258
+ }
259
+ return tokens;
260
+ }
261
+
262
+ private static class ReflectItem {
263
+ final Class<? extends Attribute> attClass;
264
+ final String key;
265
+ final Object value;
266
+
267
+ ReflectItem(Class<? extends Attribute> attClass, String key, Object value) {
268
+ this.attClass = attClass;
269
+ this.key = key;
270
+ this.value = value;
271
+ }
272
+ }
273
+
274
+ private static class Tok {
275
+ final String term;
276
+ final int pos;
277
+ final List<ReflectItem> reflected = new ArrayList<ReflectItem>();
278
+
279
+ Tok(AttributeSource token, int pos) {
280
+ this.term = token.addAttribute(CharTermAttribute.class).toString();
281
+ this.pos = pos;
282
+ token.reflectWith(new AttributeReflector() {
283
+ public void reflect(Class<? extends Attribute> attClass, String key, Object value) {
284
+ // leave out position and term
285
+ if (CharTermAttribute.class.isAssignableFrom(attClass))
286
+ return;
287
+ if (PositionIncrementAttribute.class.isAssignableFrom(attClass))
288
+ return;
289
+ reflected.add(new ReflectItem(attClass, key, value));
290
+ }
291
+ });
292
+ }
293
+ }
294
+
295
+ private static interface TokToStr {
296
+ public String toStr(Tok o);
297
+ }
298
+
299
+ private static void printRow(JspWriter out, String header, String headerTitle, List<Tok>[] arrLst, TokToStr converter, boolean multival, boolean verbose, Set<String> match) throws IOException {
300
+ // find the maximum number of terms for any position
301
+ int maxSz=1;
302
+ if (multival) {
303
+ for (List lst : arrLst) {
304
+ maxSz = Math.max(lst.size(), maxSz);
305
+ }
306
+ }
307
+
308
+
309
+ for (int idx=0; idx<maxSz; idx++) {
310
+ out.println("<tr>");
311
+ if (idx==0 && verbose) {
312
+ if (header != null) {
313
+ out.print("<th NOWRAP rowspan=\""+maxSz+"\"");
314
+ if (headerTitle != null) {
315
+ out.print(" title=\"");
316
+ XML.escapeCharData(headerTitle,out);
317
+ out.print("\"");
318
+ }
319
+ out.print(">");
320
+ XML.escapeCharData(header,out);
321
+ out.println("</th>");
322
+ }
323
+ }
324
+
325
+ for (int posIndex=0; posIndex<arrLst.length; posIndex++) {
326
+ List<Tok> lst = arrLst[posIndex];
327
+ if (lst.size() <= idx) continue;
328
+ if (match!=null && match.contains(lst.get(idx).term)) {
329
+ out.print("<td class=\"highlight\"");
330
+ } else {
331
+ out.print("<td class=\"debugdata\"");
332
+ }
333
+
334
+ // if the last value in the column, use up
335
+ // the rest of the space via rowspan.
336
+ if (lst.size() == idx+1 && lst.size() < maxSz) {
337
+ out.print("rowspan=\""+(maxSz-lst.size()+1)+'"');
338
+ }
339
+
340
+ out.print('>');
341
+
342
+ XML.escapeCharData(converter.toStr(lst.get(idx)), out);
343
+ out.print("</td>");
344
+ }
345
+
346
+ out.println("</tr>");
347
+ }
348
+
349
+ }
350
+
351
+ /* this method is totally broken, as no charset involved: new String(byte[]) is crap!
352
+ static String isPayloadString( Payload p ) {
353
+ String sp = new String(p.getData());
354
+ for( int i=0; i < sp.length(); i++ ) {
355
+ if( !Character.isDefined( sp.charAt(i) ) || Character.isISOControl( sp.charAt(i) ) )
356
+ return "";
357
+ }
358
+ return "(" + sp + ")";
359
+ }
360
+ */
361
+
362
+ static void writeHeader(JspWriter out, Class clazz, Map<String,String> args) throws IOException {
363
+ out.print("<h4>");
364
+ out.print(clazz.getName());
365
+ XML.escapeCharData(" "+args,out);
366
+ out.println("</h4>");
367
+ }
368
+
369
+
370
+
371
+ // readable, raw, pos, type, start/end
372
+ static void writeTokens(JspWriter out, List<AttributeSource> tokens, final FieldType ft, boolean verbose, Set<String> match) throws IOException {
373
+
374
+ // Use a map to tell what tokens are in what positions
375
+ // because some tokenizers/filters may do funky stuff with
376
+ // very large increments, or negative increments.
377
+ HashMap<Integer,List<Tok>> map = new HashMap<Integer,List<Tok>>();
378
+ boolean needRaw=false;
379
+ int pos=0, reflectionCount = -1;
380
+ for (AttributeSource t : tokens) {
381
+ String text = t.addAttribute(CharTermAttribute.class).toString();
382
+ if (!text.equals(ft.indexedToReadable(text))) {
383
+ needRaw=true;
384
+ }
385
+
386
+ pos += t.addAttribute(PositionIncrementAttribute.class).getPositionIncrement();
387
+ List lst = map.get(pos);
388
+ if (lst==null) {
389
+ lst = new ArrayList(1);
390
+ map.put(pos,lst);
391
+ }
392
+ Tok tok = new Tok(t,pos);
393
+ // sanity check
394
+ if (reflectionCount < 0) {
395
+ reflectionCount = tok.reflected.size();
396
+ } else {
397
+ if (reflectionCount != tok.reflected.size())
398
+ throw new RuntimeException("Should not happen: Number of reflected entries differs for position=" + pos);
399
+ }
400
+ lst.add(tok);
401
+ }
402
+
403
+ List<Tok>[] arr = (List<Tok>[])map.values().toArray(new ArrayList[map.size()]);
404
+
405
+ // Jetty 6.1.3 miscompiles a generics-enabled version..., without generics:
406
+ Arrays.sort(arr, new Comparator() {
407
+ public int compare(Object toks, Object toks1) {
408
+ return ((List<Tok>)toks).get(0).pos - ((List<Tok>)toks1).get(0).pos;
409
+ }
410
+ });
411
+
412
+ out.println("<table width=\"auto\" class=\"analysis\" border=\"1\">");
413
+
414
+ if (verbose) {
415
+ printRow(out, "position", "calculated from " + PositionIncrementAttribute.class.getName(), arr, new TokToStr() {
416
+ public String toStr(Tok t) {
417
+ return Integer.toString(t.pos);
418
+ }
419
+ },false,verbose,null);
420
+ }
421
+
422
+ printRow(out, "term text", CharTermAttribute.class.getName(), arr, new TokToStr() {
423
+ public String toStr(Tok t) {
424
+ return ft.indexedToReadable(t.term);
425
+ }
426
+ },true,verbose,match);
427
+
428
+ if (verbose) {
429
+ if (needRaw) {
430
+ printRow(out, "raw text", CharTermAttribute.class.getName(), arr, new TokToStr() {
431
+ public String toStr(Tok t) {
432
+ // page is UTF-8, so anything goes.
433
+ return t.term;
434
+ }
435
+ },true,verbose,match);
436
+ }
437
+
438
+ for (int att=0; att < reflectionCount; att++) {
439
+ final ReflectItem item0 = arr[0].get(0).reflected.get(att);
440
+ final int i = att;
441
+ printRow(out, item0.key, item0.attClass.getName(), arr, new TokToStr() {
442
+ public String toStr(Tok t) {
443
+ final ReflectItem item = t.reflected.get(i);
444
+ if (item0.attClass != item.attClass || !item0.key.equals(item.key))
445
+ throw new RuntimeException("Should not happen: attribute types suddenly change at position=" + t.pos);
446
+ if (item.value instanceof Payload) {
447
+ Payload p = (Payload) item.value;
448
+ if( null != p ) {
449
+ BigInteger bi = new BigInteger( p.getData() );
450
+ String ret = bi.toString( 16 );
451
+ if (ret.length() % 2 != 0) {
452
+ // Pad with 0
453
+ ret = "0"+ret;
454
+ }
455
+ //TODO maybe fix: ret += isPayloadString(p);
456
+ return ret;
457
+ }
458
+ return "";
459
+ } else {
460
+ return (item.value != null) ? item.value.toString() : "";
461
+ }
462
+ }
463
+ },true,verbose,null);
464
+ }
465
+ }
466
+
467
+ out.println("</table>");
468
+ }
469
+
470
+ static String writeCharStream(JspWriter out, CharStream input) throws IOException {
471
+ out.println("<table width=\"auto\" class=\"analysis\" border=\"1\">");
472
+ out.println("<tr>");
473
+
474
+ out.print("<th NOWRAP>");
475
+ XML.escapeCharData("text",out);
476
+ out.println("</th>");
477
+
478
+ final int BUFFER_SIZE = 1024;
479
+ char[] buf = new char[BUFFER_SIZE];
480
+ int len = 0;
481
+ StringBuilder sb = new StringBuilder();
482
+ do {
483
+ len = input.read( buf, 0, BUFFER_SIZE );
484
+ if( len > 0 )
485
+ sb.append(buf, 0, len);
486
+ } while( len == BUFFER_SIZE );
487
+ out.print("<td class=\"debugdata\">");
488
+ XML.escapeCharData(sb.toString(),out);
489
+ out.println("</td>");
490
+
491
+ out.println("</tr>");
492
+ out.println("</table>");
493
+ return sb.toString();
494
+ }
495
+
496
+ %>