use of io.openk9.plugin.driver.manager.model.DocumentTypeDTO in project openk9 by smclab.
the class SupportedDatasourcesEndpoint method _mapToResponse.
private SupportedDatasourcesResponse _mapToResponse(Tuple2<Datasource, PluginDriverDTO> t2) {
Datasource t1 = t2.getT1();
PluginDriverDTO pluginDriver = t2.getT2();
return SupportedDatasourcesResponse.of(t1.getName(), t1.getActive(), pluginDriver.getDocumentTypes().stream().map(documentTypeDTO -> SupportedDatasourcesDocumentType.of(documentTypeDTO.getName(), documentTypeDTO.getIcon())).collect(Collectors.toList()), SupportedDatasourcesDocumentType.of(pluginDriver.getDefaultDocumentType().getName(), pluginDriver.getDefaultDocumentType().getIcon()));
}
use of io.openk9.plugin.driver.manager.model.DocumentTypeDTO in project openk9 by smclab.
the class DateOrderQueryParser method apply.
@Override
public Mono<Consumer<BoolQueryBuilder>> apply(Context context) {
return Mono.fromSupplier(() -> (bool) -> {
List<PluginDriverDTO> pluginDriverDocumentTypeList = context.getPluginDriverDocumentTypeList();
Iterator<String> iterator = pluginDriverDocumentTypeList.stream().map(PluginDriverDTO::getDocumentTypes).flatMap(Collection::stream).map(DocumentTypeDTO::getSearchKeywords).flatMap(Collection::stream).filter(SearchKeywordDTO::isDate).distinct().map(SearchKeywordDTO::getKeyword).iterator();
if (iterator.hasNext()) {
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
boolQueryBuilder.boost(_boost);
while (iterator.hasNext()) {
String keyword = iterator.next();
FunctionScoreQueryBuilder.FilterFunctionBuilder filterFunctionBuilder = new FunctionScoreQueryBuilder.FilterFunctionBuilder(ScoreFunctionBuilders.linearDecayFunction(keyword, null, _scale));
boolQueryBuilder.should(QueryBuilders.functionScoreQuery(QueryBuilders.existsQuery(keyword), new FunctionScoreQueryBuilder.FilterFunctionBuilder[] { filterFunctionBuilder }));
}
bool.should(boolQueryBuilder);
}
});
}
use of io.openk9.plugin.driver.manager.model.DocumentTypeDTO in project openk9 by smclab.
the class DateQueryParser method _rangeQuery.
private void _rangeQuery(List<SearchToken> searchTokens, List<PluginDriverDTO> pluginDriverDocumentTypeList, BoolQueryBuilder bool) {
if (searchTokens.isEmpty()) {
return;
}
List<SearchKeywordToken> collect = pluginDriverDocumentTypeList.stream().map(PluginDriverDTO::getDocumentTypes).flatMap(Collection::stream).map(DocumentTypeDTO::getSearchKeywords).flatMap(Collection::stream).filter(SearchKeywordDTO::isDate).flatMap(searchKeywordDTO -> {
for (SearchToken searchToken : searchTokens) {
if (searchToken.getKeywordKey() != null && searchToken.getKeywordKey().equals(searchKeywordDTO.getKeyword())) {
return Stream.of(SearchKeywordToken.of(searchKeywordDTO, searchToken));
}
}
return Stream.empty();
}).collect(Collectors.toList());
if (!collect.isEmpty()) {
BoolQueryBuilder internalBool = QueryBuilders.boolQuery();
boolean flag = false;
for (SearchKeywordToken searchKeywordToken : collect) {
SearchToken searchToken = searchKeywordToken.getSearchToken();
Map<String, Object> extra = searchToken.getExtra();
if (extra == null) {
String[] values = searchToken.getValues();
String gte;
String lte;
if (values.length != 0) {
RangeQueryBuilder rangeQueryBuilder = QueryBuilders.rangeQuery(searchToken.getKeywordKey());
if (values.length == 1) {
gte = values[0];
rangeQueryBuilder.gte(gte);
} else if (values.length == 2) {
gte = values[0];
lte = values[1];
if (gte == null || gte.isBlank()) {
rangeQueryBuilder.lte(lte);
} else {
rangeQueryBuilder.gte(gte).lte(lte);
}
}
flag = true;
internalBool.should(rangeQueryBuilder);
}
} else {
Object gte = extra.get("gte");
Object lte = extra.get("lte");
Object lt = extra.get("lt");
Object gt = extra.get("gt");
String format = (String) extra.get("format");
String timeZone = (String) extra.get("time_zone");
String relation = (String) extra.get("relation");
RangeQueryBuilder rangeQueryBuilder = QueryBuilders.rangeQuery(searchToken.getKeywordKey());
if (gte != null) {
rangeQueryBuilder.gte(gte);
}
if (lte != null) {
rangeQueryBuilder.lte(lte);
}
if (gt != null) {
rangeQueryBuilder.gt(gt);
}
if (lt != null) {
rangeQueryBuilder.lt(lt);
}
if (format != null) {
rangeQueryBuilder.format(format);
}
if (timeZone != null) {
rangeQueryBuilder.timeZone(timeZone);
}
if (relation != null && (relation.equals("INTERSECTS") || relation.equals("CONTAINS") || relation.equals("WITHIN"))) {
rangeQueryBuilder.relation(relation);
}
flag = true;
internalBool.should(rangeQueryBuilder);
}
}
if (flag) {
bool.must(internalBool);
}
}
}
use of io.openk9.plugin.driver.manager.model.DocumentTypeDTO in project openk9 by smclab.
the class DocumentTypesEndpoint method _mapToResponse.
private Object _mapToResponse(List<Tuple2<Datasource, PluginDriverDTO>> list) {
Map<String, Collection<String>> response = new HashMap<>();
for (Tuple2<Datasource, PluginDriverDTO> t2 : list) {
PluginDriverDTO pluginDriver = t2.getT2();
for (DocumentTypeDTO documentType : pluginDriver.getDocumentTypes()) {
String name = documentType.getName();
List<SearchKeywordDTO> searchKeywords = documentType.getSearchKeywords();
List<String> keywords = searchKeywords.stream().map(SearchKeywordDTO::getKeyword).collect(Collectors.toList());
Collection<String> prevKeywords = response.get(name);
Set<String> combine = new HashSet<>(keywords);
if (prevKeywords != null) {
combine.addAll(prevKeywords);
}
response.put(name, combine);
}
}
return response;
}
use of io.openk9.plugin.driver.manager.model.DocumentTypeDTO in project openk9 by smclab.
the class TextQueryParser method _termQueryPrefixValues.
private void _termQueryPrefixValues(SearchToken tokenText, BoolQueryBuilder query, List<PluginDriverDTO> entityMapperList, QueryCondition queryCondition) {
String[] values = tokenText.getValues();
if (values.length == 0) {
return;
}
String keywordKey = tokenText.getKeywordKey();
boolean keywordKeyIsPresent = keywordKey != null && !keywordKey.isBlank();
Predicate<SearchKeywordDTO> keywordKeyPredicate;
if (keywordKeyIsPresent) {
keywordKeyPredicate = searchKeyword -> searchKeyword.getKeyword().equals(keywordKey);
} else {
keywordKeyPredicate = ignore -> true;
}
if (queryCondition == QueryCondition.DEFAULT) {
queryCondition = tokenText.getFilter() != null && tokenText.getFilter() ? QueryCondition.FILTER : QueryCondition.SHOULD;
}
Map<String, Float> keywordBoostMap = entityMapperList.stream().map(PluginDriverDTO::getDocumentTypes).flatMap(Collection::stream).map(DocumentTypeDTO::getSearchKeywords).flatMap(Collection::stream).filter(SearchKeywordDTO::isText).filter(keywordKeyPredicate).map(SearchKeywordDTO::getFieldBoost).collect(Collectors.toMap(FieldBoostDTO::getKeyword, FieldBoostDTO::getBoost, Math::max, HashMap::new));
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
boolQueryBuilder.boost(_boost);
for (String value : values) {
MultiMatchQueryBuilder multiMatchQueryBuilder = new MultiMatchQueryBuilder(value);
multiMatchQueryBuilder.fields(keywordBoostMap);
queryCondition.accept(boolQueryBuilder, multiMatchQueryBuilder);
if (value.split("\\s+").length > 1) {
multiMatchQueryBuilder = new MultiMatchQueryBuilder(value);
multiMatchQueryBuilder.fields(keywordBoostMap);
multiMatchQueryBuilder.type(MultiMatchQueryBuilder.Type.PHRASE);
multiMatchQueryBuilder.slop(2);
multiMatchQueryBuilder.boost(2.0f);
queryCondition.accept(boolQueryBuilder, multiMatchQueryBuilder);
}
}
queryCondition.accept(query, boolQueryBuilder);
}
Aggregations