1818 */
1919
2020 /*
21- * Copyright (c) 2014, 2016 Oracle and/or its affiliates. All rights reserved.
21+ * Copyright (c) 2014, 2017 Oracle and/or its affiliates. All rights reserved.
2222 */
2323package org .opensolaris .opengrok .web ;
2424
@@ -47,6 +47,7 @@ public class JSONSearchServlet extends HttpServlet {
4747 private static final String PARAM_PATH = "path" ;
4848 private static final String PARAM_HIST = "hist" ;
4949 private static final String PARAM_MAXRESULTS = "maxresults" ;
50+ private static final String PARAM_PROJECT = "project" ;
5051 private static final String ATTRIBUTE_DIRECTORY = "directory" ;
5152 private static final String ATTRIBUTE_FILENAME = "filename" ;
5253 private static final String ATTRIBUTE_LINENO = "lineno" ;
@@ -70,6 +71,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
7071 String symbol = req .getParameter (PARAM_SYMBOL );
7172 String path = req .getParameter (PARAM_PATH );
7273 String hist = req .getParameter (PARAM_HIST );
74+ String projects [] = req .getParameterValues (PARAM_PROJECT );
7375
7476 if (freetext != null ) {
7577 freetext = URLDecoder .decode (freetext );
@@ -112,7 +114,12 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
112114
113115 try {
114116 long start = System .currentTimeMillis ();
115- int numResults = engine .search (req );
117+ int numResults ;
118+ if (projects == null || projects .length == 0 ) {
119+ numResults = engine .search (req );
120+ } else {
121+ numResults = engine .search (req , projects );
122+ }
116123 int maxResults = MAX_RESULTS ;
117124 String maxResultsParam = req .getParameter (PARAM_MAXRESULTS );
118125 if (maxResultsParam != null ) {
@@ -146,7 +153,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
146153 result .put (ATTRIBUTE_RESULTS , resultsArray );
147154
148155
149-
156+ resp . setContentType ( "application/json" );
150157 resp .getWriter ().write (result .toString ());
151158 } finally {
152159 engine .destroy ();
0 commit comments