Search in sources :

Example 56 with FessConfig

use of org.codelibs.fess.mylasta.direction.FessConfig in project fess by codelibs.

the class IndexingHelper method getDocumentListByQuery.

protected List<Map<String, Object>> getDocumentListByQuery(final SearchEngineClient searchEngineClient, final QueryBuilder queryBuilder, final String[] fields) {
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    final SearchResponse countResponse = searchEngineClient.prepareSearch(fessConfig.getIndexDocumentUpdateIndex()).setQuery(queryBuilder).setSize(0).execute().actionGet(fessConfig.getIndexSearchTimeout());
    final long numFound = countResponse.getHits().getTotalHits().value;
    return searchEngineClient.getDocumentList(fessConfig.getIndexDocumentUpdateIndex(), requestBuilder -> {
        requestBuilder.setQuery(queryBuilder).setSize((int) numFound);
        if (fields != null) {
            requestBuilder.setFetchSource(fields, null);
        }
        return true;
    });
}
Also used : FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) SearchResponse(org.opensearch.action.search.SearchResponse)

Example 57 with FessConfig

use of org.codelibs.fess.mylasta.direction.FessConfig in project fess by codelibs.

the class IndexingHelper method deleteOldDocuments.

private void deleteOldDocuments(final SearchEngineClient searchEngineClient, final DocList docList) {
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    final List<String> docIdList = new ArrayList<>();
    for (final Map<String, Object> inputDoc : docList) {
        final Object idValue = inputDoc.get(fessConfig.getIndexFieldId());
        if (idValue == null) {
            continue;
        }
        final Object configIdValue = inputDoc.get(fessConfig.getIndexFieldConfigId());
        if (configIdValue == null) {
            continue;
        }
        final QueryBuilder queryBuilder = QueryBuilders.boolQuery().must(QueryBuilders.termQuery(fessConfig.getIndexFieldUrl(), inputDoc.get(fessConfig.getIndexFieldUrl()))).filter(QueryBuilders.termQuery(fessConfig.getIndexFieldConfigId(), configIdValue));
        final List<Map<String, Object>> docs = getDocumentListByQuery(searchEngineClient, queryBuilder, new String[] { fessConfig.getIndexFieldId(), fessConfig.getIndexFieldDocId() });
        for (final Map<String, Object> doc : docs) {
            final Object oldIdValue = doc.get(fessConfig.getIndexFieldId());
            if (!idValue.equals(oldIdValue) && oldIdValue != null) {
                final Object oldDocIdValue = doc.get(fessConfig.getIndexFieldDocId());
                if (oldDocIdValue != null) {
                    docIdList.add(oldDocIdValue.toString());
                }
            }
        }
        if (logger.isDebugEnabled()) {
            logger.debug("{} => {}", queryBuilder, docs);
        }
    }
    if (!docIdList.isEmpty()) {
        searchEngineClient.deleteByQuery(fessConfig.getIndexDocumentUpdateIndex(), QueryBuilders.idsQuery().addIds(docIdList.stream().toArray(n -> new String[n])));
    }
}
Also used : ArrayList(java.util.ArrayList) QueryBuilder(org.opensearch.index.query.QueryBuilder) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) Map(java.util.Map)

Example 58 with FessConfig

use of org.codelibs.fess.mylasta.direction.FessConfig in project fess by codelibs.

the class LanguageHelper method createScript.

public Script createScript(final Map<String, Object> doc, final String code) {
    final StringBuilder buf = new StringBuilder(100);
    buf.append(code);
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    final String language = DocumentUtil.getValue(doc, fessConfig.getIndexFieldLang(), String.class);
    if (StringUtil.isNotBlank(language)) {
        for (final String f : langFields) {
            buf.append(";ctx._source.").append(f).append('_').append(language).append("=ctx._source.").append(f);
        }
    }
    if (logger.isDebugEnabled()) {
        logger.debug("update script: {}", buf);
    }
    return new Script(buf.toString());
}
Also used : Script(org.opensearch.script.Script) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig)

Example 59 with FessConfig

use of org.codelibs.fess.mylasta.direction.FessConfig in project fess by codelibs.

the class LanguageHelper method getReindexScriptSource.

public String getReindexScriptSource() {
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    final String langField = fessConfig.getIndexFieldLang();
    final String code = Arrays.stream(langFields).map(s -> "ctx._source['" + s + "_'+ctx._source." + langField + "]=ctx._source." + s).collect(Collectors.joining(";"));
    if (logger.isDebugEnabled()) {
        logger.debug("reindex script: {}", code);
    }
    return "if(ctx._source." + langField + "!=null){" + code + "}";
}
Also used : Arrays(java.util.Arrays) DocumentUtil(org.codelibs.fess.util.DocumentUtil) Script(org.opensearch.script.Script) StringUtil(org.codelibs.core.lang.StringUtil) LanguageDetector(org.apache.tika.language.detect.LanguageDetector) Collectors(java.util.stream.Collectors) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) Logger(org.apache.logging.log4j.Logger) ComponentUtil(org.codelibs.fess.util.ComponentUtil) Map(java.util.Map) PostConstruct(javax.annotation.PostConstruct) LogManager(org.apache.logging.log4j.LogManager) LanguageResult(org.apache.tika.language.detect.LanguageResult) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig)

Example 60 with FessConfig

use of org.codelibs.fess.mylasta.direction.FessConfig in project fess by codelibs.

the class LanguageHelper method init.

@PostConstruct
public void init() {
    if (logger.isDebugEnabled()) {
        logger.debug("Initialize {}", this.getClass().getSimpleName());
    }
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    langFields = fessConfig.getIndexerLanguageFieldsAsArray();
    supportedLanguages = fessConfig.getSupportedLanguagesAsArray();
    maxTextLength = fessConfig.getIndexerLanguageDetectLengthAsInteger();
}
Also used : FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) PostConstruct(javax.annotation.PostConstruct)

Aggregations

FessConfig (org.codelibs.fess.mylasta.direction.FessConfig)176 ArrayList (java.util.ArrayList)60 Map (java.util.Map)54 HashMap (java.util.HashMap)48 StringUtil (org.codelibs.core.lang.StringUtil)42 ComponentUtil (org.codelibs.fess.util.ComponentUtil)42 List (java.util.List)37 Constants (org.codelibs.fess.Constants)36 LogManager (org.apache.logging.log4j.LogManager)30 Logger (org.apache.logging.log4j.Logger)30 StreamUtil.stream (org.codelibs.core.stream.StreamUtil.stream)28 PostConstruct (javax.annotation.PostConstruct)27 IOException (java.io.IOException)24 SystemHelper (org.codelibs.fess.helper.SystemHelper)19 File (java.io.File)18 Collectors (java.util.stream.Collectors)18 SearchEngineClient (org.codelibs.fess.es.client.SearchEngineClient)18 FessSystemException (org.codelibs.fess.exception.FessSystemException)17 Collections (java.util.Collections)15 DocumentUtil (org.codelibs.fess.util.DocumentUtil)15