Search in sources :

Example 1 with FessEsClient

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();
}
Also used : IndexingHelper(org.codelibs.fess.helper.IndexingHelper) FessEsClient(org.codelibs.fess.es.client.FessEsClient)

Example 2 with FessEsClient

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);
        }
    }
}
Also used : IndexingHelper(org.codelibs.fess.helper.IndexingHelper) FessEsClient(org.codelibs.fess.es.client.FessEsClient)

Example 3 with FessEsClient

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;
    });
}
Also used : ScoreFunctionBuilder(org.elasticsearch.index.query.functionscore.ScoreFunctionBuilder) FessEsClient(org.codelibs.fess.es.client.FessEsClient) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig)

Example 4 with FessEsClient

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();
}
Also used : SystemHelper(org.codelibs.fess.helper.SystemHelper) FessEsClient(org.codelibs.fess.es.client.FessEsClient) PingResponse(org.codelibs.fess.entity.PingResponse) Postbox(org.lastaflute.core.mail.Postbox) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig)

Example 5 with FessEsClient

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() + ".");
    }
}
Also used : DataStoreException(org.codelibs.fess.exception.DataStoreException) SystemHelper(org.codelibs.fess.helper.SystemHelper) IndexingHelper(org.codelibs.fess.helper.IndexingHelper) CrawlingInfoHelper(org.codelibs.fess.helper.CrawlingInfoHelper) FessEsClient(org.codelibs.fess.es.client.FessEsClient) AtomicLong(java.util.concurrent.atomic.AtomicLong) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig)

Aggregations

FessEsClient (org.codelibs.fess.es.client.FessEsClient)5 IndexingHelper (org.codelibs.fess.helper.IndexingHelper)3 FessConfig (org.codelibs.fess.mylasta.direction.FessConfig)3 SystemHelper (org.codelibs.fess.helper.SystemHelper)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 PingResponse (org.codelibs.fess.entity.PingResponse)1 DataStoreException (org.codelibs.fess.exception.DataStoreException)1 CrawlingInfoHelper (org.codelibs.fess.helper.CrawlingInfoHelper)1 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)1 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)1 ScoreFunctionBuilder (org.elasticsearch.index.query.functionscore.ScoreFunctionBuilder)1 Postbox (org.lastaflute.core.mail.Postbox)1