use of org.codelibs.fess.es.client.FessEsClient in project fess by codelibs.
the class FileListIndexUpdateCallbackImpl method deleteDocuments.
protected void deleteDocuments() {
final FessEsClient fessEsClient = ComponentUtil.getFessEsClient();
final IndexingHelper indexingHelper = ComponentUtil.getIndexingHelper();
for (final String url : deleteUrlList) {
indexingHelper.deleteDocumentByUrl(fessEsClient, url);
}
if (logger.isDebugEnabled()) {
logger.debug("Deleted " + deleteUrlList);
}
deleteUrlList.clear();
}
use of org.codelibs.fess.es.client.FessEsClient in project fess by codelibs.
the class IndexUpdateCallbackImpl method commit.
@Override
public void commit() {
synchronized (docList) {
if (!docList.isEmpty()) {
final IndexingHelper indexingHelper = ComponentUtil.getIndexingHelper();
final FessEsClient fessEsClient = ComponentUtil.getFessEsClient();
indexingHelper.sendDocuments(fessEsClient, docList);
}
}
}
use of org.codelibs.fess.es.client.FessEsClient in project fess by codelibs.
the class KeyMatchHelper method getBoostedDocumentList.
public List<Map<String, Object>> getBoostedDocumentList(final String term, final int size) {
final FessEsClient fessEsClient = ComponentUtil.getFessEsClient();
final Pair<QueryBuilder, ScoreFunctionBuilder> pair = keyMatchQueryMap.get(toLowerCase(term));
if (pair == null) {
return Collections.emptyList();
}
final FessConfig fessConfig = ComponentUtil.getFessConfig();
return fessEsClient.getDocumentList(fessConfig.getIndexDocumentSearchIndex(), fessConfig.getIndexDocumentType(), searchRequestBuilder -> {
searchRequestBuilder.setPreference(Constants.SEARCH_PREFERENCE_PRIMARY).setQuery(pair.getFirst()).setSize(size);
return true;
});
}
use of org.codelibs.fess.es.client.FessEsClient in project fess by codelibs.
the class PingEsJob method execute.
public String execute() {
final FessEsClient fessEsClient = ComponentUtil.getFessEsClient();
final FessConfig fessConfig = ComponentUtil.getFessConfig();
final SystemHelper systemHelper = ComponentUtil.getSystemHelper();
final StringBuilder resultBuf = new StringBuilder();
final String notificationTo = fessConfig.getNotificationTo();
final PingResponse ping = fessEsClient.ping();
final int status = ping.getStatus();
if (systemHelper.isChangedClusterState(status)) {
if (StringUtil.isNotBlank(notificationTo)) {
final Postbox postbox = ComponentUtil.getComponent(Postbox.class);
try {
EsStatusPostcard.droppedInto(postbox, postcard -> {
postcard.setFrom(fessConfig.getMailFromAddress(), fessConfig.getMailFromName());
postcard.addReplyTo(fessConfig.getMailReturnPath());
postcard.addTo(notificationTo);
postcard.setHostname(systemHelper.getHostname());
postcard.setClustername(ping.getClusterName());
postcard.setClusterstatus(ping.getClusterStatus());
});
} catch (final Exception e) {
logger.warn("Failed to send a test mail.", e);
}
}
resultBuf.append("Status of ").append(ping.getClusterName()).append(" is changed to ").append(ping.getClusterStatus()).append('.');
} else {
if (status == 0) {
resultBuf.append(ping.getClusterName()).append(" is alive.");
} else {
resultBuf.append(ping.getClusterName()).append(" is not available.");
}
}
return resultBuf.toString();
}
use of org.codelibs.fess.es.client.FessEsClient in project fess by codelibs.
the class IndexUpdateCallbackImpl method store.
/* (non-Javadoc)
* @see org.codelibs.fess.ds.impl.IndexUpdateCallback#store(java.util.Map)
*/
@Override
public void store(final Map<String, String> paramMap, final Map<String, Object> dataMap) {
final long startTime = System.currentTimeMillis();
final FessConfig fessConfig = ComponentUtil.getFessConfig();
final FessEsClient fessEsClient = ComponentUtil.getFessEsClient();
if (logger.isDebugEnabled()) {
logger.debug("Adding " + dataMap);
}
// required check
final Object urlObj = dataMap.get(fessConfig.getIndexFieldUrl());
if (urlObj == null) {
throw new DataStoreException("url is null. dataMap=" + dataMap);
}
final IndexingHelper indexingHelper = ComponentUtil.getIndexingHelper();
final CrawlingInfoHelper crawlingInfoHelper = ComponentUtil.getCrawlingInfoHelper();
dataMap.put(fessConfig.getIndexFieldId(), crawlingInfoHelper.generateId(dataMap));
final String url = dataMap.get(fessConfig.getIndexFieldUrl()).toString();
if (fessConfig.getIndexerClickCountEnabledAsBoolean()) {
addClickCountField(dataMap, url, fessConfig.getIndexFieldClickCount());
}
if (fessConfig.getIndexerFavoriteCountEnabledAsBoolean()) {
addFavoriteCountField(dataMap, url, fessConfig.getIndexFieldFavoriteCount());
}
if (!dataMap.containsKey(fessConfig.getIndexFieldDocId())) {
final SystemHelper systemHelper = ComponentUtil.getSystemHelper();
dataMap.put(fessConfig.getIndexFieldDocId(), systemHelper.generateDocId(dataMap));
}
synchronized (docList) {
docList.add(dataMap);
if (logger.isDebugEnabled()) {
logger.debug("Added the document. " + "The number of a document cache is " + docList.size() + ".");
}
final Long contentLength = DocumentUtil.getValue(dataMap, fessConfig.getIndexFieldContentLength(), Long.class);
if (contentLength != null) {
docList.addContentSize(contentLength.longValue());
if (docList.getContentSize() >= maxDocumentRequestSize) {
indexingHelper.sendDocuments(fessEsClient, docList);
}
} else if (docList.size() >= fessConfig.getIndexerDataMaxDocumentCacheSizeAsInteger().intValue()) {
indexingHelper.sendDocuments(fessEsClient, docList);
}
executeTime += System.currentTimeMillis() - startTime;
}
documentSize.getAndIncrement();
if (logger.isDebugEnabled()) {
logger.debug("The number of an added document is " + documentSize.get() + ".");
}
}
Aggregations