Search in sources :

Example 1 with ScoreFunctionBuilder

use of org.elasticsearch.index.query.functionscore.ScoreFunctionBuilder in project fess by codelibs.

the class KeyMatchHelper method getBoostedDocumentList.

public List<Map<String, Object>> getBoostedDocumentList(final String term, final int size) {
    final FessEsClient fessEsClient = ComponentUtil.getFessEsClient();
    final Pair<QueryBuilder, ScoreFunctionBuilder> pair = keyMatchQueryMap.get(toLowerCase(term));
    if (pair == null) {
        return Collections.emptyList();
    }
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    return fessEsClient.getDocumentList(fessConfig.getIndexDocumentSearchIndex(), fessConfig.getIndexDocumentType(), searchRequestBuilder -> {
        searchRequestBuilder.setPreference(Constants.SEARCH_PREFERENCE_PRIMARY).setQuery(pair.getFirst()).setSize(size);
        return true;
    });
}
Also used : ScoreFunctionBuilder(org.elasticsearch.index.query.functionscore.ScoreFunctionBuilder) FessEsClient(org.codelibs.fess.es.client.FessEsClient) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig)

Example 2 with ScoreFunctionBuilder

use of org.elasticsearch.index.query.functionscore.ScoreFunctionBuilder 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

FessEsClient (org.codelibs.fess.es.client.FessEsClient)2 FessConfig (org.codelibs.fess.mylasta.direction.FessConfig)2 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)2 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)2 ScoreFunctionBuilder (org.elasticsearch.index.query.functionscore.ScoreFunctionBuilder)2 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 SearchConditionBuilder (org.codelibs.fess.es.client.FessEsClient.SearchConditionBuilder)1 KeyMatch (org.codelibs.fess.es.config.exentity.KeyMatch)1 ComponentUtil (org.codelibs.fess.util.ComponentUtil)1 DocumentUtil (org.codelibs.fess.util.DocumentUtil)1 QueryBuilders (org.elasticsearch.index.query.QueryBuilders)1