use of org.codelibs.fess.helper.PopularWordHelper in project fess by codelibs.
the class JsonApiManager method processPopularWordRequest.
protected void processPopularWordRequest(final HttpServletRequest request, final HttpServletResponse response, final FilterChain chain) {
if (!ComponentUtil.getFessConfig().isWebApiPopularWord()) {
writeJsonResponse(9, null, "Unsupported operation.");
return;
}
final String seed = request.getParameter("seed");
final List<String> tagList = new ArrayList<>();
final String[] tags = request.getParameterValues("labels");
if (tags != null) {
tagList.addAll(Arrays.asList(tags));
}
final String key = ComponentUtil.getVirtualHostHelper().getVirtualHostKey();
if (StringUtil.isNotBlank(key)) {
tagList.add(key);
}
final String[] fields = request.getParameterValues("fields");
// TODO
final String[] excludes = StringUtil.EMPTY_STRINGS;
final PopularWordHelper popularWordHelper = ComponentUtil.getPopularWordHelper();
int status = 0;
Exception err = null;
// TODO replace response stream
final StringBuilder buf = new StringBuilder(255);
try {
final List<String> popularWordList = popularWordHelper.getWordList(SearchRequestType.JSON, seed, tagList.toArray(new String[tagList.size()]), null, fields, excludes);
buf.append("\"result\":[");
boolean first1 = true;
for (final String word : popularWordList) {
if (!first1) {
buf.append(',');
} else {
first1 = false;
}
buf.append(escapeJson(word));
}
buf.append(']');
} catch (final Exception e) {
if (e instanceof WebApiException) {
status = ((WebApiException) e).getStatusCode();
} else {
status = 1;
}
err = e;
if (logger.isDebugEnabled()) {
logger.debug("Failed to process a popularWord request.", e);
}
}
writeJsonResponse(status, buf.toString(), err);
}
Aggregations