From 2ef4a5e84c8ac081e1be88f14f2dbef832e2221b Mon Sep 17 00:00:00 2001 From: kimchy Date: Sat, 28 May 2011 23:14:58 +0300 Subject: [PATCH] fix limit filter to properly handle cross segments cases --- .../elasticsearch/common/lucene/search/LimitFilter.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/search/LimitFilter.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/search/LimitFilter.java index 0f1f222258d..bcfcb038fba 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/search/LimitFilter.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/search/LimitFilter.java @@ -28,6 +28,7 @@ import java.io.IOException; public class LimitFilter extends NoCacheFilter { private final int limit; + private int counter; public LimitFilter(int limit) { this.limit = limit; @@ -38,13 +39,15 @@ public class LimitFilter extends NoCacheFilter { } @Override public DocIdSet getDocIdSet(IndexReader reader) throws IOException { + if (counter > limit) { + return null; + } return new LimitDocSet(reader.maxDoc(), limit); } - public static class LimitDocSet extends GetDocSet { + public class LimitDocSet extends GetDocSet { private final int limit; - private int counter; public LimitDocSet(int maxDoc, int limit) { super(maxDoc);