use of org.codelibs.fess.suggest.settings.SuggestSettingsBuilder in project fess by codelibs.
the class SuggestHelper method init.
@PostConstruct
public void init() {
if (logger.isDebugEnabled()) {
logger.debug("Initialize {}", this.getClass().getSimpleName());
}
fessConfig = ComponentUtil.getFessConfig();
split(fessConfig.getSuggestFieldContents(), ",").of(stream -> stream.filter(StringUtil::isNotBlank).forEach(contentFieldNameSet::add));
split(fessConfig.getSuggestFieldTags(), ",").of(stream -> stream.filter(StringUtil::isNotBlank).forEach(tagFieldNameSet::add));
split(fessConfig.getSuggestFieldRoles(), ",").of(stream -> stream.filter(StringUtil::isNotBlank).forEach(roleFieldNameSet::add));
contentFieldList = Arrays.asList(stream(fessConfig.getSuggestFieldContents()).get(stream -> stream.toArray(n -> new String[n])));
final SearchEngineClient searchEngineClient = ComponentUtil.getSearchEngineClient();
searchEngineClient.admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet(fessConfig.getIndexHealthTimeout());
final SuggestSettingsBuilder settingsBuilder = SuggestSettings.builder();
settingsBuilder.addInitialSettings("elasticsearch.type", fessConfig.getFesenType());
settingsBuilder.bulkTimeout(fessConfig.getIndexBulkTimeout());
settingsBuilder.clusterTimeout(fessConfig.getIndexHealthTimeout());
settingsBuilder.indexTimeout(fessConfig.getIndexIndexTimeout());
settingsBuilder.indicesTimeout(fessConfig.getIndexIndicesTimeout());
settingsBuilder.searchTimeout(fessConfig.getIndexSearchTimeout());
suggester = Suggester.builder().settings(settingsBuilder).build(searchEngineClient, fessConfig.getIndexDocumentSuggestIndex());
suggester.settings().array().delete(SuggestSettings.DefaultKeys.SUPPORTED_FIELDS);
split(fessConfig.getSuggestFieldIndexContents(), ",").of(stream -> stream.filter(StringUtil::isNotBlank).forEach(field -> {
try {
suggester.settings().array().add(SuggestSettings.DefaultKeys.SUPPORTED_FIELDS, field);
} catch (final SuggestSettingsException e) {
logger.warn("Failed to add {}", field, e);
}
}));
suggester.createIndexIfNothing();
if (ComponentUtil.hasPopularWordHelper()) {
popularWordHelper = ComponentUtil.getPopularWordHelper();
}
}
Aggregations