} else {
response.setContentType("text/plain");
}
PrintWriter writer = response.getWriter();
LuceneIndexAdapter adapter = null;
IndexSearcher searcher = null;
try {
String field = this.getParameterValue(request,"field");
String term = this.getParameterValue(request,"term");
String sortBy = this.getParameterValue(request,"sortBy");
String pathInfo = "";
if (request.getPathInfo() != null) {
pathInfo = Val.chkStr(request.getPathInfo().toLowerCase());
if (pathInfo.startsWith("/")) pathInfo = pathInfo.substring(1);
if (pathInfo.endsWith("/")) pathInfo = pathInfo.substring(0,(pathInfo.length() - 1));
//System.err.println(pathInfo);
}
adapter = new LuceneIndexAdapter(context);
searcher = adapter.newSearcher();
IndexReader reader = searcher.getIndexReader();
StatsRequest statsRequest = new StatsRequest(context);
statsRequest.setResponseWriter(writer);
statsRequest.prepare(reader);
statsRequest.setSortBy(sortBy);
statsRequest.setResponseFormat(responseFormat);
if (field.length() > 0) {
int maxRecs = Val.chkInt(this.getParameterValue(request,"max"),-2);
if (maxRecs == -2) {
maxRecs = Val.chkInt(this.getParameterValue(request,"maxrecords"),-1);
}
int minFreq = Val.chkInt(this.getParameterValue(request,"minFrequency"),-1);
int maxFreq = Val.chkInt(this.getParameterValue(request,"maxFrequency"),-1);
SingleFieldStats stats = new SingleFieldStats(field,maxRecs,minFreq,maxFreq);
stats.collectStats(statsRequest,reader);
// } else if (term.length() > 0) {
// SingleTermStats stats = new SingleTermStats(term);
// stats.collectStats(statsRequest,reader);
// } else if (pathInfo.equals("terms")){
// GlobalTermStats stats = new GlobalTermStats();
// stats.collectStats(statsRequest,reader);
} else {
//GlobalFieldStats stats = new GlobalFieldStats();
SummaryStats stats = new SummaryStats();
stats.collectStats(statsRequest,reader);
}
// } catch (Exception ex) {
// response.setContentType("text/plain;charset=UTF-8");
// writer.println("Error getting metadata: " + ex.getMessage());
// LogUtil.getLogger().log(Level.SEVERE, "Error getting metadata", ex);
} finally {
try {
writer.flush();
} catch (Exception ef) {};
try {
if ((adapter != null) && (searcher != null)) {
adapter.closeSearcher(searcher);
}
} catch (Exception ef) {};
}
}