Index: gs2-extensions/video-and-audio/trunk/src/opt/Terrier/README.txt
===================================================================
--- gs2-extensions/video-and-audio/trunk/src/opt/Terrier/README.txt	(revision 26190)
+++ gs2-extensions/video-and-audio/trunk/src/opt/Terrier/README.txt	(revision 26191)
@@ -24,5 +24,9 @@
 indexing.simplefilecollection.extensionsparsers=txt:FileDocument, pdf:PDFDocument, html:TaggedDocument,htm:TaggedDocument,xhtml:TaggedDocument,xml:TaggedDocument, jpg:ImageDocument, ts:VideoDocument
 
-4. Build your index including some JPG and TS files.
+4. Overwrite the simple results JSP file in order to support images and video:
 
-5. Test the index in your preferred tool, and marvel at the beautiful image and video metadata (or thumbnails, if you are in a web interface)
+cp <gsdl>/ext/video-and-audio/opt/Terrier/results.jsp <terrier>/src/webapps/simple/results.jsp
+
+5. Build your index including some JPG and TS files.
+
+6. Test the index in your preferred tool, and marvel at the beautiful image and video metadata (or thumbnails, if you are in a web interface)
Index: gs2-extensions/video-and-audio/trunk/src/opt/Terrier/results.jsp
===================================================================
--- gs2-extensions/video-and-audio/trunk/src/opt/Terrier/results.jsp	(revision 26191)
+++ gs2-extensions/video-and-audio/trunk/src/opt/Terrier/results.jsp	(revision 26191)
@@ -0,0 +1,267 @@
+<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
+    pageEncoding="UTF-8"
+    import="org.terrier.querying.*"
+    import="org.terrier.structures.Index"
+    import="org.terrier.structures.MetaIndex"
+    import="org.terrier.matching.ResultSet"
+    import="org.terrier.utility.ApplicationSetup"
+     %>
+<%!
+
+/*
+ * Terrier - Terabyte Retriever
+ * Webpage: http://terrier.org/
+ * Contact: terrier{a.}dcs.gla.ac.uk
+ * University of Glasgow - School of Computing Science
+ * http://www.gla.uk
+ *
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (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.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+ * the License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is results.jsp
+ *
+ * The Original Code is Copyright (C) 2004-2011 the University of Glasgow.
+ * All Rights Reserved.
+ *
+ * Contributor(s):
+ *  Craig Macdonald <craigm{a.}dcs.gla.ac.uk> (original author)
+ *   
+ */
+static int NUM_RESULTS_PER_PAGE = 10;
+static int NEAREST_PAGES = 5;
+static boolean SHOW_NEXT_PREV = true;
+String defaultMatching = ApplicationSetup.getProperty("terrier.jsp.matching", "Matching");
+String defaultModel = ApplicationSetup.getProperty("terrier.jsp.model", "PL2");
+
+protected static void displayResults(ResultSet rs, int iStart, javax.servlet.jsp.JspWriter out) throws IOException
+{
+  String[] displayKeys = rs.getMetaKeys();
+  String[][] meta = new String[displayKeys.length][];
+
+  int parser_idx = 0;
+  int assocfile_idx = 0;
+  int source_idx = 0;
+  int preview_idx = 0;
+
+  for(int j=0;j<displayKeys.length;j++)
+  {
+    if (displayKeys[j].equals("parser"))
+    {
+      parser_idx = j;
+    }
+    if (displayKeys[j].equals("assocfile"))
+    {
+      assocfile_idx = j;
+    }
+    if (displayKeys[j].equals("source"))
+    {
+      source_idx = j;
+    }
+    if (displayKeys[j].equals("preview"))
+    {
+      preview_idx = j;
+    }
+    meta[j] = rs.getMetaItems(displayKeys[j]);
+  }
+  double[] scores = rs.getScores();
+  for(int i=0;i<rs.getResultSize();i++)
+  {
+    String parser = "";
+
+    final int rank = iStart + i + 1;
+    out.println("<table value=\""+rank+"\" class=\"result\" style=\"margin-left:auto;margin-right:auto;text-align:left;width:50%\">");
+    out.println("<tr>");
+    out.println("<td style=\"vertical-align:top;width:5%\">"+ rank + ".</td>");
+
+    out.print("<td style=\"vertical-align:top\">");
+    for(int j=0;j<displayKeys.length;j++)
+    {
+      String field = displayKeys[j];
+      if (!(field.equals("assocfile") || field.equals("parser") || field.equals("preview") || field.equals("source")))
+      {
+        out.print("<span class=\"results_"+field+"\"><b>"+field+":</b> "+meta[j][i]+"</span>");
+      }
+    }
+    out.print("<span class=\"results_score\"><b>Score:</b> "+ scores[i] + "</span>");
+    out.println("</td>");
+
+    // Image preview
+    if (meta[parser_idx][i].equals("ImageDocument"))
+    {
+      out.print("<td style=\"vertical-align:top\">");
+      out.print("<a href=\"images/assoc/" + meta[assocfile_idx][i] + "/" + meta[source_idx][i] + "\"><img src=\"images/assoc/" + meta[assocfile_idx][i] + "/" + meta[preview_idx][i] + "\" /></a>");
+      out.println("</td>");
+    }
+
+    // Video preview
+    if(meta[parser_idx][i].equals("VideoDocument"))
+    {
+      out.print("<td>");
+      out.print("<script src=\"images/flowplayer-3.2.10.min.js\"></script>");
+      out.print("<a style=\"display:block;width:300px;height:240px\" id=\"player\"></a>");
+      out.print("<!-- this will install flowplayer inside previous anchor tag -->");
+      out.print("<script>");
+      out.print("flowplayer('player', 'images/flowplayer-3.2.11.swf', {");
+      out.print("  plugins: {");
+      out.print("    pseudo: { url: 'images/flowplayer.pseudostreaming-3.2.9.swf' }");
+      out.print("  },");
+      out.print("  clip: {");
+      out.print("    autoPlay: false,");
+      out.print("    provider: 'pseudo',");
+      out.print("    url: 'images/assoc/" + meta[assocfile_idx][i] + "/tsv.mp4' }");
+      out.print("  }");
+      out.print(");");
+      out.print("</script>");
+      out.println("</td>");
+      out.println("</tr>");
+      out.println("<tr>");
+      out.println("<td>&nbsp;</td>");
+      out.print("<td colspan=\"2\">");
+      String[] keyframe_images = meta[preview_idx][i].split(",");
+      for (int k = 0; k < keyframe_images.length; k++)
+      {
+        out.print("<img style=\"width:100px\" src=\"images/assoc/" + meta[assocfile_idx][i] + "/" + keyframe_images[k] + "\" />");
+      }
+      out.println("</td>");
+    }
+
+    out.println("</tr>");
+    out.println("</table>");
+  }
+}
+
+protected static void displayPageNumbers(
+		
+		SearchRequest srq, ResultSet rs, 
+		int iStart, javax.servlet.jsp.JspWriter out)
+	throws IOException
+{
+	String sQuery = srq.getOriginalQuery();
+	String sQuery_URLEncoded = java.net.URLEncoder.encode(sQuery, "UTF-8");
+	int maxResults = Math.min(rs.getExactResultSize(), 1000);//we dont let anyone go deeper than 1000
+	int numPages = maxResults / NUM_RESULTS_PER_PAGE; 
+	
+	if (SHOW_NEXT_PREV && iStart > 0)
+	{
+		int prevStart = iStart - NUM_RESULTS_PER_PAGE;
+		if (prevStart < 0)
+			prevStart = 0;
+		out.print("<a href=\"?query="+sQuery_URLEncoded+ "&start="+prevStart+"\">Previous</a> &nbsp;");
+	}
+	
+	for(int i=0;i<numPages;i++)
+	{
+		int thisStart = (i * NUM_RESULTS_PER_PAGE);
+		if (Math.abs(thisStart - iStart) > NUM_RESULTS_PER_PAGE * NEAREST_PAGES)
+			continue;
+		if (thisStart != iStart)
+			out.print("<a href=\"?query="+sQuery_URLEncoded+ "&start="+ thisStart+"\">"+(i+1)+"</a>");
+		else
+			out.print(i+1);
+		out.print("&nbsp;");
+	}
+	
+	if (SHOW_NEXT_PREV)
+	{
+		int nextStart = iStart + NUM_RESULTS_PER_PAGE;
+		if (nextStart < maxResults)
+			out.print("<a href=\"?query="+sQuery_URLEncoded+ "&start="+nextStart+"\">Next</a>");
+	}
+}
+
+%>
+
+<%
+
+String query = request.getParameter("query");
+if (query == null || query.length() == 0)
+	response.sendRedirect("./");
+query = query.trim();
+if (query == null || query.length() == 0)
+	response.sendRedirect("./");
+String sStart = request.getParameter("start");
+int iStart;
+if (sStart == null || sStart.length() == 0)
+{
+	sStart = "0";
+	iStart = 0;
+}
+else
+{
+	iStart = Integer.parseInt(sStart);
+	if (iStart > 1000)
+	{
+		iStart = 1000;
+		sStart = "1000";
+	}
+}
+
+Index index = (Index)application.getAttribute("terrier.jsp.index");
+if (index == null)
+{
+	index = Index.createIndex();
+	application.setAttribute("terrier.jsp.index", index);
+}	
+Manager queryingManager = (Manager)application.getAttribute("terrier.jsp.manager");
+if (queryingManager == null)
+{
+	queryingManager = new Manager(index);
+	application.setAttribute("terrier.jsp.manager", queryingManager);
+}
+
+SearchRequest srq = queryingManager.newSearchRequest("results.jsp.query", query);
+srq.setOriginalQuery(query);
+srq.setControl("start", sStart);
+srq.setControl("decorate", "on");
+srq.setControl("end", String.valueOf(iStart + NUM_RESULTS_PER_PAGE -1));
+srq.addMatchingModel(defaultMatching, defaultModel);
+queryingManager.runPreProcessing(srq);
+queryingManager.runMatching(srq);
+queryingManager.runPostProcessing(srq);
+queryingManager.runPostFilters(srq);
+ResultSet rs = srq.getResultSet();
+int firstDisplayRank = iStart +1;
+int lastDisplayRank = 1+ Math.min(rs.getExactResultSize() -1, iStart + NUM_RESULTS_PER_PAGE);
+int possibleRanks = rs.getExactResultSize();
+
+%>
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<%@page import="java.io.IOException"%>
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+<title>Terrier Search results for <%=query%></title>
+<link rel="stylesheet" type="text/css" href="style.css" />
+</head>
+<body>
+<a href="/"><img border="0" src="/images/terrier-logo-web.jpg"></a>
+<form action="results.jsp" id="queryform">
+<input type="text" size="50" name="query" value="<%=query %>" />
+<input type="submit"  value="Search" / >
+</form>
+<div id="summary">
+Results for <%=query%>, displaying <%=firstDisplayRank%>-<%=lastDisplayRank%> of <%=possibleRanks %>
+</div>
+<div id="results">
+<%
+displayResults(rs, iStart, out);
+%>
+</div>
+<div id="pages">
+<%
+displayPageNumbers(srq, rs, iStart, out);
+%>
+</div>	
+<hr width="50%">
+<div id="poweredby">
+<a href="http://terrier.org"><img src="/images/terrier-desktop-search.gif" border="0"/> Powered by Terrier</a>
+</div>
+</body>
+</html>
