use of org.codelibs.fess.helper.LabelTypeHelper in project fess by codelibs.
the class UpdateLabelJob method execute.
public String execute() {
final SearchEngineClient searchEngineClient = ComponentUtil.getSearchEngineClient();
final FessConfig fessConfig = ComponentUtil.getFessConfig();
final LabelTypeHelper labelTypeHelper = ComponentUtil.getLabelTypeHelper();
final LanguageHelper languageHelper = ComponentUtil.getLanguageHelper();
final StringBuilder resultBuf = new StringBuilder();
try {
final long count = searchEngineClient.updateByQuery(fessConfig.getIndexDocumentUpdateIndex(), option -> {
if (queryBuilder != null) {
option.setQuery(queryBuilder);
}
return option.setFetchSource(new String[] { fessConfig.getIndexFieldUrl(), fessConfig.getIndexFieldLang() }, null);
}, (builder, hit) -> {
try {
final Map<String, Object> doc = hit.getSourceAsMap();
final String url = DocumentUtil.getValue(doc, fessConfig.getIndexFieldUrl(), String.class);
if (StringUtil.isNotBlank(url)) {
final Set<String> labelSet = labelTypeHelper.getMatchedLabelValueSet(url);
final Script script = languageHelper.createScript(doc, "ctx._source." + fessConfig.getIndexFieldLabel() + "=new String[]{" + labelSet.stream().map(s -> "\"" + s + "\"").collect(Collectors.joining(",")) + "}");
return builder.setScript(script);
}
} catch (final Exception e) {
logger.warn("Failed to process {}", hit, e);
}
return null;
});
resultBuf.append(count).append(" docs").append("\n");
} catch (final Exception e) {
logger.error("Could not update labels.", e);
resultBuf.append(e.getMessage()).append("\n");
}
return resultBuf.toString();
}
Aggregations