use of org.codelibs.fess.es.client.SearchEngineClient 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();
}
use of org.codelibs.fess.es.client.SearchEngineClient in project fess by codelibs.
the class PurgeDocJob method execute.
public String execute() {
final SearchEngineClient searchEngineClient = ComponentUtil.getSearchEngineClient();
final FessConfig fessConfig = ComponentUtil.getFessConfig();
final StringBuilder resultBuf = new StringBuilder();
// clean up
final QueryBuilder queryBuilder = QueryBuilders.rangeQuery(fessConfig.getIndexFieldExpires()).to("now");
try {
searchEngineClient.deleteByQuery(fessConfig.getIndexDocumentUpdateIndex(), queryBuilder);
} catch (final Exception e) {
logger.error("Could not delete expired documents: {}", queryBuilder.toString(), e);
resultBuf.append(e.getMessage()).append("\n");
}
return resultBuf.toString();
}
use of org.codelibs.fess.es.client.SearchEngineClient in project fess by codelibs.
the class AdminSearchlistAction method getDoc.
public static OptionalEntity<Map<String, Object>> getDoc(final CreateForm form) {
final SystemHelper systemHelper = ComponentUtil.getSystemHelper();
final FessConfig fessConfig = ComponentUtil.getFessConfig();
final SearchEngineClient searchEngineClient = ComponentUtil.getSearchEngineClient();
switch(form.crudMode) {
case CrudMode.CREATE:
final Map<String, Object> entity = new HashMap<>();
entity.put(fessConfig.getIndexFieldDocId(), systemHelper.generateDocId(entity));
return OptionalEntity.of(entity);
case CrudMode.EDIT:
final String docId;
if (form.doc != null) {
docId = (String) form.doc.get(fessConfig.getIndexFieldDocId());
} else {
docId = null;
}
if (StringUtil.isNotBlank(docId)) {
return searchEngineClient.getDocument(fessConfig.getIndexDocumentUpdateIndex(), builder -> {
builder.setQuery(QueryBuilders.termQuery(fessConfig.getIndexFieldDocId(), docId));
return true;
});
}
break;
default:
break;
}
return OptionalEntity.empty();
}
Aggregations