2006-12-15 14:53:39 -05:00
|
|
|
<%@ page contentType="text/html; charset=utf-8" pageEncoding="UTF-8"%>
|
2006-12-14 21:37:49 -05:00
|
|
|
<%--
|
|
|
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
contributor license agreements. See the NOTICE file distributed with
|
|
|
|
this work for additional information regarding copyright ownership.
|
|
|
|
The ASF licenses this file to You under the Apache License, Version 2.0
|
|
|
|
(the "License"); you may not use this file except in compliance with
|
|
|
|
the License. You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
--%>
|
2006-01-26 00:37:29 -05:00
|
|
|
<%@ page import="org.apache.lucene.analysis.Analyzer,
|
2010-08-16 19:16:32 -04:00
|
|
|
org.apache.lucene.util.AttributeSource,
|
|
|
|
org.apache.lucene.util.Attribute,
|
|
|
|
org.apache.lucene.util.BytesRef,
|
2006-01-26 00:37:29 -05:00
|
|
|
org.apache.lucene.analysis.TokenStream,
|
2008-07-12 10:12:29 -04:00
|
|
|
org.apache.lucene.index.Payload,
|
2009-07-15 13:21:04 -04:00
|
|
|
org.apache.lucene.analysis.CharReader,
|
|
|
|
org.apache.lucene.analysis.CharStream,
|
2010-03-14 20:43:05 -04:00
|
|
|
org.apache.lucene.analysis.tokenattributes.*,
|
2011-01-19 17:41:16 -05:00
|
|
|
org.apache.lucene.util.AttributeReflector,
|
2009-07-08 21:35:30 -04:00
|
|
|
org.apache.solr.analysis.CharFilterFactory,
|
2006-01-26 00:37:29 -05:00
|
|
|
org.apache.solr.analysis.TokenFilterFactory,
|
|
|
|
org.apache.solr.analysis.TokenizerChain,
|
|
|
|
org.apache.solr.analysis.TokenizerFactory,
|
|
|
|
org.apache.solr.schema.FieldType,
|
2006-02-22 00:53:23 -05:00
|
|
|
org.apache.solr.schema.SchemaField,
|
2008-07-15 17:30:37 -04:00
|
|
|
org.apache.solr.common.util.XML,
|
2011-01-19 17:41:16 -05:00
|
|
|
javax.servlet.jsp.JspWriter,java.io.IOException,
|
|
|
|
org.apache.noggit.CharArr
|
2006-01-26 00:37:29 -05:00
|
|
|
"%>
|
|
|
|
<%@ page import="java.io.Reader"%>
|
|
|
|
<%@ page import="java.io.StringReader"%>
|
|
|
|
<%@ page import="java.util.*"%>
|
2008-07-12 10:12:29 -04:00
|
|
|
<%@ page import="java.math.BigInteger" %>
|
2006-02-22 00:53:23 -05:00
|
|
|
|
2006-12-15 14:53:39 -05:00
|
|
|
<%-- $Id$ --%>
|
2006-01-26 00:37:29 -05:00
|
|
|
|
2006-12-15 14:53:39 -05:00
|
|
|
<%@include file="header.jsp" %>
|
2006-01-26 00:37:29 -05:00
|
|
|
|
|
|
|
<%
|
2007-07-20 01:28:42 -04:00
|
|
|
// is name a field name or a type name?
|
|
|
|
String nt = request.getParameter("nt");
|
|
|
|
if (nt==null || nt.length()==0) nt="name"; // assume field name
|
2010-05-17 13:18:10 -04:00
|
|
|
nt = nt.toLowerCase(Locale.ENGLISH).trim();
|
2006-01-26 00:37:29 -05:00
|
|
|
String name = request.getParameter("name");
|
2006-12-15 14:53:39 -05:00
|
|
|
if (name==null || name.length()==0) name="";
|
2006-01-26 00:37:29 -05:00
|
|
|
String val = request.getParameter("val");
|
2006-12-15 14:53:39 -05:00
|
|
|
if (val==null || val.length()==0) val="";
|
2006-01-26 00:37:29 -05:00
|
|
|
String qval = request.getParameter("qval");
|
2006-12-15 14:53:39 -05:00
|
|
|
if (qval==null || qval.length()==0) qval="";
|
2006-01-26 00:37:29 -05:00
|
|
|
String verboseS = request.getParameter("verbose");
|
2006-12-15 14:53:39 -05:00
|
|
|
boolean verbose = verboseS!=null && verboseS.equalsIgnoreCase("on");
|
2006-01-26 00:37:29 -05:00
|
|
|
String qverboseS = request.getParameter("qverbose");
|
2006-12-15 14:53:39 -05:00
|
|
|
boolean qverbose = qverboseS!=null && qverboseS.equalsIgnoreCase("on");
|
2006-01-26 00:37:29 -05:00
|
|
|
String highlightS = request.getParameter("highlight");
|
2006-12-15 14:53:39 -05:00
|
|
|
boolean highlight = highlightS!=null && highlightS.equalsIgnoreCase("on");
|
2006-01-26 00:37:29 -05:00
|
|
|
%>
|
|
|
|
|
2006-12-15 14:53:39 -05:00
|
|
|
<br clear="all">
|
|
|
|
|
|
|
|
<h2>Field Analysis</h2>
|
|
|
|
|
2008-07-12 10:59:12 -04:00
|
|
|
<form method="POST" action="analysis.jsp" accept-charset="UTF-8">
|
2006-12-15 14:53:39 -05:00
|
|
|
<table>
|
|
|
|
<tr>
|
|
|
|
<td>
|
2011-01-19 17:41:16 -05:00
|
|
|
<strong>Field
|
2007-07-20 01:28:42 -04:00
|
|
|
<select name="nt">
|
2011-01-19 17:41:16 -05:00
|
|
|
<option <%= nt.equals("name") ? "selected=\"selected\"" : "" %> >name</option>
|
|
|
|
<option <%= nt.equals("type") ? "selected=\"selected\"" : "" %>>type</option>
|
2008-07-12 10:12:29 -04:00
|
|
|
</select></strong>
|
2006-12-15 14:53:39 -05:00
|
|
|
</td>
|
|
|
|
<td>
|
2011-01-19 17:41:16 -05:00
|
|
|
<input class="std" name="name" type="text" value="<% XML.escapeCharData(name, out); %>">
|
2006-12-15 14:53:39 -05:00
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>
|
2011-01-19 17:41:16 -05:00
|
|
|
<strong>Field value (Index)</strong>
|
2006-12-15 14:53:39 -05:00
|
|
|
<br/>
|
|
|
|
verbose output
|
|
|
|
<input name="verbose" type="checkbox"
|
|
|
|
<%= verbose ? "checked=\"true\"" : "" %> >
|
|
|
|
<br/>
|
|
|
|
highlight matches
|
|
|
|
<input name="highlight" type="checkbox"
|
|
|
|
<%= highlight ? "checked=\"true\"" : "" %> >
|
|
|
|
</td>
|
|
|
|
<td>
|
2011-01-19 17:41:16 -05:00
|
|
|
<textarea class="std" rows="8" cols="70" name="val"><% XML.escapeCharData(val,out); %></textarea>
|
2006-12-15 14:53:39 -05:00
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>
|
2011-01-19 17:41:16 -05:00
|
|
|
<strong>Field value (Query)</strong>
|
2006-12-15 14:53:39 -05:00
|
|
|
<br/>
|
|
|
|
verbose output
|
|
|
|
<input name="qverbose" type="checkbox"
|
|
|
|
<%= qverbose ? "checked=\"true\"" : "" %> >
|
|
|
|
</td>
|
|
|
|
<td>
|
2011-01-19 17:41:16 -05:00
|
|
|
<textarea class="std" rows="1" cols="70" name="qval"><% XML.escapeCharData(qval,out); %></textarea>
|
2006-12-15 14:53:39 -05:00
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
|
|
|
|
<td>
|
|
|
|
</td>
|
|
|
|
|
|
|
|
<td>
|
2011-01-19 17:41:16 -05:00
|
|
|
<input class="stdbutton" type="submit" value="analyze">
|
2006-12-15 14:53:39 -05:00
|
|
|
</td>
|
|
|
|
|
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
</form>
|
|
|
|
|
2006-01-26 00:37:29 -05:00
|
|
|
|
|
|
|
<%
|
2006-12-15 14:53:39 -05:00
|
|
|
SchemaField field=null;
|
2006-01-26 00:37:29 -05:00
|
|
|
|
2006-12-15 14:53:39 -05:00
|
|
|
if (name!="") {
|
2007-07-20 01:28:42 -04:00
|
|
|
if (nt.equals("name")) {
|
|
|
|
try {
|
|
|
|
field = schema.getField(name);
|
|
|
|
} catch (Exception e) {
|
2008-06-19 22:20:39 -04:00
|
|
|
out.print("<strong>Unknown Field: ");
|
|
|
|
XML.escapeCharData(name, out);
|
|
|
|
out.println("</strong>");
|
2007-07-20 01:28:42 -04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
FieldType t = schema.getFieldTypes().get(name);
|
|
|
|
if (null == t) {
|
2008-06-19 22:20:39 -04:00
|
|
|
out.print("<strong>Unknown Field Type: ");
|
|
|
|
XML.escapeCharData(name, out);
|
|
|
|
out.println("</strong>");
|
2007-07-20 01:28:42 -04:00
|
|
|
} else {
|
|
|
|
field = new SchemaField("fakefieldoftype:"+name, t);
|
|
|
|
}
|
2006-01-26 00:37:29 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-15 14:53:39 -05:00
|
|
|
if (field!=null) {
|
2011-01-19 17:41:16 -05:00
|
|
|
HashSet<BytesRef> matches = null;
|
2006-12-15 14:53:39 -05:00
|
|
|
if (qval!="" && highlight) {
|
2006-01-26 00:37:29 -05:00
|
|
|
Reader reader = new StringReader(qval);
|
|
|
|
Analyzer analyzer = field.getType().getQueryAnalyzer();
|
2009-08-30 12:18:21 -04:00
|
|
|
TokenStream tstream = analyzer.reusableTokenStream(field.getName(),reader);
|
2011-01-19 17:41:16 -05:00
|
|
|
TermToBytesRefAttribute bytesAtt = tstream.getAttribute(TermToBytesRefAttribute.class);
|
2009-08-30 12:18:21 -04:00
|
|
|
tstream.reset();
|
2011-01-19 17:41:16 -05:00
|
|
|
matches = new HashSet<BytesRef>();
|
|
|
|
while (tstream.incrementToken()) {
|
|
|
|
final BytesRef bytes = new BytesRef();
|
|
|
|
bytesAtt.toBytesRef(bytes);
|
|
|
|
matches.add(bytes);
|
|
|
|
}
|
2006-01-26 00:37:29 -05:00
|
|
|
}
|
|
|
|
|
2006-12-15 14:53:39 -05:00
|
|
|
if (val!="") {
|
|
|
|
out.println("<h3>Index Analyzer</h3>");
|
2011-01-19 17:41:16 -05:00
|
|
|
doAnalyzer(out, field, val, false, verbose, matches);
|
2006-01-26 00:37:29 -05:00
|
|
|
}
|
2006-12-15 14:53:39 -05:00
|
|
|
if (qval!="") {
|
|
|
|
out.println("<h3>Query Analyzer</h3>");
|
2011-01-19 17:41:16 -05:00
|
|
|
doAnalyzer(out, field, qval, true, qverbose, null);
|
2006-01-26 00:37:29 -05:00
|
|
|
}
|
|
|
|
}
|
2006-12-15 14:53:39 -05:00
|
|
|
|
2006-01-26 00:37:29 -05:00
|
|
|
%>
|
2006-12-15 14:53:39 -05:00
|
|
|
|
|
|
|
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
|
2006-01-26 00:37:29 -05:00
|
|
|
|
|
|
|
<%!
|
2011-01-19 17:41:16 -05:00
|
|
|
private static void doAnalyzer(JspWriter out, SchemaField field, String val, boolean queryAnalyser, boolean verbose, Set<BytesRef> match) throws Exception {
|
2006-01-26 00:37:29 -05:00
|
|
|
|
|
|
|
FieldType ft = field.getType();
|
2006-12-15 14:53:39 -05:00
|
|
|
Analyzer analyzer = queryAnalyser ?
|
|
|
|
ft.getQueryAnalyzer() : ft.getAnalyzer();
|
2006-01-26 00:37:29 -05:00
|
|
|
if (analyzer instanceof TokenizerChain) {
|
|
|
|
TokenizerChain tchain = (TokenizerChain)analyzer;
|
2009-07-08 21:35:30 -04:00
|
|
|
CharFilterFactory[] cfiltfacs = tchain.getCharFilterFactories();
|
2006-01-26 00:37:29 -05:00
|
|
|
TokenizerFactory tfac = tchain.getTokenizerFactory();
|
|
|
|
TokenFilterFactory[] filtfacs = tchain.getTokenFilterFactories();
|
|
|
|
|
2009-07-08 21:35:30 -04:00
|
|
|
if( cfiltfacs != null ){
|
2009-08-07 19:05:05 -04:00
|
|
|
String source = val;
|
2009-07-08 21:35:30 -04:00
|
|
|
for(CharFilterFactory cfiltfac : cfiltfacs ){
|
2009-08-07 19:05:05 -04:00
|
|
|
CharStream reader = CharReader.get(new StringReader(source));
|
2009-07-08 21:35:30 -04:00
|
|
|
reader = cfiltfac.create(reader);
|
|
|
|
if(verbose){
|
|
|
|
writeHeader(out, cfiltfac.getClass(), cfiltfac.getArgs());
|
2009-08-07 19:05:05 -04:00
|
|
|
source = writeCharStream(out, reader);
|
2009-07-08 21:35:30 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-07 19:05:05 -04:00
|
|
|
TokenStream tstream = tfac.create(tchain.charStream(new StringReader(val)));
|
2010-08-16 19:16:32 -04:00
|
|
|
List<AttributeSource> tokens = getTokens(tstream);
|
2006-01-26 00:37:29 -05:00
|
|
|
if (verbose) {
|
|
|
|
writeHeader(out, tfac.getClass(), tfac.getArgs());
|
|
|
|
}
|
|
|
|
|
|
|
|
writeTokens(out, tokens, ft, verbose, match);
|
|
|
|
|
|
|
|
for (TokenFilterFactory filtfac : filtfacs) {
|
|
|
|
if (verbose) {
|
|
|
|
writeHeader(out, filtfac.getClass(), filtfac.getArgs());
|
|
|
|
}
|
|
|
|
|
2010-08-16 19:16:32 -04:00
|
|
|
final Iterator<AttributeSource> iter = tokens.iterator();
|
|
|
|
tstream = filtfac.create( new TokenStream(tstream.getAttributeFactory()) {
|
2010-03-14 20:43:05 -04:00
|
|
|
|
|
|
|
public boolean incrementToken() throws IOException {
|
|
|
|
if (iter.hasNext()) {
|
2010-08-16 19:16:32 -04:00
|
|
|
AttributeSource token = iter.next();
|
|
|
|
Iterator<Class<? extends Attribute>> atts = token.getAttributeClassesIterator();
|
|
|
|
while (atts.hasNext()) // make sure all att impls in the token exist here
|
|
|
|
addAttribute(atts.next());
|
|
|
|
token.copyTo(this);
|
2010-03-14 20:43:05 -04:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2006-01-26 00:37:29 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
tokens = getTokens(tstream);
|
|
|
|
|
|
|
|
writeTokens(out, tokens, ft, verbose, match);
|
|
|
|
}
|
2006-12-15 14:53:39 -05:00
|
|
|
|
2006-01-26 00:37:29 -05:00
|
|
|
} else {
|
2009-08-30 12:18:21 -04:00
|
|
|
TokenStream tstream = analyzer.reusableTokenStream(field.getName(),new StringReader(val));
|
|
|
|
tstream.reset();
|
2010-08-16 19:16:32 -04:00
|
|
|
List<AttributeSource> tokens = getTokens(tstream);
|
2006-01-26 00:37:29 -05:00
|
|
|
if (verbose) {
|
2011-01-19 17:41:16 -05:00
|
|
|
writeHeader(out, analyzer.getClass(), Collections.EMPTY_MAP);
|
2006-01-26 00:37:29 -05:00
|
|
|
}
|
|
|
|
writeTokens(out, tokens, ft, verbose, match);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-16 19:16:32 -04:00
|
|
|
static List<AttributeSource> getTokens(TokenStream tstream) throws IOException {
|
|
|
|
List<AttributeSource> tokens = new ArrayList<AttributeSource>();
|
2011-01-19 17:41:16 -05:00
|
|
|
tstream.reset();
|
|
|
|
while (tstream.incrementToken()) {
|
|
|
|
tokens.add(tstream.cloneAttributes());
|
2006-01-26 00:37:29 -05:00
|
|
|
}
|
|
|
|
return tokens;
|
|
|
|
}
|
|
|
|
|
2011-01-19 17:41:16 -05:00
|
|
|
private static class ReflectItem {
|
|
|
|
final Class<? extends Attribute> attClass;
|
|
|
|
final String key;
|
|
|
|
final Object value;
|
|
|
|
|
|
|
|
ReflectItem(Class<? extends Attribute> attClass, String key, Object value) {
|
|
|
|
this.attClass = attClass;
|
|
|
|
this.key = key;
|
|
|
|
this.value = value;
|
2006-01-26 00:37:29 -05:00
|
|
|
}
|
2011-01-19 17:41:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
private static class Tok {
|
|
|
|
final BytesRef bytes = new BytesRef();
|
|
|
|
final String rawText, text;
|
|
|
|
final int pos;
|
|
|
|
final List<ReflectItem> reflected = new ArrayList<ReflectItem>();
|
|
|
|
|
|
|
|
Tok(AttributeSource token, int pos, FieldType ft) {
|
|
|
|
this.pos = pos;
|
|
|
|
token.getAttribute(TermToBytesRefAttribute.class).toBytesRef(bytes);
|
|
|
|
rawText = (token.hasAttribute(CharTermAttribute.class)) ?
|
|
|
|
token.getAttribute(CharTermAttribute.class).toString() : null;
|
|
|
|
final CharArr textBuf = new CharArr(bytes.length);
|
|
|
|
ft.indexedToReadable(bytes, textBuf);
|
|
|
|
text = textBuf.toString();
|
|
|
|
token.reflectWith(new AttributeReflector() {
|
|
|
|
public void reflect(Class<? extends Attribute> attClass, String key, Object value) {
|
|
|
|
// leave out position and raw term
|
|
|
|
if (TermToBytesRefAttribute.class.isAssignableFrom(attClass))
|
|
|
|
return;
|
|
|
|
if (CharTermAttribute.class.isAssignableFrom(attClass))
|
|
|
|
return;
|
|
|
|
if (PositionIncrementAttribute.class.isAssignableFrom(attClass))
|
|
|
|
return;
|
|
|
|
reflected.add(new ReflectItem(attClass, key, value));
|
|
|
|
}
|
|
|
|
});
|
2010-08-16 19:16:32 -04:00
|
|
|
}
|
2006-01-26 00:37:29 -05:00
|
|
|
}
|
|
|
|
|
2011-01-19 17:41:16 -05:00
|
|
|
private static interface TokToStr {
|
|
|
|
public String toStr(Tok o);
|
2006-01-26 00:37:29 -05:00
|
|
|
}
|
|
|
|
|
2011-01-19 17:41:16 -05:00
|
|
|
private static void printRow(JspWriter out, String header, String headerTitle, List<Tok>[] arrLst, TokToStr converter, boolean multival, boolean verbose, Set<BytesRef> match) throws IOException {
|
2006-12-15 14:53:39 -05:00
|
|
|
// find the maximum number of terms for any position
|
|
|
|
int maxSz=1;
|
|
|
|
if (multival) {
|
|
|
|
for (List lst : arrLst) {
|
|
|
|
maxSz = Math.max(lst.size(), maxSz);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (int idx=0; idx<maxSz; idx++) {
|
|
|
|
out.println("<tr>");
|
|
|
|
if (idx==0 && verbose) {
|
|
|
|
if (header != null) {
|
2011-01-19 17:41:16 -05:00
|
|
|
out.print("<th NOWRAP rowspan=\""+maxSz+"\"");
|
|
|
|
if (headerTitle != null) {
|
|
|
|
out.print(" title=\"");
|
|
|
|
XML.escapeCharData(headerTitle,out);
|
|
|
|
out.print("\"");
|
|
|
|
}
|
|
|
|
out.print(">");
|
2006-12-15 14:53:39 -05:00
|
|
|
XML.escapeCharData(header,out);
|
|
|
|
out.println("</th>");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-01 00:46:34 -05:00
|
|
|
for (int posIndex=0; posIndex<arrLst.length; posIndex++) {
|
|
|
|
List<Tok> lst = arrLst[posIndex];
|
2006-12-15 14:53:39 -05:00
|
|
|
if (lst.size() <= idx) continue;
|
2011-01-19 17:41:16 -05:00
|
|
|
if (match!=null && match.contains(lst.get(idx).bytes)) {
|
2006-12-15 14:53:39 -05:00
|
|
|
out.print("<td class=\"highlight\"");
|
|
|
|
} else {
|
|
|
|
out.print("<td class=\"debugdata\"");
|
|
|
|
}
|
|
|
|
|
2007-03-01 00:46:34 -05:00
|
|
|
// if the last value in the column, use up
|
|
|
|
// the rest of the space via rowspan.
|
|
|
|
if (lst.size() == idx+1 && lst.size() < maxSz) {
|
|
|
|
out.print("rowspan=\""+(maxSz-lst.size()+1)+'"');
|
2006-12-15 14:53:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
out.print('>');
|
|
|
|
|
|
|
|
XML.escapeCharData(converter.toStr(lst.get(idx)), out);
|
|
|
|
out.print("</td>");
|
|
|
|
}
|
|
|
|
|
|
|
|
out.println("</tr>");
|
2006-12-12 17:24:47 -05:00
|
|
|
}
|
2006-12-15 14:53:39 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void writeHeader(JspWriter out, Class clazz, Map<String,String> args) throws IOException {
|
|
|
|
out.print("<h4>");
|
|
|
|
out.print(clazz.getName());
|
|
|
|
XML.escapeCharData(" "+args,out);
|
|
|
|
out.println("</h4>");
|
2006-01-26 00:37:29 -05:00
|
|
|
}
|
|
|
|
|
2006-12-15 14:53:39 -05:00
|
|
|
|
|
|
|
|
2006-01-26 00:37:29 -05:00
|
|
|
// readable, raw, pos, type, start/end
|
2011-01-19 17:41:16 -05:00
|
|
|
static void writeTokens(JspWriter out, List<AttributeSource> tokens, final FieldType ft, boolean verbose, Set<BytesRef> match) throws IOException {
|
2006-01-26 00:37:29 -05:00
|
|
|
|
|
|
|
// Use a map to tell what tokens are in what positions
|
|
|
|
// because some tokenizers/filters may do funky stuff with
|
|
|
|
// very large increments, or negative increments.
|
2006-12-15 14:53:39 -05:00
|
|
|
HashMap<Integer,List<Tok>> map = new HashMap<Integer,List<Tok>>();
|
|
|
|
boolean needRaw=false;
|
2011-01-19 17:41:16 -05:00
|
|
|
int pos=0, reflectionCount = -1;
|
2010-08-16 19:16:32 -04:00
|
|
|
for (AttributeSource t : tokens) {
|
|
|
|
pos += t.addAttribute(PositionIncrementAttribute.class).getPositionIncrement();
|
2006-01-26 00:37:29 -05:00
|
|
|
List lst = map.get(pos);
|
2006-12-15 14:53:39 -05:00
|
|
|
if (lst==null) {
|
2006-01-26 00:37:29 -05:00
|
|
|
lst = new ArrayList(1);
|
2006-12-15 14:53:39 -05:00
|
|
|
map.put(pos,lst);
|
2006-01-26 00:37:29 -05:00
|
|
|
}
|
2011-01-19 17:41:16 -05:00
|
|
|
Tok tok = new Tok(t,pos,ft);
|
|
|
|
// sanity check
|
|
|
|
if (reflectionCount < 0) {
|
|
|
|
reflectionCount = tok.reflected.size();
|
|
|
|
} else {
|
|
|
|
if (reflectionCount != tok.reflected.size())
|
|
|
|
throw new RuntimeException("Should not happen: Number of reflected entries differs for position=" + pos);
|
|
|
|
}
|
|
|
|
if (tok.rawText != null && !tok.text.equals(tok.rawText)) {
|
|
|
|
needRaw=true;
|
|
|
|
}
|
2006-01-26 00:37:29 -05:00
|
|
|
lst.add(tok);
|
|
|
|
}
|
|
|
|
|
|
|
|
List<Tok>[] arr = (List<Tok>[])map.values().toArray(new ArrayList[map.size()]);
|
|
|
|
|
2011-01-19 17:41:16 -05:00
|
|
|
// Jetty 6.1.3 miscompiles a generics-enabled version..., without generics:
|
2007-06-01 19:32:56 -04:00
|
|
|
Arrays.sort(arr, new Comparator() {
|
|
|
|
public int compare(Object toks, Object toks1) {
|
|
|
|
return ((List<Tok>)toks).get(0).pos - ((List<Tok>)toks1).get(0).pos;
|
|
|
|
}
|
2011-01-19 17:41:16 -05:00
|
|
|
});
|
2006-01-26 00:37:29 -05:00
|
|
|
|
2006-12-15 14:53:39 -05:00
|
|
|
out.println("<table width=\"auto\" class=\"analysis\" border=\"1\">");
|
|
|
|
|
|
|
|
if (verbose) {
|
2011-01-19 17:41:16 -05:00
|
|
|
printRow(out, "position", "calculated from " + PositionIncrementAttribute.class.getName(), arr, new TokToStr() {
|
|
|
|
public String toStr(Tok t) {
|
|
|
|
return Integer.toString(t.pos);
|
2006-12-15 14:53:39 -05:00
|
|
|
}
|
2011-01-19 17:41:16 -05:00
|
|
|
},false,verbose,null);
|
2006-12-15 14:53:39 -05:00
|
|
|
}
|
|
|
|
|
2011-01-19 17:41:16 -05:00
|
|
|
printRow(out, "term text", "indexedToReadable applied to " + TermToBytesRefAttribute.class.getName(), arr, new TokToStr() {
|
|
|
|
public String toStr(Tok t) {
|
|
|
|
return t.text;
|
2006-12-15 14:53:39 -05:00
|
|
|
}
|
2011-01-19 17:41:16 -05:00
|
|
|
},true,verbose,match);
|
2006-12-15 14:53:39 -05:00
|
|
|
|
|
|
|
if (verbose) {
|
2011-01-19 17:41:16 -05:00
|
|
|
if (needRaw) {
|
|
|
|
printRow(out, "raw text", CharTermAttribute.class.getName(), arr, new TokToStr() {
|
|
|
|
public String toStr(Tok t) {
|
|
|
|
// page is UTF-8, so anything goes.
|
|
|
|
return (t.rawText == null) ? "" : t.rawText;
|
2008-03-07 08:42:45 -05:00
|
|
|
}
|
2011-01-19 17:41:16 -05:00
|
|
|
},true,verbose,match);
|
2006-12-15 14:53:39 -05:00
|
|
|
}
|
2011-01-19 17:41:16 -05:00
|
|
|
|
|
|
|
printRow(out, "raw bytes", TermToBytesRefAttribute.class.getName(), arr, new TokToStr() {
|
|
|
|
public String toStr(Tok t) {
|
|
|
|
return t.bytes.toString();
|
2006-12-15 14:53:39 -05:00
|
|
|
}
|
2011-01-19 17:41:16 -05:00
|
|
|
},true,verbose,match);
|
|
|
|
|
|
|
|
for (int att=0; att < reflectionCount; att++) {
|
|
|
|
final ReflectItem item0 = arr[0].get(0).reflected.get(att);
|
|
|
|
final int i = att;
|
|
|
|
printRow(out, item0.key, item0.attClass.getName(), arr, new TokToStr() {
|
|
|
|
public String toStr(Tok t) {
|
|
|
|
final ReflectItem item = t.reflected.get(i);
|
|
|
|
if (item0.attClass != item.attClass || !item0.key.equals(item.key))
|
|
|
|
throw new RuntimeException("Should not happen: attribute types suddenly change at position=" + t.pos);
|
|
|
|
if (item.value instanceof Payload) {
|
|
|
|
final Payload p = (Payload) item.value;
|
|
|
|
return new BytesRef(p.getData()).toString();
|
|
|
|
} else {
|
|
|
|
return (item.value != null) ? item.value.toString() : "";
|
2008-07-12 10:12:29 -04:00
|
|
|
}
|
|
|
|
}
|
2011-01-19 17:41:16 -05:00
|
|
|
},true,verbose, null);
|
2008-07-12 10:12:29 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-15 14:53:39 -05:00
|
|
|
out.println("</table>");
|
2006-01-26 00:37:29 -05:00
|
|
|
}
|
|
|
|
|
2009-08-07 19:05:05 -04:00
|
|
|
static String writeCharStream(JspWriter out, CharStream input) throws IOException {
|
2009-07-08 21:35:30 -04:00
|
|
|
out.println("<table width=\"auto\" class=\"analysis\" border=\"1\">");
|
|
|
|
out.println("<tr>");
|
|
|
|
|
|
|
|
out.print("<th NOWRAP>");
|
|
|
|
XML.escapeCharData("text",out);
|
|
|
|
out.println("</th>");
|
|
|
|
|
|
|
|
final int BUFFER_SIZE = 1024;
|
|
|
|
char[] buf = new char[BUFFER_SIZE];
|
|
|
|
int len = 0;
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
do {
|
|
|
|
len = input.read( buf, 0, BUFFER_SIZE );
|
2009-10-11 06:04:01 -04:00
|
|
|
if( len > 0 )
|
|
|
|
sb.append(buf, 0, len);
|
2009-07-08 21:35:30 -04:00
|
|
|
} while( len == BUFFER_SIZE );
|
|
|
|
out.print("<td class=\"debugdata\">");
|
|
|
|
XML.escapeCharData(sb.toString(),out);
|
|
|
|
out.println("</td>");
|
|
|
|
|
|
|
|
out.println("</tr>");
|
|
|
|
out.println("</table>");
|
2009-08-07 19:05:05 -04:00
|
|
|
return sb.toString();
|
2009-07-08 21:35:30 -04:00
|
|
|
}
|
|
|
|
|
2006-01-26 00:37:29 -05:00
|
|
|
%>
|