use of com.rbmhtechnology.vind.elasticsearch.backend.util.DocumentUtil in project vind by RBMHTechnology.
the class ElasticSearchServer method execute.
@Override
public InverseSearchResult execute(InverseSearch inverseSearch, DocumentFactory documentFactory) {
final StopWatch elapsedtime = StopWatch.createStarted();
final List<Map<String, Object>> mapDocs = inverseSearch.getDocs().parallelStream().map(DocumentUtil::createInputDocument).collect(Collectors.toList());
final QueryBuilder query = ElasticQueryBuilder.buildFilterQuery(inverseSearch.getQueryFilter(), documentFactory, null, currentFootprint);
// query
try {
elasticClientLogger.debug(">>> query({})", query.toString());
// TODO: inverse search support multiple docs
final SearchResponse response = elasticSearchClient.percolatorDocQuery(mapDocs, query);
if (Objects.nonNull(response) && Objects.nonNull(response.getHits()) && Objects.nonNull(response.getHits().getHits())) {
final List<InverseSearchQuery> resultQueries = Arrays.stream(response.getHits().getHits()).map(hit -> DocumentUtil.buildVindDoc(hit, InverseSearchQueryFactory.getQueryFactory(), null)).map(doc -> documentFactory.createInverseSearchQuery(doc.getId(), deserializeByteArrayFilter(((ByteBuffer) doc.getValue(InverseSearchQueryFactory.BINARY_QUERY_FIELD)).array()))).collect(Collectors.toList());
elapsedtime.stop();
final long totalHits = response.getHits().getTotalHits().value;
switch(inverseSearch.getResultSet().getType()) {
case page:
{
return new InverseSearchPageResult(totalHits, response.getTook().getMillis(), resultQueries, inverseSearch, this, documentFactory).setElapsedTime(elapsedtime.getTime());
}
case slice:
{
return new InverseSearchSliceResult(totalHits, response.getTook().getMillis(), resultQueries, inverseSearch, this, documentFactory).setElapsedTime(elapsedtime.getTime());
}
default:
return new InverseSearchPageResult(totalHits, response.getTook().getMillis(), resultQueries, inverseSearch, this, documentFactory).setElapsedTime(elapsedtime.getTime());
}
} else {
throw new ElasticsearchException("Empty result from ElasticClient");
}
} catch (ElasticsearchException | IOException e) {
throw new SearchServerException(String.format("Cannot issue inverse search: %s", e.getMessage()), e);
}
}
Aggregations