Search in sources :

Example 31 with FessConfig

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

the class LdapManager method processSearchRoles.

protected void processSearchRoles(final List<SearchResult> result, final BiConsumer<String, String> consumer) throws NamingException {
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    for (final SearchResult srcrslt : result) {
        final Attributes attrs = srcrslt.getAttributes();
        //get group attr
        final Attribute attr = attrs.get(fessConfig.getLdapMemberofAttribute());
        if (attr == null) {
            continue;
        }
        for (int i = 0; i < attr.size(); i++) {
            final Object attrValue = attr.get(i);
            if (attrValue != null) {
                final String entryDn = attrValue.toString();
                int start = 0;
                int end = 0;
                start = entryDn.indexOf("CN=");
                if (start < 0) {
                    start = entryDn.indexOf("cn=");
                }
                if (start == -1) {
                    continue;
                }
                start += 3;
                end = entryDn.indexOf(',');
                String name;
                if (end == -1) {
                    name = entryDn.substring(start);
                } else {
                    name = entryDn.substring(start, end);
                }
                consumer.accept(entryDn, name);
            }
        }
    }
}
Also used : BasicAttribute(javax.naming.directory.BasicAttribute) Attribute(javax.naming.directory.Attribute) BasicAttributes(javax.naming.directory.BasicAttributes) Attributes(javax.naming.directory.Attributes) SearchResult(javax.naming.directory.SearchResult) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig)

Example 32 with FessConfig

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

the class IndexUpdater method updateDocument.

protected void updateDocument(final Map<String, Object> map) {
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    if (fessConfig.getIndexerClickCountEnabledAsBoolean()) {
        addClickCountField(map);
    }
    if (fessConfig.getIndexerFavoriteCountEnabledAsBoolean()) {
        addFavoriteCountField(map);
    }
    float documentBoost = 0.0f;
    for (final DocBoostMatcher docBoostMatcher : docBoostMatcherList) {
        if (docBoostMatcher.match(map)) {
            documentBoost = docBoostMatcher.getValue(map);
            break;
        }
    }
    if (documentBoost > 0) {
        addBoostValue(map, documentBoost);
    }
    if (!map.containsKey(fessConfig.getIndexFieldDocId())) {
        map.put(fessConfig.getIndexFieldDocId(), systemHelper.generateDocId(map));
    }
}
Also used : FessConfig(org.codelibs.fess.mylasta.direction.FessConfig)

Example 33 with FessConfig

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

the class IndexUpdater method getAccessResultList.

private List<EsAccessResult> getAccessResultList(final Consumer<SearchRequestBuilder> cb, final long cleanupTime) {
    if (logger.isDebugEnabled()) {
        logger.debug("Getting documents in IndexUpdater queue.");
    }
    final long execTime = System.currentTimeMillis();
    final List<EsAccessResult> arList = ((EsDataService) dataService).getAccessResultList(cb);
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    if (!arList.isEmpty()) {
        final long commitMarginTime = fessConfig.getIndexerWebfsCommitMarginTimeAsInteger().longValue();
        for (final AccessResult<?> ar : arList.toArray(new AccessResult[arList.size()])) {
            if (ar.getCreateTime().longValue() > execTime - commitMarginTime) {
                arList.remove(ar);
            }
        }
    }
    final long totalHits = ((EsResultList<EsAccessResult>) arList).getTotalHits();
    if (logger.isInfoEnabled()) {
        final StringBuilder buf = new StringBuilder(100);
        buf.append("Processing ");
        if (totalHits > 0) {
            buf.append(arList.size()).append('/').append(totalHits).append(" docs (Doc:{access ");
        } else {
            buf.append("no docs (Doc:{access ");
        }
        buf.append(System.currentTimeMillis() - execTime).append("ms");
        if (cleanupTime >= 0) {
            buf.append(", cleanup ").append(cleanupTime).append("ms");
        }
        buf.append("}, ");
        buf.append(MemoryUtil.getMemoryUsageLog());
        buf.append(')');
        logger.info(buf.toString());
    }
    final long unprocessedDocumentSize = fessConfig.getIndexerUnprocessedDocumentSizeAsInteger().longValue();
    final IntervalControlHelper intervalControlHelper = ComponentUtil.getIntervalControlHelper();
    if (totalHits > unprocessedDocumentSize && intervalControlHelper.isCrawlerRunning()) {
        if (logger.isInfoEnabled()) {
            logger.info("Stopped all crawler threads. " + " You have " + totalHits + " (>" + unprocessedDocumentSize + ") " + " unprocessed docs.");
        }
        intervalControlHelper.setCrawlerRunning(false);
    }
    return arList;
}
Also used : EsAccessResult(org.codelibs.fess.crawler.entity.EsAccessResult) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) EsDataService(org.codelibs.fess.crawler.service.impl.EsDataService) EsResultList(org.codelibs.fess.crawler.util.EsResultList) IntervalControlHelper(org.codelibs.fess.helper.IntervalControlHelper)

Example 34 with FessConfig

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

the class IndexUpdater method addFavoriteCountField.

protected void addFavoriteCountField(final Map<String, Object> map) {
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    final String url = (String) map.get(fessConfig.getIndexFieldUrl());
    if (StringUtil.isNotBlank(url)) {
        final SearchLogHelper searchLogHelper = ComponentUtil.getSearchLogHelper();
        final long count = searchLogHelper.getFavoriteCount(url);
        map.put(fessConfig.getIndexFieldFavoriteCount(), count);
        if (logger.isDebugEnabled()) {
            logger.debug("Favorite Count: " + count + ", url: " + url);
        }
    }
}
Also used : SearchLogHelper(org.codelibs.fess.helper.SearchLogHelper) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig)

Example 35 with FessConfig

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

the class SystemHelper method init.

@PostConstruct
public void init() {
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    filterPathEncoding = fessConfig.getPathEncoding();
    supportedLanguages = fessConfig.getSupportedLanguagesAsArray();
    langItemsCache = CacheBuilder.newBuilder().maximumSize(20).expireAfterAccess(1, TimeUnit.HOURS).build(new CacheLoader<String, List<Map<String, String>>>() {

        @Override
        public List<Map<String, String>> load(final String key) throws Exception {
            final ULocale uLocale = new ULocale(key);
            final Locale displayLocale = uLocale.toLocale();
            final List<Map<String, String>> langItems = new ArrayList<>(supportedLanguages.length);
            final String msg = ComponentUtil.getMessageManager().getMessage(displayLocale, "labels.allLanguages");
            final Map<String, String> defaultMap = new HashMap<>(2);
            defaultMap.put(Constants.ITEM_LABEL, msg);
            defaultMap.put(Constants.ITEM_VALUE, "all");
            langItems.add(defaultMap);
            for (final String lang : supportedLanguages) {
                final Locale locale = LocaleUtils.toLocale(lang);
                final String label = locale.getDisplayName(displayLocale);
                final Map<String, String> map = new HashMap<>(2);
                map.put(Constants.ITEM_LABEL, label);
                map.put(Constants.ITEM_VALUE, lang);
                langItems.add(map);
            }
            return langItems;
        }
    });
    ComponentUtil.doInitProcesses(p -> p.run());
}
Also used : ULocale(com.ibm.icu.util.ULocale) Locale(java.util.Locale) ULocale(com.ibm.icu.util.ULocale) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CacheLoader(com.google.common.cache.CacheLoader) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) HashMap(java.util.HashMap) Map(java.util.Map) PostConstruct(javax.annotation.PostConstruct)

Aggregations

FessConfig (org.codelibs.fess.mylasta.direction.FessConfig)108 ArrayList (java.util.ArrayList)41 Map (java.util.Map)33 HashMap (java.util.HashMap)32 List (java.util.List)27 ComponentUtil (org.codelibs.fess.util.ComponentUtil)27 Logger (org.slf4j.Logger)26 LoggerFactory (org.slf4j.LoggerFactory)26 StringUtil (org.codelibs.core.lang.StringUtil)24 Constants (org.codelibs.fess.Constants)22 StreamUtil.stream (org.codelibs.core.stream.StreamUtil.stream)21 IOException (java.io.IOException)15 SystemHelper (org.codelibs.fess.helper.SystemHelper)15 PostConstruct (javax.annotation.PostConstruct)14 FessSystemException (org.codelibs.fess.exception.FessSystemException)14 File (java.io.File)11 Date (java.util.Date)11 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)11 Hashtable (java.util.Hashtable)10 FessEsClient (org.codelibs.fess.es.client.FessEsClient)9