Search in sources :

Example 1 with SuggestSettingsException

use of org.codelibs.fess.suggest.exception.SuggestSettingsException 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();
    }
}
Also used : ThreadUtil(org.codelibs.core.lang.ThreadUtil) Arrays(java.util.Arrays) Constants(org.codelibs.fess.Constants) LocalDateTime(java.time.LocalDateTime) Pair(org.codelibs.core.misc.Pair) SortBuilders(org.opensearch.search.sort.SortBuilders) HashMap(java.util.HashMap) SearchEngineClient(org.codelibs.fess.es.client.SearchEngineClient) BadWordBhv(org.codelibs.fess.es.config.exbhv.BadWordBhv) FieldNames(org.codelibs.fess.suggest.constants.FieldNames) SuggestSettingsException(org.codelibs.fess.suggest.exception.SuggestSettingsException) ArrayList(java.util.ArrayList) SuggestUtil(org.codelibs.fess.suggest.util.SuggestUtil) HashSet(java.util.HashSet) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) StreamUtil.split(org.codelibs.core.stream.StreamUtil.split) BadWord(org.codelibs.fess.es.config.exentity.BadWord) Map(java.util.Map) CombineFunction(org.opensearch.common.lucene.search.function.CombineFunction) ElevateWordBhv(org.codelibs.fess.es.config.exbhv.ElevateWordBhv) SuggestDeleteResponse(org.codelibs.fess.suggest.index.SuggestDeleteResponse) QueryBuilders(org.opensearch.index.query.QueryBuilders) ESSourceReader(org.codelibs.fess.suggest.index.contents.document.ESSourceReader) StreamUtil.stream(org.codelibs.core.stream.StreamUtil.stream) Suggester(org.codelibs.fess.suggest.Suggester) SearchLog(org.codelibs.fess.es.log.exentity.SearchLog) SuggestSettingsBuilder(org.codelibs.fess.suggest.settings.SuggestSettingsBuilder) StringUtil(org.codelibs.core.lang.StringUtil) ScoreFunctionBuilders(org.opensearch.index.query.functionscore.ScoreFunctionBuilders) Set(java.util.Set) ZoneId(java.time.ZoneId) Consumer(java.util.function.Consumer) SuggestSettings(org.codelibs.fess.suggest.settings.SuggestSettings) List(java.util.List) Logger(org.apache.logging.log4j.Logger) SearchLogBhv(org.codelibs.fess.es.log.exbhv.SearchLogBhv) ComponentUtil(org.codelibs.fess.util.ComponentUtil) DateTimeFormatter(java.time.format.DateTimeFormatter) SuggestItem(org.codelibs.fess.suggest.entity.SuggestItem) PostConstruct(javax.annotation.PostConstruct) ElevateWord(org.codelibs.fess.es.config.exentity.ElevateWord) FunctionScoreQueryBuilder(org.opensearch.index.query.functionscore.FunctionScoreQueryBuilder) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) BoolQueryBuilder(org.opensearch.index.query.BoolQueryBuilder) SearchEngineClient(org.codelibs.fess.es.client.SearchEngineClient) SuggestSettingsBuilder(org.codelibs.fess.suggest.settings.SuggestSettingsBuilder) StringUtil(org.codelibs.core.lang.StringUtil) SuggestSettingsException(org.codelibs.fess.suggest.exception.SuggestSettingsException) PostConstruct(javax.annotation.PostConstruct)

Aggregations

LocalDateTime (java.time.LocalDateTime)1 ZoneId (java.time.ZoneId)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Consumer (java.util.function.Consumer)1 PostConstruct (javax.annotation.PostConstruct)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1 StringUtil (org.codelibs.core.lang.StringUtil)1 ThreadUtil (org.codelibs.core.lang.ThreadUtil)1 Pair (org.codelibs.core.misc.Pair)1 StreamUtil.split (org.codelibs.core.stream.StreamUtil.split)1 StreamUtil.stream (org.codelibs.core.stream.StreamUtil.stream)1