@SuppressWarnings({ "unchecked", "deprecation" })
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
JSONObject result = new JSONObject();
SearchEngine engine = new SearchEngine();
boolean valid = false;
String freetext = req.getParameter(PARAM_FREETEXT);
String def = req.getParameter(PARAM_DEF);
String symbol = req.getParameter(PARAM_SYMBOL);
String path = req.getParameter(PARAM_PATH);
String hist = req.getParameter(PARAM_HIST);
if (freetext != null) {
freetext = URLDecoder.decode(freetext);
engine.setFreetext(freetext);
valid = true;
result.put(PARAM_FREETEXT, freetext);
}
if (def != null) {
def = URLDecoder.decode(def);
engine.setDefinition(def);
valid = true;
result.put(PARAM_DEF, def);
}
if (symbol != null) {
symbol = URLDecoder.decode(symbol);
engine.setSymbol(symbol);
valid = true;
result.put(PARAM_SYMBOL, symbol);
}
if (path != null) {
path = URLDecoder.decode(path);
engine.setFile(path);
valid = true;
result.put(PARAM_PATH, path);
}
if (hist != null) {
hist = URLDecoder.decode(hist);
engine.setHistory(hist);
valid = true;
result.put(PARAM_HIST, hist);
}
if (valid) {
long start = System.currentTimeMillis();
int numResults = engine.search();
int maxResults = MAX_RESULTS;
String maxResultsParam = req.getParameter(PARAM_MAXRESULTS);
if (maxResultsParam != null) {
try {
maxResults = Integer.parseInt(maxResultsParam);
result.put(PARAM_MAXRESULTS, maxResults);
} catch (NumberFormatException ex) {
}
}
List<Hit> results = new ArrayList<Hit>(maxResults);
engine.results(0,
numResults > maxResults ? maxResults : numResults, results);
JSONArray resultsArray = new JSONArray();
for (Hit hit : results) {
JSONObject hitJson = new JSONObject();
hitJson.put(ATTRIBUTE_DIRECTORY,