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);
}
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);
}
}
Aggregations