1 | <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
|
---|
2 | pageEncoding="UTF-8"
|
---|
3 | import="org.terrier.querying.*"
|
---|
4 | import="org.terrier.structures.Index"
|
---|
5 | import="org.terrier.structures.MetaIndex"
|
---|
6 | import="org.terrier.matching.ResultSet"
|
---|
7 | import="org.terrier.utility.ApplicationSetup"
|
---|
8 | %>
|
---|
9 | <%!
|
---|
10 |
|
---|
11 | /*
|
---|
12 | * Terrier - Terabyte Retriever
|
---|
13 | * Webpage: http://terrier.org/
|
---|
14 | * Contact: terrier{a.}dcs.gla.ac.uk
|
---|
15 | * University of Glasgow - School of Computing Science
|
---|
16 | * http://www.gla.uk
|
---|
17 | *
|
---|
18 | * The contents of this file are subject to the Mozilla Public License
|
---|
19 | * Version 1.1 (the "License"); you may not use this file except in
|
---|
20 | * compliance with the License. You may obtain a copy of the License at
|
---|
21 | * http://www.mozilla.org/MPL/
|
---|
22 | *
|
---|
23 | * Software distributed under the License is distributed on an "AS IS"
|
---|
24 | * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
---|
25 | * the License for the specific language governing rights and limitations
|
---|
26 | * under the License.
|
---|
27 | *
|
---|
28 | * The Original Code is results.jsp
|
---|
29 | *
|
---|
30 | * The Original Code is Copyright (C) 2004-2011 the University of Glasgow.
|
---|
31 | * All Rights Reserved.
|
---|
32 | *
|
---|
33 | * Contributor(s):
|
---|
34 | * Craig Macdonald <craigm{a.}dcs.gla.ac.uk> (original author)
|
---|
35 | *
|
---|
36 | */
|
---|
37 | static int NUM_RESULTS_PER_PAGE = 10;
|
---|
38 | static int NEAREST_PAGES = 5;
|
---|
39 | static boolean SHOW_NEXT_PREV = true;
|
---|
40 | String defaultMatching = ApplicationSetup.getProperty("terrier.jsp.matching", "Matching");
|
---|
41 | String defaultModel = ApplicationSetup.getProperty("terrier.jsp.model", "PL2");
|
---|
42 |
|
---|
43 | protected static void displayResults(ResultSet rs, int iStart, javax.servlet.jsp.JspWriter out) throws IOException
|
---|
44 | {
|
---|
45 | String[] displayKeys = rs.getMetaKeys();
|
---|
46 | String[][] meta = new String[displayKeys.length][];
|
---|
47 |
|
---|
48 | int parser_idx = 0;
|
---|
49 | int assocfile_idx = 0;
|
---|
50 | int source_idx = 0;
|
---|
51 | int preview_idx = 0;
|
---|
52 |
|
---|
53 | for(int j=0;j<displayKeys.length;j++)
|
---|
54 | {
|
---|
55 | if (displayKeys[j].equals("parser"))
|
---|
56 | {
|
---|
57 | parser_idx = j;
|
---|
58 | }
|
---|
59 | if (displayKeys[j].equals("assocfile"))
|
---|
60 | {
|
---|
61 | assocfile_idx = j;
|
---|
62 | }
|
---|
63 | if (displayKeys[j].equals("source"))
|
---|
64 | {
|
---|
65 | source_idx = j;
|
---|
66 | }
|
---|
67 | if (displayKeys[j].equals("preview"))
|
---|
68 | {
|
---|
69 | preview_idx = j;
|
---|
70 | }
|
---|
71 | meta[j] = rs.getMetaItems(displayKeys[j]);
|
---|
72 | }
|
---|
73 | double[] scores = rs.getScores();
|
---|
74 | for(int i=0;i<rs.getResultSize();i++)
|
---|
75 | {
|
---|
76 | String parser = "";
|
---|
77 |
|
---|
78 | final int rank = iStart + i + 1;
|
---|
79 | out.println("<table value=\""+rank+"\" class=\"result\" style=\"margin-left:auto;margin-right:auto;text-align:left;width:50%\">");
|
---|
80 | out.println("<tr>");
|
---|
81 | out.println("<td style=\"vertical-align:top;width:5%\">"+ rank + ".</td>");
|
---|
82 |
|
---|
83 | out.print("<td style=\"vertical-align:top\">");
|
---|
84 | for(int j=0;j<displayKeys.length;j++)
|
---|
85 | {
|
---|
86 | String field = displayKeys[j];
|
---|
87 | if (!(field.equals("assocfile") || field.equals("parser") || field.equals("preview") || field.equals("source")))
|
---|
88 | {
|
---|
89 | out.print("<span class=\"results_"+field+"\"><b>"+field+":</b> "+meta[j][i]+"</span>");
|
---|
90 | }
|
---|
91 | }
|
---|
92 | out.print("<span class=\"results_score\"><b>Score:</b> "+ scores[i] + "</span>");
|
---|
93 | out.println("</td>");
|
---|
94 |
|
---|
95 | // Image preview
|
---|
96 | if (meta[parser_idx][i].equals("ImageDocument"))
|
---|
97 | {
|
---|
98 | out.print("<td style=\"vertical-align:top\">");
|
---|
99 | 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>");
|
---|
100 | out.println("</td>");
|
---|
101 | }
|
---|
102 |
|
---|
103 | // Video preview
|
---|
104 | if(meta[parser_idx][i].equals("VideoDocument"))
|
---|
105 | {
|
---|
106 | out.print("<td>");
|
---|
107 | out.print("<script src=\"images/flowplayer-3.2.10.min.js\"></script>");
|
---|
108 | out.print("<a style=\"display:block;width:300px;height:240px\" id=\"player\"></a>");
|
---|
109 | out.print("<!-- this will install flowplayer inside previous anchor tag -->");
|
---|
110 | out.print("<script>");
|
---|
111 | out.print("flowplayer('player', 'images/flowplayer-3.2.11.swf', {");
|
---|
112 | out.print(" plugins: {");
|
---|
113 | out.print(" pseudo: { url: 'images/flowplayer.pseudostreaming-3.2.9.swf' }");
|
---|
114 | out.print(" },");
|
---|
115 | out.print(" clip: {");
|
---|
116 | out.print(" autoPlay: false,");
|
---|
117 | out.print(" provider: 'pseudo',");
|
---|
118 | out.print(" url: 'images/assoc/" + meta[assocfile_idx][i] + "/tsv.mp4' }");
|
---|
119 | out.print(" }");
|
---|
120 | out.print(");");
|
---|
121 | out.print("</script>");
|
---|
122 | out.println("</td>");
|
---|
123 | out.println("</tr>");
|
---|
124 | out.println("<tr>");
|
---|
125 | out.println("<td> </td>");
|
---|
126 | out.print("<td colspan=\"2\">");
|
---|
127 | String[] keyframe_images = meta[preview_idx][i].split(",");
|
---|
128 | for (int k = 0; k < keyframe_images.length; k++)
|
---|
129 | {
|
---|
130 | out.print("<img style=\"width:100px\" src=\"images/assoc/" + meta[assocfile_idx][i] + "/" + keyframe_images[k] + "\" />");
|
---|
131 | }
|
---|
132 | out.println("</td>");
|
---|
133 | }
|
---|
134 |
|
---|
135 | out.println("</tr>");
|
---|
136 | out.println("</table>");
|
---|
137 | }
|
---|
138 | }
|
---|
139 |
|
---|
140 | protected static void displayPageNumbers(
|
---|
141 |
|
---|
142 | SearchRequest srq, ResultSet rs,
|
---|
143 | int iStart, javax.servlet.jsp.JspWriter out)
|
---|
144 | throws IOException
|
---|
145 | {
|
---|
146 | String sQuery = srq.getOriginalQuery();
|
---|
147 | String sQuery_URLEncoded = java.net.URLEncoder.encode(sQuery, "UTF-8");
|
---|
148 | int maxResults = Math.min(rs.getExactResultSize(), 1000);//we dont let anyone go deeper than 1000
|
---|
149 | int numPages = maxResults / NUM_RESULTS_PER_PAGE;
|
---|
150 |
|
---|
151 | if (SHOW_NEXT_PREV && iStart > 0)
|
---|
152 | {
|
---|
153 | int prevStart = iStart - NUM_RESULTS_PER_PAGE;
|
---|
154 | if (prevStart < 0)
|
---|
155 | prevStart = 0;
|
---|
156 | out.print("<a href=\"?query="+sQuery_URLEncoded+ "&start="+prevStart+"\">Previous</a> ");
|
---|
157 | }
|
---|
158 |
|
---|
159 | for(int i=0;i<numPages;i++)
|
---|
160 | {
|
---|
161 | int thisStart = (i * NUM_RESULTS_PER_PAGE);
|
---|
162 | if (Math.abs(thisStart - iStart) > NUM_RESULTS_PER_PAGE * NEAREST_PAGES)
|
---|
163 | continue;
|
---|
164 | if (thisStart != iStart)
|
---|
165 | out.print("<a href=\"?query="+sQuery_URLEncoded+ "&start="+ thisStart+"\">"+(i+1)+"</a>");
|
---|
166 | else
|
---|
167 | out.print(i+1);
|
---|
168 | out.print(" ");
|
---|
169 | }
|
---|
170 |
|
---|
171 | if (SHOW_NEXT_PREV)
|
---|
172 | {
|
---|
173 | int nextStart = iStart + NUM_RESULTS_PER_PAGE;
|
---|
174 | if (nextStart < maxResults)
|
---|
175 | out.print("<a href=\"?query="+sQuery_URLEncoded+ "&start="+nextStart+"\">Next</a>");
|
---|
176 | }
|
---|
177 | }
|
---|
178 |
|
---|
179 | %>
|
---|
180 |
|
---|
181 | <%
|
---|
182 |
|
---|
183 | String query = request.getParameter("query");
|
---|
184 | if (query == null || query.length() == 0)
|
---|
185 | response.sendRedirect("./");
|
---|
186 | query = query.trim();
|
---|
187 | if (query == null || query.length() == 0)
|
---|
188 | response.sendRedirect("./");
|
---|
189 | String sStart = request.getParameter("start");
|
---|
190 | int iStart;
|
---|
191 | if (sStart == null || sStart.length() == 0)
|
---|
192 | {
|
---|
193 | sStart = "0";
|
---|
194 | iStart = 0;
|
---|
195 | }
|
---|
196 | else
|
---|
197 | {
|
---|
198 | iStart = Integer.parseInt(sStart);
|
---|
199 | if (iStart > 1000)
|
---|
200 | {
|
---|
201 | iStart = 1000;
|
---|
202 | sStart = "1000";
|
---|
203 | }
|
---|
204 | }
|
---|
205 |
|
---|
206 | Index index = (Index)application.getAttribute("terrier.jsp.index");
|
---|
207 | if (index == null)
|
---|
208 | {
|
---|
209 | index = Index.createIndex();
|
---|
210 | application.setAttribute("terrier.jsp.index", index);
|
---|
211 | }
|
---|
212 | Manager queryingManager = (Manager)application.getAttribute("terrier.jsp.manager");
|
---|
213 | if (queryingManager == null)
|
---|
214 | {
|
---|
215 | queryingManager = new Manager(index);
|
---|
216 | application.setAttribute("terrier.jsp.manager", queryingManager);
|
---|
217 | }
|
---|
218 |
|
---|
219 | SearchRequest srq = queryingManager.newSearchRequest("results.jsp.query", query);
|
---|
220 | srq.setOriginalQuery(query);
|
---|
221 | srq.setControl("start", sStart);
|
---|
222 | srq.setControl("decorate", "on");
|
---|
223 | srq.setControl("end", String.valueOf(iStart + NUM_RESULTS_PER_PAGE -1));
|
---|
224 | srq.addMatchingModel(defaultMatching, defaultModel);
|
---|
225 | queryingManager.runPreProcessing(srq);
|
---|
226 | queryingManager.runMatching(srq);
|
---|
227 | queryingManager.runPostProcessing(srq);
|
---|
228 | queryingManager.runPostFilters(srq);
|
---|
229 | ResultSet rs = srq.getResultSet();
|
---|
230 | int firstDisplayRank = iStart +1;
|
---|
231 | int lastDisplayRank = 1+ Math.min(rs.getExactResultSize() -1, iStart + NUM_RESULTS_PER_PAGE);
|
---|
232 | int possibleRanks = rs.getExactResultSize();
|
---|
233 |
|
---|
234 | %>
|
---|
235 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
---|
236 | <%@page import="java.io.IOException"%>
|
---|
237 | <html>
|
---|
238 | <head>
|
---|
239 | <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
---|
240 | <title>Terrier Search results for <%=query%></title>
|
---|
241 | <link rel="stylesheet" type="text/css" href="style.css" />
|
---|
242 | </head>
|
---|
243 | <body>
|
---|
244 | <a href="/"><img border="0" src="/images/terrier-logo-web.jpg"></a>
|
---|
245 | <form action="results.jsp" id="queryform">
|
---|
246 | <input type="text" size="50" name="query" value="<%=query %>" />
|
---|
247 | <input type="submit" value="Search" / >
|
---|
248 | </form>
|
---|
249 | <div id="summary">
|
---|
250 | Results for <%=query%>, displaying <%=firstDisplayRank%>-<%=lastDisplayRank%> of <%=possibleRanks %>
|
---|
251 | </div>
|
---|
252 | <div id="results">
|
---|
253 | <%
|
---|
254 | displayResults(rs, iStart, out);
|
---|
255 | %>
|
---|
256 | </div>
|
---|
257 | <div id="pages">
|
---|
258 | <%
|
---|
259 | displayPageNumbers(srq, rs, iStart, out);
|
---|
260 | %>
|
---|
261 | </div>
|
---|
262 | <hr width="50%">
|
---|
263 | <div id="poweredby">
|
---|
264 | <a href="http://terrier.org"><img src="/images/terrier-desktop-search.gif" border="0"/> Powered by Terrier</a>
|
---|
265 | </div>
|
---|
266 | </body>
|
---|
267 | </html>
|
---|