Skip to content

Commit 0660813

Browse files
committed
Added new field “type” to the web search form.
The field is a single selection containing file types with user readable descriptions. It is mapped to the field “fileType” in Lucene.
1 parent cd1fe74 commit 0660813

File tree

4 files changed

+72
-2
lines changed

4 files changed

+72
-2
lines changed

src/org/opensolaris/opengrok/web/PageConfig.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,12 @@ public List<SortOrder> getSortOrder() {
461461
*/
462462
public QueryBuilder getQueryBuilder() {
463463
if (queryBuilder == null) {
464-
queryBuilder = new QueryBuilder().setFreetext(req.getParameter("q")).setDefs(req.getParameter("defs")).setRefs(req.getParameter("refs")).setPath(req.getParameter("path")).setHist(req.getParameter("hist"));
464+
queryBuilder = new QueryBuilder().setFreetext(req.getParameter("q"))
465+
.setDefs(req.getParameter("defs"))
466+
.setRefs(req.getParameter("refs"))
467+
.setPath(req.getParameter("path"))
468+
.setHist(req.getParameter("hist"))
469+
.setFileType(req.getParameter("type"));
465470

466471
// This is for backward compatibility with links created by OpenGrok
467472
// 0.8.x and earlier. We used to concatenate the entire query into a

src/org/opensolaris/opengrok/web/SearchHelper.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@
2929
import java.util.ArrayList;
3030
import java.util.Arrays;
3131
import java.util.List;
32+
import java.util.Map;
33+
import java.util.Set;
3234
import java.util.SortedSet;
35+
import java.util.TreeMap;
3336
import java.util.concurrent.ExecutorService;
3437
import java.util.concurrent.Executors;
3538
import java.util.logging.Level;
@@ -161,13 +164,54 @@ public class SearchHelper {
161164
* history context usually created via {@link #prepareSummary()}.
162165
*/
163166
public HistoryContext historyContext;
167+
/**
168+
* User readable description for file types.
169+
* Only those listed in fileTypeDescription will be shown
170+
* to the user.
171+
*/
172+
private static final Map<String, String> fileTypeDescription;
164173
/**
165174
* Default query parse error message prefix
166175
*/
167176
public static final String PARSE_ERROR_MSG = "Unable to parse your query: ";
168177
private ExecutorService executor = null;
169178
private static final Logger log = Logger.getLogger(SearchHelper.class.getName());
170179

180+
static {
181+
fileTypeDescription = new TreeMap<>();
182+
183+
fileTypeDescription.put("xml", "XML");
184+
fileTypeDescription.put("troff", "Troff");
185+
fileTypeDescription.put("elf", "ELF");
186+
fileTypeDescription.put("javaclass", "Java class");
187+
fileTypeDescription.put("image", "Image file");
188+
fileTypeDescription.put("c", "C");
189+
fileTypeDescription.put("csharp", "C#");
190+
fileTypeDescription.put("vb", "Visual Basic");
191+
fileTypeDescription.put("cxx", "C++");
192+
fileTypeDescription.put("sh", "Shell script");
193+
fileTypeDescription.put("java", "Java");
194+
fileTypeDescription.put("javascript", "JavaScript");
195+
fileTypeDescription.put("python", "Python");
196+
fileTypeDescription.put("perl", "Perl");
197+
fileTypeDescription.put("php", "PHP");
198+
fileTypeDescription.put("lisp", "Lisp");
199+
fileTypeDescription.put("tcl", "Tcl");
200+
fileTypeDescription.put("scala", "Scala");
201+
fileTypeDescription.put("sql", "SQL");
202+
fileTypeDescription.put("plsql", "PL/SQL");
203+
fileTypeDescription.put("fortran", "Fortran");
204+
}
205+
206+
/**
207+
* Returns a set of file type descriptions to be used for a
208+
* search form.
209+
* @return Set of tuples with file type and description.
210+
*/
211+
public static Set<Map.Entry<String, String>> getFileTypeDescirptions() {
212+
return fileTypeDescription.entrySet();
213+
}
214+
171215
/**
172216
* Create the searcher to use wrt. to currently set parameters and the given
173217
* projects. Does not produce any {@link #redirect} link. It also does

web/menu.jspf

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ Use is subject to license terms.
2323

2424
Portions Copyright 2011 Jens Elkner.
2525

26-
--%><%@page import="
26+
--%><%@page import="org.opensolaris.opengrok.web.SearchHelper"%>
27+
<%@page import="java.util.Map"%>
28+
<%@page import="
2729
java.util.SortedSet,
2830
java.util.TreeMap,
2931
java.util.Map.Entry,
@@ -101,6 +103,24 @@ org.opensolaris.opengrok.web.Util"
101103
<td><input class="q" tabindex="5" name="hist" id="hist" value="<%=
102104
Util.formQuoteEscape(queryParams.getHist()) %>"/></td>
103105
</tr>
106+
<tr>
107+
<td><label for="s5">Type</label></td>
108+
<td><select class="q" tabindex="6" name="type" id="type"><%
109+
String selection = queryParams.getFileType();
110+
%>
111+
<option value="">Any</option><%
112+
for (Map.Entry<String, String> d : SearchHelper.getFileTypeDescirptions()) {
113+
%>
114+
<option value="<%= d.getKey() %>"<%
115+
if (d.getKey().equals(selection)) {
116+
%> selected="selected"<%
117+
}
118+
%>><%= Util.formQuoteEscape(d.getValue()) %></option><%
119+
}
120+
%>
121+
</select>
122+
</td>
123+
</tr>
104124
<%-- TODO Bug 11749
105125
<%
106126
if (projects.size() != 0) {

web/search.jsp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ include file="projects.jspf"
4545
Util.appendQuery(url, "refs", qb.getRefs());
4646
Util.appendQuery(url, "path", qb.getPath());
4747
Util.appendQuery(url, "hist", qb.getHist());
48+
Util.appendQuery(url, "type", qb.getFileType());
4849
}
4950
if (sh.projects != null && sh.projects.size() != 0) {
5051
Util.appendQuery(url, "project", cfg.getRequestedProjectsAsString());

0 commit comments

Comments
 (0)