add getTook method to search result

This commit is contained in:
Jörg Prante 2021-06-08 11:41:16 +02:00
parent 2701c2b11d
commit db6d67a91a
4 changed files with 16 additions and 4 deletions

View file

@ -6,5 +6,7 @@ public interface SearchResult {
long getTotal();
long getTook();
List<SearchDocument> getDocuments();
}

View file

@ -165,7 +165,7 @@ public abstract class AbstractSearchClient extends AbstractBasicClient implement
}
return isempty ?
Optional.empty() :
Optional.of(new DefaultSearchResult(searchResponse.getHits()));
Optional.of(new DefaultSearchResult(searchResponse.getHits(), searchResponse.getTook().getMillis()));
}
@Override
@ -248,7 +248,8 @@ public abstract class AbstractSearchClient extends AbstractBasicClient implement
return StreamSupport.stream(TakeWhileSpliterator.over(responseStream.spliterator(),
condition, lastAction), false)
.onClose(responseStream::close)
.flatMap(searchResponse -> new DefaultSearchResult(searchResponse.getHits()).getDocuments().stream());
.flatMap(searchResponse ->
new DefaultSearchResult(searchResponse.getHits(), searchResponse.getTook().getMillis()).getDocuments().stream());
}
@Override

View file

@ -12,14 +12,23 @@ public class DefaultSearchResult implements SearchResult {
private final SearchHits searchHits;
public DefaultSearchResult(SearchHits searchHits) {
private final long took;
public DefaultSearchResult(SearchHits searchHits, long took) {
this.searchHits = searchHits;
this.took = took;
}
@Override
public long getTotal() {
return searchHits.getTotalHits().value;
}
@Override
public long getTook() {
return took;
}
@Override
public List<SearchDocument> getDocuments() {
List<SearchDocument> list = new ArrayList<>();

View file

@ -1,6 +1,6 @@
group = org.xbib
name = elx
version = 7.10.2.13
version = 7.10.2.14
gradle.wrapper.version = 6.6.1
xbib-metrics.version = 2.2.0