Search in sources :

Example 1 with KeyMatchService

use of org.codelibs.fess.app.service.KeyMatchService in project fess by codelibs.

the class KeyMatchHelper method reload.

protected void reload(final long interval) {
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    final KeyMatchService keyMatchService = ComponentUtil.getComponent(KeyMatchService.class);
    final Map<String, Pair<QueryBuilder, ScoreFunctionBuilder>> keyMatchQueryMap = new HashMap<>();
    keyMatchService.getAvailableKeyMatchList().stream().forEach(keyMatch -> {
        final BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
        getDocumentList(keyMatch).stream().map(doc -> {
            return DocumentUtil.getValue(doc, fessConfig.getIndexFieldDocId(), String.class);
        }).forEach(docId -> {
            boolQuery.should(QueryBuilders.termQuery(fessConfig.getIndexFieldDocId(), docId));
        });
        if (boolQuery.hasClauses()) {
            keyMatchQueryMap.put(toLowerCase(keyMatch.getTerm()), new Pair<>(boolQuery, ScoreFunctionBuilders.weightFactorFunction(keyMatch.getBoost())));
        }
        if (reloadInterval > 0) {
            try {
                Thread.sleep(reloadInterval);
            } catch (final InterruptedException e) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Interrupted.", e);
                }
            }
        }
    });
    this.keyMatchQueryMap = keyMatchQueryMap;
}
Also used : QueryBuilder(org.elasticsearch.index.query.QueryBuilder) Constants(org.codelibs.fess.Constants) DocumentUtil(org.codelibs.fess.util.DocumentUtil) Logger(org.slf4j.Logger) FessEsClient(org.codelibs.fess.es.client.FessEsClient) LoggerFactory(org.slf4j.LoggerFactory) Pair(org.codelibs.core.misc.Pair) HashMap(java.util.HashMap) SearchConditionBuilder(org.codelibs.fess.es.client.FessEsClient.SearchConditionBuilder) QueryBuilders(org.elasticsearch.index.query.QueryBuilders) ScoreFunctionBuilders(org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders) KeyMatchService(org.codelibs.fess.app.service.KeyMatchService) List(java.util.List) SearchRequestType(org.codelibs.fess.entity.SearchRequestParams.SearchRequestType) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) FilterFunctionBuilder(org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder.FilterFunctionBuilder) ComponentUtil(org.codelibs.fess.util.ComponentUtil) Locale(java.util.Locale) Map(java.util.Map) KeyMatch(org.codelibs.fess.es.config.exentity.KeyMatch) PostConstruct(javax.annotation.PostConstruct) ScoreFunctionBuilder(org.elasticsearch.index.query.functionscore.ScoreFunctionBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) Collections(java.util.Collections) HashMap(java.util.HashMap) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) KeyMatchService(org.codelibs.fess.app.service.KeyMatchService) Pair(org.codelibs.core.misc.Pair)

Aggregations

Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Locale (java.util.Locale)1 Map (java.util.Map)1 PostConstruct (javax.annotation.PostConstruct)1 Pair (org.codelibs.core.misc.Pair)1 Constants (org.codelibs.fess.Constants)1 KeyMatchService (org.codelibs.fess.app.service.KeyMatchService)1 SearchRequestType (org.codelibs.fess.entity.SearchRequestParams.SearchRequestType)1 FessEsClient (org.codelibs.fess.es.client.FessEsClient)1 SearchConditionBuilder (org.codelibs.fess.es.client.FessEsClient.SearchConditionBuilder)1 KeyMatch (org.codelibs.fess.es.config.exentity.KeyMatch)1 FessConfig (org.codelibs.fess.mylasta.direction.FessConfig)1 ComponentUtil (org.codelibs.fess.util.ComponentUtil)1 DocumentUtil (org.codelibs.fess.util.DocumentUtil)1 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)1 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)1 QueryBuilders (org.elasticsearch.index.query.QueryBuilders)1 FilterFunctionBuilder (org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder.FilterFunctionBuilder)1