GEODE-11: Apply limit in FunctionResultCollector The SearchResultCollector needs to pass on contraints provided in function search context to sub-components. One of the sub-components is reducer which will trim the results as needed.
Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/02d56eb9 Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/02d56eb9 Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/02d56eb9 Branch: refs/heads/feature/GEODE-11 Commit: 02d56eb904ed0f37e62830189ea7c4ba750c3d7f Parents: 7160e88 Author: Ashvin Agrawal <[email protected]> Authored: Fri Sep 11 16:35:49 2015 -0700 Committer: Ashvin Agrawal <[email protected]> Committed: Fri Sep 11 16:35:49 2015 -0700 ---------------------------------------------------------------------- .../internal/distributed/LuceneFunctionContext.java | 9 ++++++++- .../distributed/TopEntriesFunctionCollector.java | 8 +++++--- .../TopEntriesFunctionCollectorJUnitTest.java | 15 +++++++++++++++ 3 files changed, 28 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/02d56eb9/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/distributed/LuceneFunctionContext.java ---------------------------------------------------------------------- diff --git a/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/distributed/LuceneFunctionContext.java b/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/distributed/LuceneFunctionContext.java index 170bb65..b3a613f 100644 --- a/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/distributed/LuceneFunctionContext.java +++ b/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/distributed/LuceneFunctionContext.java @@ -16,9 +16,16 @@ import com.gemstone.gemfire.internal.VersionedDataSerializable; public class LuceneFunctionContext<C extends IndexResultCollector> implements VersionedDataSerializable { private static final long serialVersionUID = 1L; private final CollectorManager<C> manager; + private final int limit; public LuceneFunctionContext(CollectorManager<C> manager) { this.manager = manager; + this.limit = LuceneQueryFactory.DEFAULT_LIMIT; + } + + public LuceneFunctionContext(int limit) { + this.limit = limit; + this.manager = null; } @Override @@ -43,7 +50,7 @@ public class LuceneFunctionContext<C extends IndexResultCollector> implements Ve * @return The maximum count of result objects to be produced by the function */ public int getLimit() { - return LuceneQueryFactory.DEFAULT_LIMIT; + return limit; } /** http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/02d56eb9/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/distributed/TopEntriesFunctionCollector.java ---------------------------------------------------------------------- diff --git a/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/distributed/TopEntriesFunctionCollector.java b/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/distributed/TopEntriesFunctionCollector.java index 0bb36cf..26586d9 100644 --- a/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/distributed/TopEntriesFunctionCollector.java +++ b/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/distributed/TopEntriesFunctionCollector.java @@ -45,18 +45,20 @@ public class TopEntriesFunctionCollector implements ResultCollector<TopEntriesCo this(null, null); } - public TopEntriesFunctionCollector(LuceneFunctionContext context) { + public TopEntriesFunctionCollector(LuceneFunctionContext<TopEntriesCollector> context) { this(context, null); } - public TopEntriesFunctionCollector(LuceneFunctionContext context, GemFireCacheImpl cache) { + public TopEntriesFunctionCollector(LuceneFunctionContext<TopEntriesCollector> context, GemFireCacheImpl cache) { this.cache = cache; id = cache == null ? String.valueOf(this.hashCode()) : cache.getName(); + int limit = context == null ? 0 : context.getLimit(); + if (context != null && context.getCollectorManager() != null) { this.manager = context.getCollectorManager(); } else { - this.manager = new TopEntriesCollectorManager(id); + this.manager = new TopEntriesCollectorManager(id, limit); } } http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/02d56eb9/gemfire-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/distributed/TopEntriesFunctionCollectorJUnitTest.java ---------------------------------------------------------------------- diff --git a/gemfire-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/distributed/TopEntriesFunctionCollectorJUnitTest.java b/gemfire-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/distributed/TopEntriesFunctionCollectorJUnitTest.java index 17cee85..d45865d 100644 --- a/gemfire-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/distributed/TopEntriesFunctionCollectorJUnitTest.java +++ b/gemfire-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/distributed/TopEntriesFunctionCollectorJUnitTest.java @@ -183,6 +183,21 @@ public class TopEntriesFunctionCollectorJUnitTest { } @Test + public void mergeShardAndLimitResults() throws Exception { + LuceneFunctionContext<TopEntriesCollector> context = new LuceneFunctionContext<>(3); + + TopEntriesFunctionCollector collector = new TopEntriesFunctionCollector(context); + collector.addResult(null, result1); + collector.addResult(null, result2); + collector.endResults(); + + TopEntries merged = collector.getResult(); + Assert.assertNotNull(merged); + assertEquals(3, merged.size()); + TopEntriesJUnitTest.verifyResultOrder(merged.getHits(), r1_1, r2_1, r1_2); + } + + @Test public void mergeResultsDefaultCollectorManager() throws Exception { TopEntriesFunctionCollector collector = new TopEntriesFunctionCollector(); collector.addResult(null, result1);
