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