Search in sources :

Example 1 with KeyMatch

use of org.codelibs.fess.es.config.exentity.KeyMatch in project fess by codelibs.

the class ApiAdminKeymatchAction method post$setting.

// POST /api/admin/keymatch/setting
@Execute
public JsonResponse<ApiResult> post$setting(final EditBody body) {
    validateApi(body, messages -> {
    });
    body.crudMode = CrudMode.EDIT;
    final KeyMatch keyMatch = getKeyMatch(body).map(entity -> {
        try {
            keyMatchService.store(entity);
        } catch (final Exception e) {
            throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToUpdateCrudTable(GLOBAL, buildThrowableMessage(e)));
        }
        return entity;
    }).orElseGet(() -> {
        throwValidationErrorApi(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, body.id));
        return null;
    });
    return asJson(new ApiUpdateResponse().id(keyMatch.getId()).created(false).status(Status.OK).result());
}
Also used : FessApiAdminAction(org.codelibs.fess.app.web.api.admin.FessApiAdminAction) Resource(javax.annotation.Resource) ApiConfigResponse(org.codelibs.fess.app.web.api.ApiResult.ApiConfigResponse) JsonResponse(org.lastaflute.web.response.JsonResponse) Collectors(java.util.stream.Collectors) ApiResult(org.codelibs.fess.app.web.api.ApiResult) ApiUpdateResponse(org.codelibs.fess.app.web.api.ApiResult.ApiUpdateResponse) KeyMatchService(org.codelibs.fess.app.service.KeyMatchService) Status(org.codelibs.fess.app.web.api.ApiResult.Status) List(java.util.List) CrudMode(org.codelibs.fess.app.web.CrudMode) KeyMatch(org.codelibs.fess.es.config.exentity.KeyMatch) Execute(org.lastaflute.web.Execute) ApiResponse(org.codelibs.fess.app.web.api.ApiResult.ApiResponse) AdminKeymatchAction.getKeyMatch(org.codelibs.fess.app.web.admin.keymatch.AdminKeymatchAction.getKeyMatch) KeyMatchPager(org.codelibs.fess.app.pager.KeyMatchPager) KeyMatch(org.codelibs.fess.es.config.exentity.KeyMatch) AdminKeymatchAction.getKeyMatch(org.codelibs.fess.app.web.admin.keymatch.AdminKeymatchAction.getKeyMatch) ApiUpdateResponse(org.codelibs.fess.app.web.api.ApiResult.ApiUpdateResponse) Execute(org.lastaflute.web.Execute)

Example 2 with KeyMatch

use of org.codelibs.fess.es.config.exentity.KeyMatch 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)

Example 3 with KeyMatch

use of org.codelibs.fess.es.config.exentity.KeyMatch in project fess by codelibs.

the class KeyMatchHelper method load.

@Override
public int load() {
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    final Map<String, Map<String, List<Tuple3<String, QueryBuilder, ScoreFunctionBuilder<?>>>>> keyMatchQueryMap = new HashMap<>();
    getAvailableKeyMatchList().stream().forEach(keyMatch -> {
        try {
            final BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
            if (logger.isDebugEnabled()) {
                logger.debug("Loading KeyMatch Query: {}, Size: {}", keyMatch.getQuery(), keyMatch.getMaxSize());
            }
            getDocumentList(keyMatch).stream().map(doc -> {
                if (logger.isDebugEnabled()) {
                    logger.debug("Loaded KeyMatch doc: {}", doc);
                }
                return DocumentUtil.getValue(doc, fessConfig.getIndexFieldDocId(), String.class);
            }).forEach(docId -> {
                boolQuery.should(QueryBuilders.termQuery(fessConfig.getIndexFieldDocId(), docId));
            });
            if (boolQuery.hasClauses()) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Loaded KeyMatch Boost Query: {}", boolQuery);
                }
                String virtualHost = keyMatch.getVirtualHost();
                if (StringUtil.isBlank(virtualHost)) {
                    virtualHost = StringUtil.EMPTY;
                }
                Map<String, List<Tuple3<String, QueryBuilder, ScoreFunctionBuilder<?>>>> queryMap = keyMatchQueryMap.get(virtualHost);
                if (queryMap == null) {
                    queryMap = new HashMap<>();
                    keyMatchQueryMap.put(virtualHost, queryMap);
                }
                final String termKey = toLowerCase(keyMatch.getTerm());
                List<Tuple3<String, QueryBuilder, ScoreFunctionBuilder<?>>> boostList = queryMap.get(termKey);
                if (boostList == null) {
                    boostList = new ArrayList<>();
                    queryMap.put(termKey, boostList);
                }
                boostList.add(new Tuple3<>(keyMatch.getId(), boolQuery, ScoreFunctionBuilders.weightFactorFunction(keyMatch.getBoost())));
            } else if (logger.isDebugEnabled()) {
                logger.debug("No KeyMatch boost docs");
            }
            waitForNext();
        } catch (final Exception e) {
            logger.warn("Cannot load {}", keyMatch, e);
        }
    });
    this.keyMatchQueryMap = keyMatchQueryMap;
    return keyMatchQueryMap.size();
}
Also used : Constants(org.codelibs.fess.Constants) DocumentUtil(org.codelibs.fess.util.DocumentUtil) ScoreFunctionBuilder(org.opensearch.index.query.functionscore.ScoreFunctionBuilder) HashMap(java.util.HashMap) SearchEngineClient(org.codelibs.fess.es.client.SearchEngineClient) SearchConditionBuilder(org.codelibs.fess.es.client.SearchEngineClient.SearchConditionBuilder) ArrayList(java.util.ArrayList) SearchRequestType(org.codelibs.fess.entity.SearchRequestParams.SearchRequestType) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) KeyMatchBhv(org.codelibs.fess.es.config.exbhv.KeyMatchBhv) Locale(java.util.Locale) Map(java.util.Map) KeyMatch(org.codelibs.fess.es.config.exentity.KeyMatch) QueryBuilders(org.opensearch.index.query.QueryBuilders) StringUtil(org.codelibs.core.lang.StringUtil) ScoreFunctionBuilders(org.opensearch.index.query.functionscore.ScoreFunctionBuilders) Tuple3(org.codelibs.core.misc.Tuple3) List(java.util.List) Logger(org.apache.logging.log4j.Logger) QueryBuilder(org.opensearch.index.query.QueryBuilder) ComponentUtil(org.codelibs.fess.util.ComponentUtil) PostConstruct(javax.annotation.PostConstruct) FilterFunctionBuilder(org.opensearch.index.query.functionscore.FunctionScoreQueryBuilder.FilterFunctionBuilder) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) BoolQueryBuilder(org.opensearch.index.query.BoolQueryBuilder) ScoreFunctionBuilder(org.opensearch.index.query.functionscore.ScoreFunctionBuilder) HashMap(java.util.HashMap) QueryBuilder(org.opensearch.index.query.QueryBuilder) BoolQueryBuilder(org.opensearch.index.query.BoolQueryBuilder) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) BoolQueryBuilder(org.opensearch.index.query.BoolQueryBuilder) Tuple3(org.codelibs.core.misc.Tuple3) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with KeyMatch

use of org.codelibs.fess.es.config.exentity.KeyMatch in project fess by codelibs.

the class ApiAdminKeymatchAction method settings.

// ===================================================================================
// Search Execute
// ==============
// GET /api/admin/keymatch/settings
// POST /api/admin/keymatch/settings
@Execute
public JsonResponse<ApiResult> settings(final SearchBody body) {
    validateApi(body, messages -> {
    });
    final KeyMatchPager pager = copyBeanToNewBean(body, KeyMatchPager.class);
    final List<KeyMatch> list = keyMatchService.getKeyMatchList(pager);
    return asJson(new ApiResult.ApiConfigsResponse<EditBody>().settings(list.stream().map(this::createEditBody).collect(Collectors.toList())).total(pager.getAllRecordCount()).status(ApiResult.Status.OK).result());
}
Also used : ApiResult(org.codelibs.fess.app.web.api.ApiResult) KeyMatch(org.codelibs.fess.es.config.exentity.KeyMatch) AdminKeymatchAction.getKeyMatch(org.codelibs.fess.app.web.admin.keymatch.AdminKeymatchAction.getKeyMatch) KeyMatchPager(org.codelibs.fess.app.pager.KeyMatchPager) Execute(org.lastaflute.web.Execute)

Example 5 with KeyMatch

use of org.codelibs.fess.es.config.exentity.KeyMatch in project fess by codelibs.

the class ApiAdminKeymatchAction method put$setting.

// PUT /api/admin/keymatch/setting
@Execute
public JsonResponse<ApiResult> put$setting(final CreateBody body) {
    validateApi(body, messages -> {
    });
    body.crudMode = CrudMode.CREATE;
    final KeyMatch keyMatch = getKeyMatch(body).map(entity -> {
        try {
            keyMatchService.store(entity);
        } catch (final Exception e) {
            throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToCreateCrudTable(GLOBAL, buildThrowableMessage(e)));
        }
        return entity;
    }).orElseGet(() -> {
        throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToCreateInstance(GLOBAL));
        return null;
    });
    return asJson(new ApiUpdateResponse().id(keyMatch.getId()).created(true).status(Status.OK).result());
}
Also used : FessApiAdminAction(org.codelibs.fess.app.web.api.admin.FessApiAdminAction) Resource(javax.annotation.Resource) ApiConfigResponse(org.codelibs.fess.app.web.api.ApiResult.ApiConfigResponse) JsonResponse(org.lastaflute.web.response.JsonResponse) Collectors(java.util.stream.Collectors) ApiResult(org.codelibs.fess.app.web.api.ApiResult) ApiUpdateResponse(org.codelibs.fess.app.web.api.ApiResult.ApiUpdateResponse) KeyMatchService(org.codelibs.fess.app.service.KeyMatchService) Status(org.codelibs.fess.app.web.api.ApiResult.Status) List(java.util.List) CrudMode(org.codelibs.fess.app.web.CrudMode) KeyMatch(org.codelibs.fess.es.config.exentity.KeyMatch) Execute(org.lastaflute.web.Execute) ApiResponse(org.codelibs.fess.app.web.api.ApiResult.ApiResponse) AdminKeymatchAction.getKeyMatch(org.codelibs.fess.app.web.admin.keymatch.AdminKeymatchAction.getKeyMatch) KeyMatchPager(org.codelibs.fess.app.pager.KeyMatchPager) KeyMatch(org.codelibs.fess.es.config.exentity.KeyMatch) AdminKeymatchAction.getKeyMatch(org.codelibs.fess.app.web.admin.keymatch.AdminKeymatchAction.getKeyMatch) ApiUpdateResponse(org.codelibs.fess.app.web.api.ApiResult.ApiUpdateResponse) Execute(org.lastaflute.web.Execute)

Aggregations

KeyMatch (org.codelibs.fess.es.config.exentity.KeyMatch)5 List (java.util.List)4 KeyMatchPager (org.codelibs.fess.app.pager.KeyMatchPager)3 KeyMatchService (org.codelibs.fess.app.service.KeyMatchService)3 AdminKeymatchAction.getKeyMatch (org.codelibs.fess.app.web.admin.keymatch.AdminKeymatchAction.getKeyMatch)3 ApiResult (org.codelibs.fess.app.web.api.ApiResult)3 Execute (org.lastaflute.web.Execute)3 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 Locale (java.util.Locale)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 PostConstruct (javax.annotation.PostConstruct)2 Resource (javax.annotation.Resource)2 Constants (org.codelibs.fess.Constants)2 CrudMode (org.codelibs.fess.app.web.CrudMode)2 ApiConfigResponse (org.codelibs.fess.app.web.api.ApiResult.ApiConfigResponse)2 ApiResponse (org.codelibs.fess.app.web.api.ApiResult.ApiResponse)2 ApiUpdateResponse (org.codelibs.fess.app.web.api.ApiResult.ApiUpdateResponse)2 Status (org.codelibs.fess.app.web.api.ApiResult.Status)2