use of io.openk9.plugin.driver.manager.model.PluginDriverDTO in project openk9 by smclab.
the class BaseNerEnrichProcessor method prepareRequestRawContent.
protected ObjectNode prepareRequestRawContent(ObjectNode objectNode, ObjectNode datasourceConfiguration, DatasourceContext context, PluginDriverDTO pluginDriverDTO) {
JsonNode entitiesNode = datasourceConfiguration.get(entitiesField());
JsonNode relationsNode = datasourceConfiguration.get(relationsField());
JsonNode rawContentNode = objectNode.get(Constants.RAW_CONTENT);
JsonNode confidenceNode = datasourceConfiguration.get(Constants.CONFIDENCE);
ObjectNode request = _jsonFactory.createObjectNode();
request.put(entitiesField(), entitiesNode);
request.put(relationsField(), relationsNode);
request.put(Constants.CONFIDENCE, confidenceNode);
request.put(Constants.CONTENT, rawContentNode);
JsonNode typeNode = objectNode.get(Constants.TYPE);
ObjectNode datasourcePayload = _jsonFactory.createObjectNode();
if (typeNode != null && typeNode.isArray()) {
ArrayNode types = typeNode.toArrayNode();
for (JsonNode typeJsonNode : types) {
String type = typeJsonNode.asText();
datasourcePayload.put(type, objectNode.get(type));
}
}
request.put(Constants.DATASOURCE_PAYLOAD, datasourcePayload);
request.put(Constants.TENANT_ID, context.getTenant().getTenantId());
request.put(Constants.DATASOURCE_ID, context.getDatasource().getDatasourceId());
request.put(Constants.CONTENT_ID, objectNode.get(Constants.CONTENT_ID));
return request;
}
use of io.openk9.plugin.driver.manager.model.PluginDriverDTO in project openk9 by smclab.
the class PluginDriverEndPoints method _findPluginDriverByName.
private Publisher<Void> _findPluginDriverByName(HttpServerRequest httpRequest, HttpServerResponse httpResponse) {
return Mono.defer(() -> {
String serviceDriverName = httpRequest.param("serviceDriverName");
PluginDriverDTO response = _pluginDriverDTOService.findPluginDriverDTOByName(serviceDriverName).orElseThrow(() -> new HttpException(404, "No Content. PluginDriver not found for serviceDriverName: " + serviceDriverName));
return Mono.from(_httpResponseWriter.write(httpResponse, response));
});
}
use of io.openk9.plugin.driver.manager.model.PluginDriverDTO 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);
}
use of io.openk9.plugin.driver.manager.model.PluginDriverDTO in project openk9 by smclab.
the class JsEnrichProcessor method process.
@Override
public Mono<ObjectNode> process(ObjectNode objectNode, DatasourceContext context, EnrichItem enrichItem, PluginDriverDTO pluginDriverName) {
return Mono.defer(() -> {
JsonNode datasourceConfiguration = _jsonFactory.fromJsonToJsonNode(enrichItem.getJsonConfig());
if (!datasourceConfiguration.isObject()) {
return Mono.error(new RuntimeException("jsonConfig must be an instance of ObjectNode " + datasourceConfiguration.toString()));
}
ObjectNode request = prepareRequestRawContent(objectNode, datasourceConfiguration.toObjectNode(), context, pluginDriverName);
return Mono.from(_httpClient.request(getMethod(), getPath(), request.toString(), getHeaders())).map(_jsonFactory::fromJsonToJsonNode).map(JsonNode::toObjectNode).map(objectNode::merge);
});
}
use of io.openk9.plugin.driver.manager.model.PluginDriverDTO in project openk9 by smclab.
the class SearchAsYouTypeQueryParser method _termSearchAsYouTypeQueryValues.
private void _termSearchAsYouTypeQueryValues(SearchToken tokenText, BoolQueryBuilder query, List<PluginDriverDTO> entityMapperList) {
String[] values = tokenText.getValues();
if (values.length == 0) {
return;
}
String keywordKey = tokenText.getKeywordKey();
Predicate<SearchKeywordDTO> keywordKeyPredicate = searchKeyword -> keywordKey == null || keywordKey.isEmpty() || searchKeyword.getKeyword().equals(keywordKey);
Map<String, Float> keywordBoostMap = entityMapperList.stream().map(PluginDriverDTO::getDocumentTypes).flatMap(Collection::stream).map(DocumentTypeDTO::getSearchKeywords).flatMap(Collection::stream).filter(SearchKeywordDTO::isAutocomplete).filter(keywordKeyPredicate).map(SearchKeywordDTO::getFieldBoost).collect(Collectors.toMap(FieldBoostDTO::getKeyword, FieldBoostDTO::getBoost, Math::max, HashMap::new));
BoolQueryBuilder innerBoolQueryBuilder = QueryBuilders.boolQuery();
for (String value : values) {
MultiMatchQueryBuilder multiMatchQueryBuilder = new MultiMatchQueryBuilder(value);
multiMatchQueryBuilder.type(MultiMatchQueryBuilder.Type.BOOL_PREFIX);
multiMatchQueryBuilder.fields(keywordBoostMap);
innerBoolQueryBuilder.should(multiMatchQueryBuilder);
}
query.must(innerBoolQueryBuilder);
}
Aggregations