Search in sources :

Example 1 with IndexUpdateCallback

use of org.codelibs.fess.ds.IndexUpdateCallback in project fess by codelibs.

the class AbstractDataStoreImpl method store.

@Override
public void store(final DataConfig config, final IndexUpdateCallback callback, final Map<String, String> initParamMap) {
    final Map<String, String> configParamMap = config.getHandlerParameterMap();
    final Map<String, String> configScriptMap = config.getHandlerScriptMap();
    final CrawlingInfoHelper crawlingInfoHelper = ComponentUtil.getCrawlingInfoHelper();
    final SystemHelper systemHelper = ComponentUtil.getSystemHelper();
    final Date documentExpires = crawlingInfoHelper.getDocumentExpires(config);
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    initParamMap.putAll(configParamMap);
    final Map<String, String> paramMap = initParamMap;
    // default values
    final Map<String, Object> defaultDataMap = new HashMap<>();
    // cid
    final String configId = config.getConfigId();
    if (configId != null) {
        defaultDataMap.put(fessConfig.getIndexFieldConfigId(), configId);
    }
    //  expires
    if (documentExpires != null) {
        defaultDataMap.put(fessConfig.getIndexFieldExpires(), documentExpires);
    }
    // segment
    defaultDataMap.put(fessConfig.getIndexFieldSegment(), initParamMap.get(Constants.SESSION_ID));
    // created
    defaultDataMap.put(fessConfig.getIndexFieldCreated(), systemHelper.getCurrentTime());
    // boost
    defaultDataMap.put(fessConfig.getIndexFieldBoost(), config.getBoost().toString());
    // label: labelType
    final List<String> labelTypeList = new ArrayList<>();
    for (final String labelType : config.getLabelTypeValues()) {
        labelTypeList.add(labelType);
    }
    defaultDataMap.put(fessConfig.getIndexFieldLabel(), labelTypeList);
    // role: roleType
    final List<String> roleTypeList = new ArrayList<>();
    stream(config.getPermissions()).of(stream -> stream.forEach(p -> roleTypeList.add(p)));
    defaultDataMap.put(fessConfig.getIndexFieldRole(), roleTypeList);
    // mimetype
    defaultDataMap.put(fessConfig.getIndexFieldMimetype(), mimeType);
    // title
    // content
    // cache
    // digest
    // host
    // site
    // url
    // anchor
    // content_length
    // last_modified
    // id
    storeData(config, callback, paramMap, configScriptMap, defaultDataMap);
}
Also used : DataConfig(org.codelibs.fess.es.config.exentity.DataConfig) Constants(org.codelibs.fess.Constants) StreamUtil.stream(org.codelibs.core.stream.StreamUtil.stream) Logger(org.slf4j.Logger) Date(java.util.Date) StringUtil(org.codelibs.core.lang.StringUtil) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) IndexUpdateCallback(org.codelibs.fess.ds.IndexUpdateCallback) ArrayList(java.util.ArrayList) DataStore(org.codelibs.fess.ds.DataStore) List(java.util.List) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) ComponentUtil(org.codelibs.fess.util.ComponentUtil) CrawlingInfoHelper(org.codelibs.fess.helper.CrawlingInfoHelper) SystemHelper(org.codelibs.fess.helper.SystemHelper) GroovyUtil(org.codelibs.fess.util.GroovyUtil) Map(java.util.Map) SystemHelper(org.codelibs.fess.helper.SystemHelper) HashMap(java.util.HashMap) CrawlingInfoHelper(org.codelibs.fess.helper.CrawlingInfoHelper) ArrayList(java.util.ArrayList) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) Date(java.util.Date)

Example 2 with IndexUpdateCallback

use of org.codelibs.fess.ds.IndexUpdateCallback in project fess by codelibs.

the class EsDataStoreImpl 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) {
    final String hostsStr = paramMap.get(HOSTS);
    if (StringUtil.isBlank(hostsStr)) {
        logger.info("hosts is empty.");
        return;
    }
    final long readInterval = getReadInterval(paramMap);
    final Settings settings = Settings.builder().put(paramMap.entrySet().stream().filter(e -> e.getKey().startsWith(SETTINGS_PREFIX)).collect(Collectors.toMap(e -> e.getKey().replaceFirst("^settings\\.", StringUtil.EMPTY), e -> e.getValue()))).build();
    logger.info("Connecting to " + hostsStr + " with [" + settings.toDelimitedString(',') + "]");
    final InetSocketTransportAddress[] addresses = split(hostsStr, ",").get(stream -> stream.map(h -> {
        final String[] values = h.trim().split(":");
        try {
            if (values.length == 1) {
                return new InetSocketTransportAddress(InetAddress.getByName(values[0]), 9300);
            } else if (values.length == 2) {
                return new InetSocketTransportAddress(InetAddress.getByName(values[0]), Integer.parseInt(values[1]));
            }
        } catch (final Exception e) {
            logger.warn("Failed to parse address: " + h, e);
        }
        return null;
    }).filter(v -> v != null).toArray(n -> new InetSocketTransportAddress[n]));
    try (PreBuiltTransportClient client = new PreBuiltTransportClient(settings)) {
        client.addTransportAddresses(addresses);
        processData(dataConfig, callback, paramMap, scriptMap, defaultDataMap, readInterval, client);
    }
}
Also used : CrawlingAccessException(org.codelibs.fess.crawler.exception.CrawlingAccessException) Constants(org.codelibs.fess.Constants) MultipleCrawlingAccessException(org.codelibs.fess.crawler.exception.MultipleCrawlingAccessException) SearchHits(org.elasticsearch.search.SearchHits) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) IndexUpdateCallback(org.codelibs.fess.ds.IndexUpdateCallback) QueryBuilders(org.elasticsearch.index.query.QueryBuilders) InetAddress(java.net.InetAddress) LinkedHashMap(java.util.LinkedHashMap) StreamUtil.split(org.codelibs.core.stream.StreamUtil.split) Settings(org.elasticsearch.common.settings.Settings) Map(java.util.Map) SearchResponse(org.elasticsearch.action.search.SearchResponse) DataConfig(org.codelibs.fess.es.config.exentity.DataConfig) SearchHit(org.elasticsearch.search.SearchHit) DataStoreCrawlingException(org.codelibs.fess.exception.DataStoreCrawlingException) Logger(org.slf4j.Logger) InetSocketTransportAddress(org.elasticsearch.common.transport.InetSocketTransportAddress) Client(org.elasticsearch.client.Client) StringUtil(org.codelibs.core.lang.StringUtil) BulkResponse(org.elasticsearch.action.bulk.BulkResponse) DataStoreException(org.codelibs.fess.exception.DataStoreException) PreBuiltTransportClient(org.elasticsearch.transport.client.PreBuiltTransportClient) Collectors(java.util.stream.Collectors) ComponentUtil(org.codelibs.fess.util.ComponentUtil) SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) FailureUrlService(org.codelibs.fess.app.service.FailureUrlService) BulkRequestBuilder(org.elasticsearch.action.bulk.BulkRequestBuilder) PreBuiltTransportClient(org.elasticsearch.transport.client.PreBuiltTransportClient) InetSocketTransportAddress(org.elasticsearch.common.transport.InetSocketTransportAddress) Settings(org.elasticsearch.common.settings.Settings) CrawlingAccessException(org.codelibs.fess.crawler.exception.CrawlingAccessException) MultipleCrawlingAccessException(org.codelibs.fess.crawler.exception.MultipleCrawlingAccessException) DataStoreCrawlingException(org.codelibs.fess.exception.DataStoreCrawlingException) DataStoreException(org.codelibs.fess.exception.DataStoreException)

Aggregations

HashMap (java.util.HashMap)2 Map (java.util.Map)2 StringUtil (org.codelibs.core.lang.StringUtil)2 Constants (org.codelibs.fess.Constants)2 IndexUpdateCallback (org.codelibs.fess.ds.IndexUpdateCallback)2 DataConfig (org.codelibs.fess.es.config.exentity.DataConfig)2 ComponentUtil (org.codelibs.fess.util.ComponentUtil)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 InetAddress (java.net.InetAddress)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 StreamUtil.split (org.codelibs.core.stream.StreamUtil.split)1 StreamUtil.stream (org.codelibs.core.stream.StreamUtil.stream)1 FailureUrlService (org.codelibs.fess.app.service.FailureUrlService)1 CrawlingAccessException (org.codelibs.fess.crawler.exception.CrawlingAccessException)1 MultipleCrawlingAccessException (org.codelibs.fess.crawler.exception.MultipleCrawlingAccessException)1