Search in sources :

Example 11 with SearchEngineClient

use of org.codelibs.fess.es.client.SearchEngineClient in project fess by codelibs.

the class BaseThumbnailGenerator method process.

protected boolean process(final String id, final BiPredicate<String, String> consumer) {
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    final SearchEngineClient searchEngineClient = ComponentUtil.getSearchEngineClient();
    final IndexingHelper indexingHelper = ComponentUtil.getIndexingHelper();
    try {
        final Map<String, Object> doc = indexingHelper.getDocument(searchEngineClient, id, new String[] { fessConfig.getIndexFieldThumbnail(), fessConfig.getIndexFieldConfigId() });
        if (doc == null) {
            throw new ThumbnailGenerationException("Document is not found: " + id);
        }
        final String url = DocumentUtil.getValue(doc, fessConfig.getIndexFieldThumbnail(), String.class);
        if (StringUtil.isBlank(url)) {
            throw new ThumbnailGenerationException("Invalid thumbnail: " + url);
        }
        final String configId = DocumentUtil.getValue(doc, fessConfig.getIndexFieldConfigId(), String.class);
        if (configId == null || configId.length() < 2) {
            throw new ThumbnailGenerationException("Invalid configId: " + configId);
        }
        return consumer.test(configId, url);
    } catch (final ThumbnailGenerationException e) {
        if (e.getCause() == null) {
            logger.debug(e.getMessage());
        } else {
            logger.warn("Failed to process {}", id, e);
        }
    } catch (final Exception e) {
        logger.warn("Failed to process {}", id, e);
    }
    return false;
}
Also used : IndexingHelper(org.codelibs.fess.helper.IndexingHelper) ThumbnailGenerationException(org.codelibs.fess.exception.ThumbnailGenerationException) SearchEngineClient(org.codelibs.fess.es.client.SearchEngineClient) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) CrawlingAccessException(org.codelibs.fess.crawler.exception.CrawlingAccessException) ThumbnailGenerationException(org.codelibs.fess.exception.ThumbnailGenerationException)

Example 12 with SearchEngineClient

use of org.codelibs.fess.es.client.SearchEngineClient in project fess by codelibs.

the class SystemMonitorTarget method appendFesenStats.

private void appendFesenStats(final StringBuilder buf) {
    String stats = null;
    try {
        final SearchEngineClient esClient = ComponentUtil.getSearchEngineClient();
        final NodesStatsResponse response = esClient.admin().cluster().prepareNodesStats().all().execute().actionGet(10000L);
        final XContentBuilder builder = XContentFactory.jsonBuilder();
        builder.startObject();
        response.toXContent(builder, ToXContent.EMPTY_PARAMS);
        builder.endObject();
        builder.flush();
        try (OutputStream out = builder.getOutputStream()) {
            stats = ((ByteArrayOutputStream) out).toString(Constants.UTF_8);
        }
    } catch (final Exception e) {
        logger.debug("Failed to access Fesen stats.", e);
    }
    buf.append("\"elasticsearch\":").append(stats).append(',');
}
Also used : NodesStatsResponse(org.opensearch.action.admin.cluster.node.stats.NodesStatsResponse) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) SearchEngineClient(org.codelibs.fess.es.client.SearchEngineClient) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder)

Example 13 with SearchEngineClient

use of org.codelibs.fess.es.client.SearchEngineClient in project fess by codelibs.

the class FileListIndexUpdateCallbackImpl method deleteDocuments.

protected void deleteDocuments() {
    final SearchEngineClient searchEngineClient = ComponentUtil.getSearchEngineClient();
    final IndexingHelper indexingHelper = ComponentUtil.getIndexingHelper();
    for (final String url : deleteUrlList) {
        indexingHelper.deleteDocumentByUrl(searchEngineClient, url);
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Deleted {}", deleteUrlList);
    }
    deleteUrlList.clear();
}
Also used : IndexingHelper(org.codelibs.fess.helper.IndexingHelper) SearchEngineClient(org.codelibs.fess.es.client.SearchEngineClient)

Example 14 with SearchEngineClient

use of org.codelibs.fess.es.client.SearchEngineClient in project fess by codelibs.

the class IndexUpdateCallbackImpl method store.

/* (non-Javadoc)
     * @see org.codelibs.fess.ds.callback.IndexUpdateCallback#store(java.util.Map)
     */
@Override
public void store(final Map<String, String> paramMap, final Map<String, Object> dataMap) {
    final SystemHelper systemHelper = ComponentUtil.getSystemHelper();
    systemHelper.calibrateCpuLoad();
    final long startTime = System.currentTimeMillis();
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    final SearchEngineClient searchEngineClient = ComponentUtil.getSearchEngineClient();
    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());
    }
    final Set<String> matchedLabelSet = ComponentUtil.getLabelTypeHelper().getMatchedLabelValueSet(url);
    if (!matchedLabelSet.isEmpty()) {
        final Set<String> newLabelSet = new HashSet<>();
        final String[] oldLabels = DocumentUtil.getValue(dataMap, fessConfig.getIndexFieldLabel(), String[].class);
        StreamUtil.stream(oldLabels).of(stream -> stream.forEach(newLabelSet::add));
        matchedLabelSet.stream().forEach(newLabelSet::add);
        dataMap.put(fessConfig.getIndexFieldLabel(), newLabelSet.toArray(new String[newLabelSet.size()]));
    }
    if (!dataMap.containsKey(fessConfig.getIndexFieldDocId())) {
        dataMap.put(fessConfig.getIndexFieldDocId(), systemHelper.generateDocId(dataMap));
    }
    ComponentUtil.getLanguageHelper().updateDocument(dataMap);
    synchronized (docList) {
        docList.add(ingest(paramMap, dataMap));
        final long contentSize = indexingHelper.calculateDocumentSize(dataMap);
        docList.addContentSize(contentSize);
        final long processingTime = System.currentTimeMillis() - startTime;
        docList.addProcessingTime(processingTime);
        if (logger.isDebugEnabled()) {
            logger.debug("Added the document({}, {}ms). The number of a document cache is {}.", MemoryUtil.byteCountToDisplaySize(contentSize), processingTime, docList.size());
        }
        if (docList.getContentSize() >= maxDocumentRequestSize || docList.size() >= maxDocumentCacheSize) {
            indexingHelper.sendDocuments(searchEngineClient, docList);
        }
        executeTime += processingTime;
    }
    documentSize.getAndIncrement();
    if (logger.isDebugEnabled()) {
        logger.debug("The number of an added document is {}.", documentSize.get());
    }
}
Also used : DataStoreException(org.codelibs.fess.exception.DataStoreException) SearchEngineClient(org.codelibs.fess.es.client.SearchEngineClient) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) SystemHelper(org.codelibs.fess.helper.SystemHelper) IndexingHelper(org.codelibs.fess.helper.IndexingHelper) CrawlingInfoHelper(org.codelibs.fess.helper.CrawlingInfoHelper) HashSet(java.util.HashSet)

Example 15 with SearchEngineClient

use of org.codelibs.fess.es.client.SearchEngineClient in project fess by codelibs.

the class PingSearchEngineJob method execute.

public String execute() {
    final SearchEngineClient searchEngineClient = ComponentUtil.getSearchEngineClient();
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    final SystemHelper systemHelper = ComponentUtil.getSystemHelper();
    final StringBuilder resultBuf = new StringBuilder();
    final PingResponse ping = searchEngineClient.ping();
    final int status = ping.getStatus();
    if (systemHelper.isChangedClusterState(status)) {
        if (fessConfig.hasNotification()) {
            final String toStrs = fessConfig.getNotificationTo();
            final String[] toAddresses;
            if (StringUtil.isNotBlank(toStrs)) {
                toAddresses = toStrs.split(",");
            } else {
                toAddresses = StringUtil.EMPTY_STRINGS;
            }
            final Postbox postbox = ComponentUtil.getComponent(Postbox.class);
            try {
                final NotificationHelper notificationHelper = ComponentUtil.getNotificationHelper();
                SMailCallbackContext.setPreparedMessageHookOnThread(notificationHelper::send);
                EsStatusPostcard.droppedInto(postbox, postcard -> {
                    postcard.setFrom(fessConfig.getMailFromAddress(), fessConfig.getMailFromName());
                    postcard.addReplyTo(fessConfig.getMailReturnPath());
                    if (toAddresses.length > 0) {
                        stream(toAddresses).of(stream -> stream.map(String::trim).forEach(address -> {
                            postcard.addTo(address);
                        }));
                    } else {
                        postcard.addTo(fessConfig.getMailFromAddress());
                        postcard.dryrun();
                    }
                    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);
            } finally {
                SMailCallbackContext.clearPreparedMessageHookOnThread();
            }
        }
        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();
}
Also used : StreamUtil.stream(org.codelibs.core.stream.StreamUtil.stream) SMailCallbackContext(org.dbflute.mail.send.hook.SMailCallbackContext) NotificationHelper(org.codelibs.fess.helper.NotificationHelper) StringUtil(org.codelibs.core.lang.StringUtil) SearchEngineClient(org.codelibs.fess.es.client.SearchEngineClient) EsStatusPostcard(org.codelibs.fess.mylasta.mail.EsStatusPostcard) Postbox(org.lastaflute.core.mail.Postbox) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) Logger(org.apache.logging.log4j.Logger) PingResponse(org.codelibs.fess.entity.PingResponse) ComponentUtil(org.codelibs.fess.util.ComponentUtil) SystemHelper(org.codelibs.fess.helper.SystemHelper) LogManager(org.apache.logging.log4j.LogManager) SearchEngineClient(org.codelibs.fess.es.client.SearchEngineClient) PingResponse(org.codelibs.fess.entity.PingResponse) Postbox(org.lastaflute.core.mail.Postbox) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) SystemHelper(org.codelibs.fess.helper.SystemHelper) NotificationHelper(org.codelibs.fess.helper.NotificationHelper)

Aggregations

SearchEngineClient (org.codelibs.fess.es.client.SearchEngineClient)18 FessConfig (org.codelibs.fess.mylasta.direction.FessConfig)12 IndexingHelper (org.codelibs.fess.helper.IndexingHelper)7 LogManager (org.apache.logging.log4j.LogManager)4 Logger (org.apache.logging.log4j.Logger)4 StringUtil (org.codelibs.core.lang.StringUtil)4 SystemHelper (org.codelibs.fess.helper.SystemHelper)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 List (java.util.List)3 Map (java.util.Map)3 StreamUtil.stream (org.codelibs.core.stream.StreamUtil.stream)3 ComponentUtil (org.codelibs.fess.util.ComponentUtil)3 Set (java.util.Set)2 Consumer (java.util.function.Consumer)2 PostConstruct (javax.annotation.PostConstruct)2 ThreadUtil (org.codelibs.core.lang.ThreadUtil)2 Constants (org.codelibs.fess.Constants)2 ContainerNotAvailableException (org.codelibs.fess.exception.ContainerNotAvailableException)2