Search in sources :

Example 1 with SearchEngineClient

use of org.codelibs.fess.es.client.SearchEngineClient in project fess by codelibs.

the class AdminUpgradeAction method upgradeFrom13_16.

private void upgradeFrom13_16() {
    final String[] configIndices = { // 
    "fess_config.access_token", // 
    "fess_config.bad_word", // 
    "fess_config.boost_document_rule", // 
    "fess_config.crawling_info", // 
    "fess_config.crawling_info_param", // 
    "fess_config.data_config", // 
    "fess_config.duplicate_host", // 
    "fess_config.elevate_word", // 
    "fess_config.elevate_word_to_label", // 
    "fess_config.failure_url", // 
    "fess_config.file_authentication", // 
    "fess_config.file_config", // 
    "fess_config.job_log", // 
    "fess_config.key_match", // 
    "fess_config.label_type", // 
    "fess_config.path_mapping", // 
    "fess_config.related_content", // 
    "fess_config.related_query", // 
    "fess_config.request_header", // 
    "fess_config.role_type", // 
    "fess_config.scheduled_job", // 
    "fess_config.thumbnail_queue", // 
    "fess_config.web_authentication", // 
    "fess_config.web_config", // 
    "fess_user.group", // 
    "fess_user.role", // 
    "fess_user.user", // 
    "configsync" };
    final String[] crawlerIndices = { // 
    ".crawler.data", // 
    ".crawler.filter", // 
    ".crawler.queue" };
    final SearchEngineClient client = ComponentUtil.getSearchEngineClient();
    for (final String index : configIndices) {
        final String oldIndex = "." + index;
        if (client.existsIndex(oldIndex) && client.existsIndex(index)) {
            logger.info("Copying from {} to {}", oldIndex, index);
            if (!client.reindex(oldIndex, index, false)) {
                logger.warn("Failed to copy from {} to {}", oldIndex, index);
            }
        } else if (logger.isDebugEnabled()) {
            if (!client.existsIndex(oldIndex)) {
                logger.debug("{} does not exist.", oldIndex);
            }
            if (!client.existsIndex(index)) {
                logger.debug("{} does not exist.", index);
            }
        }
    }
    for (final String index : crawlerIndices) {
        if (client.existsIndex(index)) {
            if (client.deleteIndex(index)) {
                logger.warn("Deleted {}.", index);
            } else {
                logger.warn("Failed to delete {}.", index);
            }
        } else if (logger.isDebugEnabled()) {
            logger.debug("{} does not exist.", index);
        }
    }
}
Also used : SearchEngineClient(org.codelibs.fess.es.client.SearchEngineClient)

Example 2 with SearchEngineClient

use of org.codelibs.fess.es.client.SearchEngineClient in project fess by codelibs.

the class JsonApiManager method processPingRequest.

protected void processPingRequest(final HttpServletRequest request, final HttpServletResponse response, final FilterChain chain) {
    final SearchEngineClient searchEngineClient = ComponentUtil.getSearchEngineClient();
    int status;
    Exception err = null;
    try {
        final PingResponse pingResponse = searchEngineClient.ping();
        status = pingResponse.getStatus();
        writeJsonResponse(status, "\"message\":" + pingResponse.getMessage());
    } catch (final Exception e) {
        status = 9;
        err = e;
        if (logger.isDebugEnabled()) {
            logger.debug("Failed to process a ping request.", e);
        }
        writeJsonResponse(status, null, err);
    }
}
Also used : SearchEngineClient(org.codelibs.fess.es.client.SearchEngineClient) PingResponse(org.codelibs.fess.entity.PingResponse) IORuntimeException(org.codelibs.core.exception.IORuntimeException) ServletException(javax.servlet.ServletException) WebApiException(org.codelibs.fess.exception.WebApiException) IOException(java.io.IOException)

Example 3 with SearchEngineClient

use of org.codelibs.fess.es.client.SearchEngineClient in project fess by codelibs.

the class FileListIndexUpdateCallbackImpl method deleteDocument.

protected boolean deleteDocument(final Map<String, String> paramMap, final Map<String, Object> dataMap) {
    if (logger.isDebugEnabled()) {
        logger.debug("Deleting {}", dataMap);
    }
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    // required check
    if (!dataMap.containsKey(fessConfig.getIndexFieldUrl()) || dataMap.get(fessConfig.getIndexFieldUrl()) == null) {
        logger.warn("Could not delete a doc. Invalid data: {}", dataMap);
        return false;
    }
    synchronized (indexUpdateCallback) {
        final long maxAccessCount = getMaxAccessCount(paramMap, dataMap);
        final String url = dataMap.get(fessConfig.getIndexFieldUrl()).toString();
        if (maxAccessCount != 1L) {
            final SearchEngineClient searchEngineClient = ComponentUtil.getSearchEngineClient();
            final IndexingHelper indexingHelper = ComponentUtil.getIndexingHelper();
            final long count = indexingHelper.deleteDocumentByQuery(searchEngineClient, QueryBuilders.prefixQuery(fessConfig.getIndexFieldUrl(), url));
            if (logger.isDebugEnabled()) {
                logger.debug("Deleted {} docs for {}*", count, url);
            }
        } else {
            deleteUrlList.add(url);
            if (deleteUrlList.size() >= maxDeleteDocumentCacheSize) {
                deleteDocuments();
            }
        }
    }
    return true;
}
Also used : IndexingHelper(org.codelibs.fess.helper.IndexingHelper) SearchEngineClient(org.codelibs.fess.es.client.SearchEngineClient) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig)

Example 4 with SearchEngineClient

use of org.codelibs.fess.es.client.SearchEngineClient in project fess by codelibs.

the class IndexUpdateCallbackImpl method commit.

@Override
public void commit() {
    synchronized (docList) {
        if (!docList.isEmpty()) {
            final IndexingHelper indexingHelper = ComponentUtil.getIndexingHelper();
            final SearchEngineClient searchEngineClient = ComponentUtil.getSearchEngineClient();
            indexingHelper.sendDocuments(searchEngineClient, docList);
        }
    }
}
Also used : IndexingHelper(org.codelibs.fess.helper.IndexingHelper) SearchEngineClient(org.codelibs.fess.es.client.SearchEngineClient)

Example 5 with SearchEngineClient

use of org.codelibs.fess.es.client.SearchEngineClient 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

SearchEngineClient (org.codelibs.fess.es.client.SearchEngineClient)18 FessConfig (org.codelibs.fess.mylasta.direction.FessConfig)12 IndexingHelper (org.codelibs.fess.helper.IndexingHelper)7 LogManager (org.apache.logging.log4j.LogManager)4 Logger (org.apache.logging.log4j.Logger)4 StringUtil (org.codelibs.core.lang.StringUtil)4 SystemHelper (org.codelibs.fess.helper.SystemHelper)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 List (java.util.List)3 Map (java.util.Map)3 StreamUtil.stream (org.codelibs.core.stream.StreamUtil.stream)3 ComponentUtil (org.codelibs.fess.util.ComponentUtil)3 Set (java.util.Set)2 Consumer (java.util.function.Consumer)2 PostConstruct (javax.annotation.PostConstruct)2 ThreadUtil (org.codelibs.core.lang.ThreadUtil)2 Constants (org.codelibs.fess.Constants)2 ContainerNotAvailableException (org.codelibs.fess.exception.ContainerNotAvailableException)2