");
}
// readable, raw, pos, type, start/end
static void writeTokens(JspWriter out, List tokens, final FieldType ft, boolean verbose, Set match) throws IOException {
// 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.
HashMap> map = new HashMap>();
boolean needRaw=false;
int pos=0;
for (Token t : tokens) {
if (!t.termText().equals(ft.indexedToReadable(t.termText()))) {
needRaw=true;
}
pos += t.getPositionIncrement();
List lst = map.get(pos);
if (lst==null) {
lst = new ArrayList(1);
map.put(pos,lst);
}
Tok tok = new Tok(t,pos);
lst.add(tok);
}
List[] arr = (List[])map.values().toArray(new ArrayList[map.size()]);
/***
// This generics version works fine with Resin, but fails with Tomcat 5.5
// with java.lang.AbstractMethodError
// at java.util.Arrays.mergeSort(Arrays.java:1284)
// at java.util.Arrays.sort(Arrays.java:1223)
Arrays.sort(arr, new Comparator>() {
public int compare(List toks, List toks1) {
return toks.get(0).pos - toks1.get(0).pos;
}
}
***/
Arrays.sort(arr, new Comparator() {
public int compare(Object a, Object b) {
List toks = (List)a;
List toks1 = (List)b;
return toks.get(0).pos - toks1.get(0).pos;
}
}
);
out.println("
");
if (verbose) {
printRow(out,"term position", arr, new ToStr() {
public String toStr(Object o) {
return Integer.toString(((Tok)o).pos);
}
}
,false
,verbose
,null);
}
printRow(out,"term text", arr, new ToStr() {
public String toStr(Object o) {
return ft.indexedToReadable( ((Tok)o).token.termText() );
}
}
,true
,verbose
,match
);
if (needRaw) {
printRow(out,"raw text", arr, new ToStr() {
public String toStr(Object o) {
// todo: output in hex or something?
// check if it's all ascii or not?
return ((Tok)o).token.termText();
}
}
,true
,verbose
,match
);
}
if (verbose) {
printRow(out,"term type", arr, new ToStr() {
public String toStr(Object o) {
return ((Tok)o).token.type();
}
}
,true
,verbose,
null
);
}
if (verbose) {
printRow(out,"source start,end", arr, new ToStr() {
public String toStr(Object o) {
Token t = ((Tok)o).token;
return Integer.toString(t.startOffset()) + ',' + t.endOffset() ;
}
}
,true
,verbose
,null
);
}
out.println("