Search in sources :

Example 6 with PluginDriverDTO

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;
}
Also used : ObjectNode(io.openk9.json.api.ObjectNode) JsonNode(io.openk9.json.api.JsonNode) ArrayNode(io.openk9.json.api.ArrayNode)

Example 7 with PluginDriverDTO

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));
    });
}
Also used : HttpException(io.openk9.http.exception.HttpException) PluginDriverDTO(io.openk9.plugin.driver.manager.model.PluginDriverDTO)

Example 8 with PluginDriverDTO

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);
}
Also used : BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) Collection(java.util.Collection) MultiMatchQueryBuilder(org.elasticsearch.index.query.MultiMatchQueryBuilder) SearchKeywordDTO(io.openk9.plugin.driver.manager.model.SearchKeywordDTO)

Example 9 with PluginDriverDTO

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);
    });
}
Also used : ObjectNode(io.openk9.json.api.ObjectNode) JsonNode(io.openk9.json.api.JsonNode)

Example 10 with PluginDriverDTO

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);
}
Also used : PluginDriverDTO(io.openk9.plugin.driver.manager.model.PluginDriverDTO) FieldBoostDTO(io.openk9.plugin.driver.manager.model.FieldBoostDTO) Predicate(java.util.function.Predicate) Collection(java.util.Collection) DocumentTypeDTO(io.openk9.plugin.driver.manager.model.DocumentTypeDTO) Mono(reactor.core.publisher.Mono) HashMap(java.util.HashMap) QueryParser(io.openk9.search.api.query.QueryParser) QueryBuilders(org.elasticsearch.index.query.QueryBuilders) SearchKeywordDTO(io.openk9.plugin.driver.manager.model.SearchKeywordDTO) SearchToken(io.openk9.search.api.query.SearchToken) Collectors(java.util.stream.Collectors) Consumer(java.util.function.Consumer) Component(org.osgi.service.component.annotations.Component) List(java.util.List) Map(java.util.Map) MultiMatchQueryBuilder(org.elasticsearch.index.query.MultiMatchQueryBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) Collection(java.util.Collection) MultiMatchQueryBuilder(org.elasticsearch.index.query.MultiMatchQueryBuilder) SearchKeywordDTO(io.openk9.plugin.driver.manager.model.SearchKeywordDTO)

Aggregations

PluginDriverDTO (io.openk9.plugin.driver.manager.model.PluginDriverDTO)10 Collection (java.util.Collection)9 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)8 SearchKeywordDTO (io.openk9.plugin.driver.manager.model.SearchKeywordDTO)7 List (java.util.List)7 Map (java.util.Map)7 Component (org.osgi.service.component.annotations.Component)7 Mono (reactor.core.publisher.Mono)7 ObjectNode (io.openk9.json.api.ObjectNode)6 Datasource (io.openk9.model.Datasource)6 DocumentTypeDTO (io.openk9.plugin.driver.manager.model.DocumentTypeDTO)6 Collectors (java.util.stream.Collectors)6 QueryBuilders (org.elasticsearch.index.query.QueryBuilders)6 JsonNode (io.openk9.json.api.JsonNode)5 PluginDriverManagerClient (io.openk9.plugin.driver.manager.client.api.PluginDriverManagerClient)5 QueryParser (io.openk9.search.api.query.QueryParser)5 HashMap (java.util.HashMap)5 DatasourceClient (io.openk9.datasource.client.api.DatasourceClient)4 RouterHandler (io.openk9.http.web.RouterHandler)4 JsonFactory (io.openk9.json.api.JsonFactory)4