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