Search in sources :

Example 6 with LabelTypeHelper

use of org.codelibs.fess.helper.LabelTypeHelper in project fess by codelibs.

the class UpdateLabelJob method execute.

public String execute() {
    final SearchEngineClient searchEngineClient = ComponentUtil.getSearchEngineClient();
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    final LabelTypeHelper labelTypeHelper = ComponentUtil.getLabelTypeHelper();
    final LanguageHelper languageHelper = ComponentUtil.getLanguageHelper();
    final StringBuilder resultBuf = new StringBuilder();
    try {
        final long count = searchEngineClient.updateByQuery(fessConfig.getIndexDocumentUpdateIndex(), option -> {
            if (queryBuilder != null) {
                option.setQuery(queryBuilder);
            }
            return option.setFetchSource(new String[] { fessConfig.getIndexFieldUrl(), fessConfig.getIndexFieldLang() }, null);
        }, (builder, hit) -> {
            try {
                final Map<String, Object> doc = hit.getSourceAsMap();
                final String url = DocumentUtil.getValue(doc, fessConfig.getIndexFieldUrl(), String.class);
                if (StringUtil.isNotBlank(url)) {
                    final Set<String> labelSet = labelTypeHelper.getMatchedLabelValueSet(url);
                    final Script script = languageHelper.createScript(doc, "ctx._source." + fessConfig.getIndexFieldLabel() + "=new String[]{" + labelSet.stream().map(s -> "\"" + s + "\"").collect(Collectors.joining(",")) + "}");
                    return builder.setScript(script);
                }
            } catch (final Exception e) {
                logger.warn("Failed to process {}", hit, e);
            }
            return null;
        });
        resultBuf.append(count).append(" docs").append("\n");
    } catch (final Exception e) {
        logger.error("Could not update labels.", e);
        resultBuf.append(e.getMessage()).append("\n");
    }
    return resultBuf.toString();
}
Also used : Script(org.opensearch.script.Script) LanguageHelper(org.codelibs.fess.helper.LanguageHelper) SearchEngineClient(org.codelibs.fess.es.client.SearchEngineClient) LabelTypeHelper(org.codelibs.fess.helper.LabelTypeHelper) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig)

Aggregations

LabelTypeHelper (org.codelibs.fess.helper.LabelTypeHelper)6 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Set (java.util.Set)2 SerializeUtil (org.codelibs.core.io.SerializeUtil)2 StringUtil (org.codelibs.core.lang.StringUtil)2 StreamUtil.stream (org.codelibs.core.stream.StreamUtil.stream)2 Constants (org.codelibs.fess.Constants)2 AccessResultData (org.codelibs.fess.crawler.entity.AccessResultData)2 ResponseData (org.codelibs.fess.crawler.entity.ResponseData)2 ResultData (org.codelibs.fess.crawler.entity.ResultData)2 UrlQueue (org.codelibs.fess.crawler.entity.UrlQueue)2 CrawlerSystemException (org.codelibs.fess.crawler.exception.CrawlerSystemException)2 CrawlingAccessException (org.codelibs.fess.crawler.exception.CrawlingAccessException)2 CrawlingParameterUtil (org.codelibs.fess.crawler.util.CrawlingParameterUtil)2 FessConfig (org.codelibs.fess.mylasta.direction.FessConfig)2