Search in sources :

Example 6 with DataStoreException

use of org.codelibs.fess.exception.DataStoreException 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)

Example 7 with DataStoreException

use of org.codelibs.fess.exception.DataStoreException in project fess by codelibs.

the class EsListDataStoreImpl method storeData.

@Override
protected void storeData(final DataConfig dataConfig, final IndexUpdateCallback callback, final Map<String, String> paramMap, final Map<String, String> scriptMap, final Map<String, Object> defaultDataMap) {
    int nThreads = 1;
    if (paramMap.containsKey(Constants.NUM_OF_THREADS)) {
        try {
            nThreads = Integer.parseInt(paramMap.get(Constants.NUM_OF_THREADS));
        } catch (final NumberFormatException e) {
            logger.warn(Constants.NUM_OF_THREADS + " is not int value.", e);
        }
    }
    final CrawlerClientFactory crawlerClientFactory = ComponentUtil.getCrawlerClientFactory();
    dataConfig.initializeClientFactory(crawlerClientFactory);
    try {
        final FileListIndexUpdateCallbackImpl fileListIndexUpdateCallback = new FileListIndexUpdateCallbackImpl(callback, crawlerClientFactory, nThreads);
        super.storeData(dataConfig, fileListIndexUpdateCallback, paramMap, scriptMap, defaultDataMap);
        fileListIndexUpdateCallback.commit();
    } catch (final Exception e) {
        throw new DataStoreException(e);
    }
}
Also used : DataStoreException(org.codelibs.fess.exception.DataStoreException) CrawlerClientFactory(org.codelibs.fess.crawler.client.CrawlerClientFactory) DataStoreException(org.codelibs.fess.exception.DataStoreException)

Aggregations

DataStoreException (org.codelibs.fess.exception.DataStoreException)7 HashMap (java.util.HashMap)4 Map (java.util.Map)4 FailureUrlService (org.codelibs.fess.app.service.FailureUrlService)4 CrawlingAccessException (org.codelibs.fess.crawler.exception.CrawlingAccessException)4 MultipleCrawlingAccessException (org.codelibs.fess.crawler.exception.MultipleCrawlingAccessException)4 DataStoreCrawlingException (org.codelibs.fess.exception.DataStoreCrawlingException)4 LinkedHashMap (java.util.LinkedHashMap)3 CsvReader (com.orangesignal.csv.CsvReader)2 BufferedReader (java.io.BufferedReader)2 FileInputStream (java.io.FileInputStream)2 InputStreamReader (java.io.InputStreamReader)2 CrawlerClientFactory (org.codelibs.fess.crawler.client.CrawlerClientFactory)2 CsvConfig (com.orangesignal.csv.CsvConfig)1 File (java.io.File)1 Connection (java.sql.Connection)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Statement (java.sql.Statement)1 ArrayList (java.util.ArrayList)1