use of io.kestra.core.models.SearchResult in project kestra by kestra-io.
the class ElasticSearchFlowRepository method findSourceCode.
@Override
public ArrayListTotal<SearchResult<Flow>> findSourceCode(String query, Pageable pageable) {
BoolQueryBuilder bool = this.defaultFilter().must(QueryBuilders.queryStringQuery(query).field("sourceCode"));
SearchSourceBuilder sourceBuilder = this.searchSource(bool, Optional.empty(), pageable);
sourceBuilder.fetchSource("*", "sourceCode");
sourceBuilder.highlighter(new HighlightBuilder().preTags("[mark]").postTags("[/mark]").field("sourceCode"));
SearchRequest searchRequest = searchRequest(INDEX_NAME, sourceBuilder, false);
try {
SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
return new ArrayListTotal<>(Arrays.stream(searchResponse.getHits().getHits()).map(documentFields -> {
try {
return new SearchResult<>(MAPPER.readValue(documentFields.getSourceAsString(), this.cls), documentFields.getHighlightFields().get("sourceCode") != null ? Arrays.stream(documentFields.getHighlightFields().get("sourceCode").getFragments()).map(Text::string).collect(Collectors.toList()) : Collections.emptyList());
} catch (IOException e) {
throw new RuntimeException(e);
}
}).collect(Collectors.toList()), searchResponse.getHits().getTotalHits().value);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
Aggregations