Index: /trunk/gsdl3/src/java/org/greenstone/gsdl3/service/Visualizer.java
===================================================================
--- /trunk/gsdl3/src/java/org/greenstone/gsdl3/service/Visualizer.java	(revision 8346)
+++ /trunk/gsdl3/src/java/org/greenstone/gsdl3/service/Visualizer.java	(revision 8347)
@@ -32,4 +32,5 @@
 import vishnu.server.Search.*;
 import vishnu.datablock.*;
+import vishnu.util.Base64;
 
 public class Visualizer
@@ -70,4 +71,5 @@
 	app_info += "<PARAM NAME='collection'   VALUE='" + this.cluster_name + "'/>";
 	app_info += "<PARAM NAME='engine'   VALUE='GSDLEngine' />";
+	// add view info if appropriate
 	app_info += "The visualization applet.</"+GSXML.APPLET_ELEM+">";
 	   
@@ -134,8 +136,8 @@
 	if (type.equals("search")) {
 
-	    Element cluster_results = this.doc.createElement("cluster");
-	    vis_data.appendChild(cluster_results);
-	    Element description_results = this.doc.createElement("descriptions");
-	    vis_data.appendChild(description_results);
+	    //Element cluster_results = this.doc.createElement("cluster");
+	    //vis_data.appendChild(cluster_results);
+	    //Element description_results = this.doc.createElement("descriptions");
+	    //vis_data.appendChild(description_results);
 
 	    String query = (String)params.get("q");
@@ -149,4 +151,24 @@
 	    descriptions = engine.getDocDescriptions();
 	    
+	    DataBlock db = generateDataBlock(collection_home, null, doc_nums, descriptions);
+	    System.err.println("got back data, now converting to string");
+	    try {
+		results = Base64.encodeObject(db);
+	    } catch (Exception e) {
+		System.err.println("trying to base64 encode the datablock, but exception happened: "+e);
+	    }
+	    System.err.println("after converting to string");
+// 	    // serialise the data block
+// 	    try {
+// 		ByteArrayOutputStream baos = new ByteArrayOutputStream();
+// 		ObjectOutputStream oos = new ObjectOutputStream(baos);
+// 		oos.writeObject(db);
+// 		oos.close();
+		
+// 		//results = baos.toString("UTF-8");
+// 		results = Base64.encode(baos.toByteArray());
+// 	    } catch (Exception e) {
+// 		System.err.println("Visualizer serialise data block error: "+e);
+// 	    }
 	    //System.err.println("num docs = "+doc_nums.size());
 	    //Cluster c = new Cluster();
@@ -156,11 +178,12 @@
 
 	    Text t = this.doc.createTextNode(results);
-	    cluster_results.appendChild(t);
-
-	    for (int i=0; i<descriptions.size(); i++) {
-		String d = (String)descriptions.get(i);
-		Element de = GSXML.createTextElement(this.doc, "desc", d);
-		description_results.appendChild(de);
-	    }
+	    vis_data.appendChild(t);
+
+// 	    for (int i=0; i<descriptions.size(); i++) {
+// 		String d = (String)descriptions.get(i);
+// 		Element de = GSXML.createTextElement(this.doc, "desc", d);
+// 		description_results.appendChild(de);
+// 	    }
+	    System.err.println("end of search");
 	} else if (type.equals("fetch")) {
 	    String docNum = (String)params.get("d");
@@ -176,7 +199,79 @@
 	    return result;
 	}
+	System.err.println("returning result");
+	return result;
+    }
+
+    private DataBlock generateDataBlock(String collection_home, String view, Vector docNums, Vector descriptions) {
+
+	if (docNums.size()==0) {
+	    return null;
+	}
+	DataBlock data = new DataBlock();
+
+	CKServer ck_server = new CKServer(collection_home, view);
 	
-	return result;
-    }
+	/**** set data fields one by one and pass one what ever gets assembled ****/
+		
+	try{
+	    
+	    ck_server.setDescriptions(descriptions);
+	    
+	    /**** get candidate keywords ****/
+	    
+	    String[] keywords = ck_server.computeKeywords(docNums);
+	    
+	    data.words = keywords;
+	    
+	    
+	    /**** get sparse document * keyword matrix ****/
+	    
+	    SparseMatrix matrix = ck_server.getSparseMatrix(docNums);
+	    
+	    data.matrix = matrix;
+	    
+	    
+	    /**** get document indices, this is a subset of the original ****/
+	    /**** those without keywords are excluded                    ****/
+	    
+	    int[] docs = ck_server.getHitDocuments();
+	    
+	    data.docs = docs;
+	    
+	    
+	    String[] desc = ck_server.getHitDescriptions();
+	    
+	    data.descriptions = desc;
+	    
+	    
+	    /**** get 10 or so clusters ****/
+	    
+	    Vector[] clusters = ck_server.getClusters();
+	    
+	    data.clusters = clusters;
+	    
+	    
+	    double[][] centroids = ck_server.getCentroids();
+	    
+	    
+	    /**** send their centroids through sammon mapping ****/
+	    
+	    Point2D[] sammon = ck_server.getSammonMap(centroids);
+	    
+	    System.err.println("Num descriptions: " + descriptions.size());
+	    System.err.println("Num docs: " + docs.length);
+	    System.err.println("Num desc: " + desc.length);
+	    
+	    data.sammon = sammon;
+	    System.err.println("end of try in generatedatablock");
+	} catch (Exception e) {
+	    System.err.println("VisServlet: computing clustering Error: "+e);
+	    e.printStackTrace();
+	}
+	ck_server = null;
+	System.err.println("returning data");
+	return data;
+    }
+
 }
 
