Search in sources :

Example 51 with FessConfig

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

the class SearchHelper method getDocumentListByDocIds.

public List<Map<String, Object>> getDocumentListByDocIds(final String[] docIds, final String[] fields, final OptionalThing<FessUserBean> userBean, final SearchRequestType searchRequestType) {
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    return ComponentUtil.getSearchEngineClient().getDocumentList(fessConfig.getIndexDocumentSearchIndex(), builder -> {
        final BoolQueryBuilder boolQuery = QueryBuilders.boolQuery().must(QueryBuilders.termsQuery(fessConfig.getIndexFieldDocId(), docIds));
        final QueryHelper queryHelper = ComponentUtil.getQueryHelper();
        if (searchRequestType != SearchRequestType.ADMIN_SEARCH) {
            final Set<String> roleSet = ComponentUtil.getRoleQueryHelper().build(searchRequestType);
            if (!roleSet.isEmpty()) {
                queryHelper.buildRoleQuery(roleSet, boolQuery);
            }
        }
        builder.setQuery(boolQuery);
        builder.setSize(fessConfig.getPagingSearchPageMaxSizeAsInteger());
        builder.setFetchSource(fields, null);
        queryHelper.processSearchPreference(builder, userBean, String.join(StringUtil.EMPTY, docIds));
        return true;
    });
}
Also used : BoolQueryBuilder(org.opensearch.index.query.BoolQueryBuilder) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig)

Example 52 with FessConfig

use of org.codelibs.fess.mylasta.direction.FessConfig 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)

Example 53 with FessConfig

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

the class CorsFilter method doFilter.

@Override
public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException {
    final HttpServletRequest httpRequest = (HttpServletRequest) request;
    final String origin = httpRequest.getHeader("Origin");
    if (StringUtil.isBlank(origin)) {
        chain.doFilter(request, response);
        return;
    }
    if (logger.isDebugEnabled()) {
        logger.debug("HTTP Request: {}", httpRequest.getMethod());
    }
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    final String allowOrigin = getAllowOrigin(fessConfig, origin);
    if (StringUtil.isNotBlank(allowOrigin)) {
        if (logger.isDebugEnabled()) {
            logger.debug("allowOrigin: {}", allowOrigin);
        }
        final HttpServletResponse httpResponse = (HttpServletResponse) response;
        httpResponse.addHeader(ACCESS_CONTROL_ALLOW_ORIGIN, allowOrigin);
        httpResponse.addHeader(ACCESS_CONTROL_ALLOW_METHODS, fessConfig.getApiCorsAllowMethods());
        httpResponse.addHeader(ACCESS_CONTROL_ALLOW_HEADERS, fessConfig.getApiCorsAllowHeaders());
        httpResponse.addHeader(ACCESS_CONTROL_MAX_AGE, fessConfig.getApiCorsMaxAge());
        httpResponse.addHeader(ACCESS_CONTROL_ALLOW_CREDENTIALS, fessConfig.getApiCorsAllowCredentials());
        if (OPTIONS.equals(httpRequest.getMethod())) {
            httpResponse.setStatus(HttpServletResponse.SC_ACCEPTED);
            return;
        }
    }
    chain.doFilter(request, response);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig)

Example 54 with FessConfig

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

the class CrawlingConfigHelper method getExcludedUrlList.

public List<String> getExcludedUrlList(final String configId) {
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    final int failureCount = fessConfig.getFailureCountThreshold();
    final String ignoreFailureType = fessConfig.getIgnoreFailureType();
    if (failureCount < 0) {
        return Collections.emptyList();
    }
    final int count = failureCount;
    final ListResultBean<FailureUrl> list = ComponentUtil.getComponent(FailureUrlBhv.class).selectList(cb -> {
        cb.query().setConfigId_Equal(configId);
        cb.query().setErrorCount_GreaterEqual(count);
        cb.fetchFirst(fessConfig.getPageFailureUrlMaxFetchSizeAsInteger());
    });
    if (list.isEmpty()) {
        return Collections.emptyList();
    }
    Pattern pattern = null;
    if (StringUtil.isNotBlank(ignoreFailureType)) {
        pattern = Pattern.compile(ignoreFailureType);
    }
    final List<String> urlList = new ArrayList<>();
    for (final FailureUrl failureUrl : list) {
        if (pattern != null) {
            if (!pattern.matcher(failureUrl.getErrorName()).matches()) {
                urlList.add(failureUrl.getUrl());
            }
        } else {
            urlList.add(failureUrl.getUrl());
        }
    }
    return urlList;
}
Also used : Pattern(java.util.regex.Pattern) FailureUrlBhv(org.codelibs.fess.es.config.exbhv.FailureUrlBhv) ArrayList(java.util.ArrayList) FailureUrl(org.codelibs.fess.es.config.exentity.FailureUrl) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig)

Example 55 with FessConfig

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

the class CrawlingInfoHelper method getSessionIdList.

public List<Map<String, String>> getSessionIdList(final SearchEngineClient searchEngineClient) {
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    return searchEngineClient.search(fessConfig.getIndexDocumentSearchIndex(), queryRequestBuilder -> {
        queryRequestBuilder.setQuery(QueryBuilders.matchAllQuery());
        final TermsAggregationBuilder termsBuilder = AggregationBuilders.terms(fessConfig.getIndexFieldSegment()).field(fessConfig.getIndexFieldSegment()).size(maxSessionIdsInList).order(BucketOrder.key(false));
        queryRequestBuilder.addAggregation(termsBuilder);
        queryRequestBuilder.setPreference(Constants.SEARCH_PREFERENCE_LOCAL);
        return true;
    }, (queryRequestBuilder, execTime, searchResponse) -> {
        final List<Map<String, String>> sessionIdList = new ArrayList<>();
        searchResponse.ifPresent(response -> {
            final Terms terms = response.getAggregations().get(fessConfig.getIndexFieldSegment());
            for (final Bucket bucket : terms.getBuckets()) {
                final Map<String, String> map = new HashMap<>(2);
                map.put(fessConfig.getIndexFieldSegment(), bucket.getKey().toString());
                map.put(FACET_COUNT_KEY, Long.toString(bucket.getDocCount()));
                sessionIdList.add(map);
            }
        });
        return sessionIdList;
    });
}
Also used : TermsAggregationBuilder(org.opensearch.search.aggregations.bucket.terms.TermsAggregationBuilder) Bucket(org.opensearch.search.aggregations.bucket.terms.Terms.Bucket) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) Terms(org.opensearch.search.aggregations.bucket.terms.Terms) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

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