SenateResponse sr = Application.getLucene().search(term, start, pageSize, sort, sortOrder);
ApiHelper.buildSearchResultList(sr);
if (format.equals("json")) {
response.setContentType("application/json");
new Api1JsonConverter().write(sr, response.getOutputStream());
}
else if (format.equals("jsonp")) {
String callback = request.getParameter("callback");
if (callback != null && callback != "") {
PrintWriter out = response.getWriter();
response.setContentType("application/javascript");
out.write(callback+"("+new Api1JsonConverter().toString(sr)+");");
}
else {
throw new ApiRequestException("callback parameter required for jsonp queries.");
}
}