Search in sources :

Example 6 with DocumentTypeDTO

use of io.openk9.plugin.driver.manager.model.DocumentTypeDTO 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)

Example 7 with DocumentTypeDTO

use of io.openk9.plugin.driver.manager.model.DocumentTypeDTO in project openk9 by smclab.

the class EnrichPipelineProcessor method _adaptIngestionPayload.

private Tuple3<DatasourceContext, ObjectNode, PluginDriverDTO> _adaptIngestionPayload(DatasourceContext datasourceContext, ObjectNode ingestionPayload, PluginDriverDTO pluginDriverDTO) {
    ObjectNode newIngestionPayload = ingestionPayload;
    if (newIngestionPayload.hasNonNull(io.openk9.core.api.constant.Constants.DATASOURCE_PAYLOAD)) {
        JsonNode datasourcePayload = newIngestionPayload.remove(io.openk9.core.api.constant.Constants.DATASOURCE_PAYLOAD);
        if (datasourcePayload.isObject()) {
            ObjectNode jsonNodes = datasourcePayload.toObjectNode();
            for (Map.Entry<String, JsonNode> field : jsonNodes.fields()) {
                newIngestionPayload.set(field.getKey(), field.getValue());
            }
        }
    }
    if (!ingestionPayload.hasNonNull(Constants.DATASOURCE_NAME)) {
        newIngestionPayload = newIngestionPayload.deepCopy().put(Constants.DATASOURCE_NAME, pluginDriverDTO.getName());
    }
    if (ingestionPayload.hasNonNull(io.openk9.core.api.constant.Constants.TYPE) && !ingestionPayload.get(io.openk9.core.api.constant.Constants.TYPE).toArrayNode().isEmpty()) {
        return Tuples.of(datasourceContext, ingestionPayload, pluginDriverDTO);
    }
    DocumentTypeDTO documentType = pluginDriverDTO.getDefaultDocumentType();
    return Tuples.of(datasourceContext, newIngestionPayload.set(io.openk9.core.api.constant.Constants.TYPE, _jsonFactory.createArrayNode().add(documentType.getName())), pluginDriverDTO);
}
Also used : ObjectNode(io.openk9.json.api.ObjectNode) JsonNode(io.openk9.json.api.JsonNode) Map(java.util.Map) DocumentTypeDTO(io.openk9.plugin.driver.manager.model.DocumentTypeDTO)

Example 8 with DocumentTypeDTO

use of io.openk9.plugin.driver.manager.model.DocumentTypeDTO in project openk9 by smclab.

the class BaseSearchHTTPHandler method customizeSearchSourceBuilder.

protected void customizeSearchSourceBuilder(Tenant tenant, List<Datasource> datasources, SearchRequest searchRequest, List<PluginDriverDTO> documentTypeList, SearchSourceBuilder searchSourceBuilder, org.elasticsearch.action.search.SearchRequest elasticSearchQuery) {
    int[] range = searchRequest.getRange();
    if (range != null) {
        searchSourceBuilder.from(range[0]);
        searchSourceBuilder.size(range[1]);
    }
    HighlightBuilder highlightBuilder = new HighlightBuilder();
    documentTypeList.stream().map(PluginDriverDTO::getDocumentTypes).flatMap(Collection::stream).map(DocumentTypeDTO::getSearchKeywords).flatMap(Collection::stream).filter(SearchKeywordDTO::isText).map(SearchKeywordDTO::getKeyword).distinct().forEach(highlightBuilder::field);
    highlightBuilder.forceSource(true);
    highlightBuilder.tagsSchema("default");
    searchSourceBuilder.highlighter(highlightBuilder);
}
Also used : Collection(java.util.Collection) HighlightBuilder(org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder) SearchKeywordDTO(io.openk9.plugin.driver.manager.model.SearchKeywordDTO)

Example 9 with DocumentTypeDTO

use of io.openk9.plugin.driver.manager.model.DocumentTypeDTO in project openk9 by smclab.

the class PluginDriverDTOServiceImpl method _findDocumentType.

private PluginDriverDTO _findDocumentType(PluginDriver pluginDriver) {
    String name = pluginDriver.getName();
    List<DocumentType> documentTypeList = _documentTypeProvider.getDocumentTypeList(name);
    DocumentType defaultDocumentType = _documentTypeProvider.getDefaultDocumentType(name);
    if (documentTypeList.isEmpty() && defaultDocumentType != null) {
        documentTypeList = List.of(defaultDocumentType);
    } else if (!documentTypeList.isEmpty() && defaultDocumentType == null) {
        defaultDocumentType = documentTypeList.get(0);
    }
    List<DocumentTypeDTO> documentTypeDTOS = documentTypeList.stream().map(documentType -> DocumentTypeDTO.of(documentType.getName(), documentType.getIcon(), _wrapSearchKeywords(documentType))).collect(Collectors.toList());
    return PluginDriverDTO.of(pluginDriver.getDriverServiceName(), pluginDriver.getName(), pluginDriver.schedulerEnabled(), documentTypeDTOS, defaultDocumentType == null ? null : DocumentTypeDTO.of(defaultDocumentType.getName(), defaultDocumentType.getIcon(), _wrapSearchKeywords(defaultDocumentType)));
}
Also used : PluginDriverDTO(io.openk9.plugin.driver.manager.model.PluginDriverDTO) SearchKeyword(io.openk9.plugin.driver.manager.api.SearchKeyword) FieldBoostDTO(io.openk9.plugin.driver.manager.model.FieldBoostDTO) PluginDriverDTOList(io.openk9.plugin.driver.manager.model.PluginDriverDTOList) Collection(java.util.Collection) DocumentTypeDTO(io.openk9.plugin.driver.manager.model.DocumentTypeDTO) PluginDriverDTOService(io.openk9.plugin.driver.manager.api.PluginDriverDTOService) PluginDriverRegistry(io.openk9.plugin.driver.manager.api.PluginDriverRegistry) DocumentType(io.openk9.plugin.driver.manager.api.DocumentType) SearchKeywordDTO(io.openk9.plugin.driver.manager.model.SearchKeywordDTO) Collectors(java.util.stream.Collectors) Component(org.osgi.service.component.annotations.Component) List(java.util.List) Optional(java.util.Optional) PluginDriver(io.openk9.plugin.driver.manager.api.PluginDriver) Reference(org.osgi.service.component.annotations.Reference) DocumentTypeProvider(io.openk9.plugin.driver.manager.api.DocumentTypeProvider) DocumentType(io.openk9.plugin.driver.manager.api.DocumentType) DocumentTypeDTO(io.openk9.plugin.driver.manager.model.DocumentTypeDTO)

Aggregations

Collection (java.util.Collection)7 PluginDriverDTO (io.openk9.plugin.driver.manager.model.PluginDriverDTO)6 SearchKeywordDTO (io.openk9.plugin.driver.manager.model.SearchKeywordDTO)6 DocumentTypeDTO (io.openk9.plugin.driver.manager.model.DocumentTypeDTO)5 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)4 List (java.util.List)3 Map (java.util.Map)3 Collectors (java.util.stream.Collectors)3 Component (org.osgi.service.component.annotations.Component)3 Datasource (io.openk9.model.Datasource)2 FieldBoostDTO (io.openk9.plugin.driver.manager.model.FieldBoostDTO)2 QueryParser (io.openk9.search.api.query.QueryParser)2 SearchToken (io.openk9.search.api.query.SearchToken)2 HashMap (java.util.HashMap)2 Consumer (java.util.function.Consumer)2 MultiMatchQueryBuilder (org.elasticsearch.index.query.MultiMatchQueryBuilder)2 QueryBuilders (org.elasticsearch.index.query.QueryBuilders)2 Mono (reactor.core.publisher.Mono)2 JsonNode (io.openk9.json.api.JsonNode)1 ObjectNode (io.openk9.json.api.ObjectNode)1