You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-commits@lucene.apache.org by yo...@apache.org on 2006/12/15 20:53:39 UTC

svn commit: r487639 - /incubator/solr/trunk/src/webapp/resources/admin/analysis.jsp

Author: yonik
Date: Fri Dec 15 11:53:39 2006
New Revision: 487639

URL: http://svn.apache.org/viewvc?view=rev&rev=487639
Log:
reverting analysis.jsp changes from SOLR-58

Modified:
    incubator/solr/trunk/src/webapp/resources/admin/analysis.jsp

Modified: incubator/solr/trunk/src/webapp/resources/admin/analysis.jsp
URL: http://svn.apache.org/viewvc/incubator/solr/trunk/src/webapp/resources/admin/analysis.jsp?view=diff&rev=487639&r1=487638&r2=487639
==============================================================================
--- incubator/solr/trunk/src/webapp/resources/admin/analysis.jsp (original)
+++ incubator/solr/trunk/src/webapp/resources/admin/analysis.jsp Fri Dec 15 11:53:39 2006
@@ -1,4 +1,4 @@
-<%@ page contentType="text/xml; charset=utf-8" pageEncoding="UTF-8" language="java" %>
+<%@ page contentType="text/html; charset=utf-8" pageEncoding="UTF-8"%>
 <%--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
@@ -30,86 +30,129 @@
 <%@ page import="java.io.StringReader"%>
 <%@ page import="java.util.*"%>
 
-<?xml-stylesheet type="text/xsl" href="analysis.xsl"?>
+<%-- $Id$ --%>
+<%-- $Source: /cvs/main/searching/org.apache.solrolarServer/resources/admin/analysis.jsp,v $ --%>
+<%-- $Name:  $ --%>
 
-<%@include file="_info.jsp" %>
+<%@include file="header.jsp" %>
 
 <%
   String name = request.getParameter("name");
-  if (name == null || name.length() == 0) name = "";
+  if (name==null || name.length()==0) name="";
   String val = request.getParameter("val");
-  if (val == null || val.length() == 0) val = "";
+  if (val==null || val.length()==0) val="";
   String qval = request.getParameter("qval");
-  if (qval == null || qval.length() == 0) qval = "";
+  if (qval==null || qval.length()==0) qval="";
   String verboseS = request.getParameter("verbose");
-  boolean verbose = verboseS != null && verboseS.equalsIgnoreCase("on");
+  boolean verbose = verboseS!=null && verboseS.equalsIgnoreCase("on");
   String qverboseS = request.getParameter("qverbose");
-  boolean qverbose = qverboseS != null && qverboseS.equalsIgnoreCase("on");
+  boolean qverbose = qverboseS!=null && qverboseS.equalsIgnoreCase("on");
   String highlightS = request.getParameter("highlight");
-  boolean highlight = highlightS != null && highlightS.equalsIgnoreCase("on");
+  boolean highlight = highlightS!=null && highlightS.equalsIgnoreCase("on");
 %>
 
-<solr>
-<%@include file="heading.jsp" %>
-  <analysis>
+<br clear="all">
+
+<h2>Field Analysis</h2>
+
+<form method="GET" action="analysis.jsp">
+<table>
+<tr>
+  <td>
+	<strong>Field name</strong>
+  </td>
+  <td>
+	<input class="std" name="name" type="text" value="<%= name %>">
+  </td>
+</tr>
+<tr>
+  <td>
+	<strong>Field value (Index)</strong>
+  <br/>
+  verbose output
+  <input name="verbose" type="checkbox"
+     <%= verbose ? "checked=\"true\"" : "" %> >
+    <br/>
+  highlight matches
+  <input name="highlight" type="checkbox"
+     <%= highlight ? "checked=\"true\"" : "" %> >
+  </td>
+  <td>
+	<textarea class="std" rows="3" cols="70" name="val"><%= val %></textarea>
+  </td>
+</tr>
+<tr>
+  <td>
+	<strong>Field value (Query)</strong>
+  <br/>
+  verbose output
+  <input name="qverbose" type="checkbox"
+     <%= qverbose ? "checked=\"true\"" : "" %> >
+  </td>
+  <td>
+	<textarea class="std" rows="1" cols="70" name="qval"><%= qval %></textarea>
+  </td>
+</tr>
+<tr>
+
+  <td>
+  </td>
+
+  <td>
+	<input class="stdbutton" type="submit" value="analyze">
+  </td>
+
+</tr>
+</table>
+</form>
+
 
 <%
-  SchemaField field = null;
+  SchemaField field=null;
 
-  if (name != "") {
+  if (name!="") {
     try {
       field = schema.getField(name);
     } catch (Exception e) {
-      out.println("<error>Unknown Field " + name + "</error>");
+      out.println("<strong>Unknown Field " + name + "</strong>");
     }
   }
 
-  if (field != null) {
-    out.println("    <form>");
-    out.println("      <field>");
-      XML.escapeCharData(name, out);
-    out.println("</field>");
-    out.print("      <fieldIndexValue>");
-      XML.escapeCharData(val, out);
-    out.println("      </fieldIndexValue>");
-    out.print("      <fieldQueryValue>");
-      XML.escapeCharData(qval, out);
-    out.println("      </fieldQueryValue>");
-    out.println("    </form>");
-
+  if (field!=null) {
     HashSet<Tok> matches = null;
-    if (qval != "" && highlight) {
+    if (qval!="" && highlight) {
       Reader reader = new StringReader(qval);
       Analyzer analyzer =  field.getType().getQueryAnalyzer();
-      TokenStream tstream = analyzer.tokenStream(field.getName(), reader);
+      TokenStream tstream = analyzer.tokenStream(field.getName(),reader);
       List<Token> tokens = getTokens(tstream);
       matches = new HashSet<Tok>();
-      for (Token t : tokens) { matches.add( new Tok(t, 0)); }
+      for (Token t : tokens) { matches.add( new Tok(t,0)); }
     }
 
-    out.println("    <results>");
-    if (val != "") {
-      out.println("<indexAnalyzer>");
-      doAnalyzer(out, field, val, false, verbose, matches);
-      out.println("</indexAnalyzer>");
+    if (val!="") {
+      out.println("<h3>Index Analyzer</h3>");
+      doAnalyzer(out, field, val, false, verbose,matches);
     }
-    if (qval != "") {
-      out.println("<queryAnalyzer>");
-      doAnalyzer(out, field, qval, true, qverbose, null);
-      out.println("</queryAnalyzer>");
+    if (qval!="") {
+      out.println("<h3>Query Analyzer</h3>");
+      doAnalyzer(out, field, qval, true, qverbose,null);
     }
-    out.println("    </results>");
   }
+
 %>
-  </analysis>
-</solr>
+
+
+</body>
+</html>
+
 
 <%!
   private static void doAnalyzer(JspWriter out, SchemaField field, String val, boolean queryAnalyser, boolean verbose, Set<Tok> match) throws Exception {
     Reader reader = new StringReader(val);
 
     FieldType ft = field.getType();
-    Analyzer analyzer = queryAnalyser ? ft.getQueryAnalyzer() : ft.getAnalyzer();
+     Analyzer analyzer = queryAnalyser ?
+             ft.getQueryAnalyzer() : ft.getAnalyzer();
      if (analyzer instanceof TokenizerChain) {
        TokenizerChain tchain = (TokenizerChain)analyzer;
        TokenizerFactory tfac = tchain.getTokenizerFactory();
@@ -118,14 +161,12 @@
        TokenStream tstream = tfac.create(reader);
        List<Token> tokens = getTokens(tstream);
        tstream = tfac.create(reader);
-       // write tokenizer factories
        if (verbose) {
          writeHeader(out, tfac.getClass(), tfac.getArgs());
        }
 
        writeTokens(out, tokens, ft, verbose, match);
 
-       // write filter factories
        for (TokenFilterFactory filtfac : filtfacs) {
          if (verbose) {
            writeHeader(out, filtfac.getClass(), filtfac.getArgs());
@@ -142,6 +183,7 @@
 
          writeTokens(out, tokens, ft, verbose, match);
        }
+
      } else {
        TokenStream tstream = analyzer.tokenStream(field.getName(),reader);
        List<Token> tokens = getTokens(tstream);
@@ -157,7 +199,7 @@
     List<Token> tokens = new ArrayList<Token>();
     while (true) {
       Token t = tstream.next();
-      if (t == null) break;
+      if (t==null) break;
       tokens.add(t);
     }
     return tokens;
@@ -168,8 +210,8 @@
     Token token;
     int pos;
     Tok(Token token, int pos) {
-      this.token = token;
-      this.pos = pos;
+      this.token=token;
+      this.pos=pos;
     }
 
     public boolean equals(Object o) {
@@ -179,7 +221,7 @@
       return token.termText().hashCode();
     }
     public String toString() {
-      return token.termText() + " at position " + pos;
+      return token.termText();
     }
   }
 
@@ -187,38 +229,81 @@
     public String toStr(Object o);
   }
 
-  static void writeHeader(JspWriter out, Class clazz, Map<String,String> args) throws IOException {
-    out.println("  <factory class=\"" + clazz.getName() + "\">");
-    out.println("    <args>");
-    for (Iterator<String> iter = args.keySet().iterator(); iter.hasNext(); ) {
-      String key = iter.next();
-      String value = args.get(key);
-      out.println("      <arg name=\"" + key + "\">" + value + "</arg>");
+  private static void printRow(JspWriter out, String header, List[] arrLst, ToStr converter, boolean multival, boolean verbose, Set<Tok> match) throws IOException {
+    // find the maximum number of terms for any position
+    int maxSz=1;
+    if (multival) {
+      for (List lst : arrLst) {
+        maxSz = Math.max(lst.size(), maxSz);
+      }
     }
-    out.println("    </args>");
+
+
+    for (int idx=0; idx<maxSz; idx++) {
+      out.println("<tr>");
+      if (idx==0 && verbose) {
+        if (header != null) {
+          out.print("<th NOWRAP rowspan=\""+maxSz+"\">");
+          XML.escapeCharData(header,out);
+          out.println("</th>");
+        }
+      }
+
+      for (List<Tok> lst : arrLst) {
+        if (lst.size() <= idx) continue;
+        if (match!=null && match.contains(lst.get(idx))) {
+          out.print("<td class=\"highlight\"");
+        } else {
+          out.print("<td class=\"debugdata\"");
+        }
+
+        if (idx==0 && lst.size()==1 && maxSz > 1) {
+          out.print("rowspan=\""+maxSz+'"');
+        }
+
+        out.print('>');
+
+        XML.escapeCharData(converter.toStr(lst.get(idx)), out);
+        out.print("</td>");
+      }
+
+      out.println("</tr>");
+    }
+
   }
 
+
+
+  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>");
+  }
+
+
+
   // readable, raw, pos, type, start/end
   static void writeTokens(JspWriter out, List<Token> tokens, final FieldType ft, boolean verbose, Set<Tok> 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<Integer, List<Tok>> map = new HashMap<Integer, List<Tok>>();
-    boolean needRaw = false;
-    int pos = 0;
+    HashMap<Integer,List<Tok>> map = new HashMap<Integer,List<Tok>>();
+    boolean needRaw=false;
+    int pos=0;
     for (Token t : tokens) {
       if (!t.termText().equals(ft.indexedToReadable(t.termText()))) {
-        needRaw = true;
+        needRaw=true;
       }
 
       pos += t.getPositionIncrement();
       List lst = map.get(pos);
-      if (lst == null) {
+      if (lst==null) {
         lst = new ArrayList(1);
-        map.put(pos, lst);
+        map.put(pos,lst);
       }
-      Tok tok = new Tok(t, pos);
+      Tok tok = new Tok(t,pos);
       lst.add(tok);
     }
 
@@ -228,7 +313,7 @@
     // 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) 
+    //    at java.util.Arrays.sort(Arrays.java:1223)
     Arrays.sort(arr, new Comparator<List<Tok>>() {
       public int compare(List<Tok> toks, List<Tok> toks1) {
         return toks.get(0).pos - toks1.get(0).pos;
@@ -245,21 +330,70 @@
 
     );
 
-   out.println("    <tokens>");
-   for (int i = 0; i < arr.length; i++) {
-     for (Tok tok : arr[i]) {
-       out.print("      <token");
-       out.print(" type=\"" + tok.token.type() + "\"");
-       out.print(" pos=\"" + tok.pos + "\"");
-       out.print(" start=\"" + tok.token.startOffset() + "\"");
-       out.print(" end=\"" + tok.token.endOffset() + "\"");
-       out.print(">");
-       out.print(tok.token.termText());
-       out.println("      </token>");
-     }
-   }
-   out.println("    </tokens>");
-   out.println("  </factory>");
+    out.println("<table width=\"auto\" class=\"analysis\" border=\"1\">");
+
+    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("</table>");
   }
 
 %>