You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by ro...@apache.org on 2017/01/11 16:45:48 UTC
[21/22] james-project git commit: JAMES-1894 Optimization in ES : If
the limit is less than the batch size, we don't need to do a full batch
JAMES-1894 Optimization in ES : If the limit is less than the batch size, we don't need to do a full batch
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/f6bc8bec
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/f6bc8bec
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/f6bc8bec
Branch: refs/heads/master
Commit: f6bc8bec71c14a83288676550e92ec019641c8c3
Parents: 4dec966
Author: Benoit Tellier <bt...@linagora.com>
Authored: Fri Dec 23 11:10:08 2016 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Mon Jan 9 22:01:07 2017 +0700
----------------------------------------------------------------------
.../elasticsearch/search/ElasticSearchSearcher.java | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/f6bc8bec/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/search/ElasticSearchSearcher.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/search/ElasticSearchSearcher.java b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/search/ElasticSearchSearcher.java
index e508e7d..20ab38d 100644
--- a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/search/ElasticSearchSearcher.java
+++ b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/search/ElasticSearchSearcher.java
@@ -74,13 +74,13 @@ public class ElasticSearchSearcher {
}
public Stream<MessageSearchIndex.SearchResult> search(List<User> users, MultimailboxesSearchQuery query, Optional<Long> limit) throws MailboxException {
- Stream<MessageSearchIndex.SearchResult> pairStream = new ScrollIterable(client, getSearchRequestBuilder(client, users, query)).stream()
+ Stream<MessageSearchIndex.SearchResult> pairStream = new ScrollIterable(client, getSearchRequestBuilder(client, users, query, limit)).stream()
.flatMap(this::transformResponseToUidStream);
return limit.map(pairStream::limit)
.orElse(pairStream);
}
- private SearchRequestBuilder getSearchRequestBuilder(Client client, List<User> users, MultimailboxesSearchQuery query) {
+ private SearchRequestBuilder getSearchRequestBuilder(Client client, List<User> users, MultimailboxesSearchQuery query, Optional<Long> limit) {
return query.getSearchQuery().getSorts()
.stream()
.reduce(
@@ -89,11 +89,16 @@ public class ElasticSearchSearcher {
.setScroll(TIMEOUT)
.addFields(JsonMessageConstants.UID, JsonMessageConstants.MAILBOX_ID, JsonMessageConstants.MESSAGE_ID)
.setQuery(queryConverter.from(users, query))
- .setSize(size),
+ .setSize(computeRequiredSize(limit)),
(searchBuilder, sort) -> searchBuilder.addSort(SortConverter.convertSort(sort)),
(partialResult1, partialResult2) -> partialResult1);
}
+ private int computeRequiredSize(Optional<Long> limit) {
+ return limit.map(value -> Math.min(value.intValue(), size))
+ .orElse(size);
+ }
+
private Stream<MessageSearchIndex.SearchResult> transformResponseToUidStream(SearchResponse searchResponse) {
return StreamSupport.stream(searchResponse.getHits().spliterator(), false)
.map(this::extractContentFromHit)
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org