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());
}
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;
}
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();
}
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());
}
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());
}
Aggregations