geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ash...@apache.org
Subject [3/3] incubator-geode git commit: GEODE-11: Use ResultCollector in LuceneFunction
Date Fri, 04 Sep 2015 21:15:24 GMT
GEODE-11: Use ResultCollector in LuceneFunction

Shards will not use LuceneQueryResults object to send result to coordinator.
Replace this dependency with EntryScore and related objects.


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/a0155ef9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/a0155ef9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/a0155ef9

Branch: refs/heads/feature/GEODE-11
Commit: a0155ef9757f0dddca4326f27ec5d76ee123032f
Parents: 240b39b
Author: Ashvin Agrawal <ashvin@apache.org>
Authored: Fri Sep 4 14:10:04 2015 -0700
Committer: Ashvin Agrawal <ashvin@apache.org>
Committed: Fri Sep 4 14:14:00 2015 -0700

----------------------------------------------------------------------
 .../distributed/LuceneQueryFunction.java        | 45 +++++++-------------
 .../LuceneQueryFunctionJUnitTest.java           | 36 +++++++---------
 2 files changed, 32 insertions(+), 49 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/a0155ef9/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/distributed/LuceneQueryFunction.java
----------------------------------------------------------------------
diff --git a/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/distributed/LuceneQueryFunction.java
b/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/distributed/LuceneQueryFunction.java
index 6f59329..9b494e0 100644
--- a/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/distributed/LuceneQueryFunction.java
+++ b/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/distributed/LuceneQueryFunction.java
@@ -3,7 +3,6 @@ package com.gemstone.gemfire.cache.lucene.internal.distributed;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.List;
 import java.util.Set;
 
 import org.apache.logging.log4j.Logger;
@@ -13,10 +12,6 @@ import com.gemstone.gemfire.cache.execute.FunctionAdapter;
 import com.gemstone.gemfire.cache.execute.FunctionContext;
 import com.gemstone.gemfire.cache.execute.RegionFunctionContext;
 import com.gemstone.gemfire.cache.execute.ResultSender;
-import com.gemstone.gemfire.cache.lucene.LuceneQueryResults;
-import com.gemstone.gemfire.cache.lucene.internal.LuceneQueryResultsImpl;
-import com.gemstone.gemfire.cache.lucene.internal.LuceneResultStructImpl;
-import com.gemstone.gemfire.cache.lucene.internal.mergers.TopDocsResultMerger;
 import com.gemstone.gemfire.cache.lucene.internal.repository.IndexRepository;
 import com.gemstone.gemfire.cache.lucene.internal.repository.IndexResultCollector;
 import com.gemstone.gemfire.cache.lucene.internal.repository.RepositoryManager;
@@ -39,7 +34,7 @@ public class LuceneQueryFunction extends FunctionAdapter {
   @Override
   public void execute(FunctionContext context) {
     RegionFunctionContext ctx = (RegionFunctionContext) context;
-    ResultSender<LuceneQueryResults> resultSender = ctx.getResultSender();
+    ResultSender<TopEntries> resultSender = ctx.getResultSender();
 
     Region region = ctx.getDataSet();
     if (logger.isDebugEnabled()) {
@@ -47,16 +42,18 @@ public class LuceneQueryFunction extends FunctionAdapter {
     }
 
     LuceneSearchFunctionArgs args = (LuceneSearchFunctionArgs) ctx.getArguments();
-    Set<Integer> buckets = args == null ? null : args.getBuckets();
+    Set<Integer> buckets = (args == null ? null : args.getBuckets());
 
-    List<LuceneQueryResults> results = new ArrayList<>();
+    CollectorManager<TopEntries, TopEntriesCollector> manager = new TopEntriesCollectorManager();
+
+    Collection<IndexResultCollector> results = new ArrayList<>();
     try {
       Collection<IndexRepository> repositories = repoManager.getRepositories(region,
buckets);
       for (IndexRepository repo : repositories) {
-        ShardResultCollector collector = new ShardResultCollector();
-        logger.debug("Executing search on repo: " + repo);
+        TopEntriesCollector collector = manager.newCollector(repo.toString());
+        logger.debug("Executing search on repo: " + repo.toString());
         repo.query(null, 0, collector);
-        results.add(collector.getResult());
+        results.add(collector);
       }
     } catch (IOException e) {
       logger.warn("", e);
@@ -68,24 +65,14 @@ public class LuceneQueryFunction extends FunctionAdapter {
       return;
     }
 
-    TopDocsResultMerger merger = new TopDocsResultMerger();
-    LuceneQueryResults merged = merger.mergeResults(results);
-    resultSender.lastResult(merged);
-  }
-
-  /**
-   * Collects and merges results from {@link IndexRepository}s
-   */
-  class ShardResultCollector implements IndexResultCollector {
-    LuceneQueryResultsImpl result = new LuceneQueryResultsImpl();
-    
-    @Override
-    public void collect(Object key, float score) {
-      result.addHit(new LuceneResultStructImpl(key, score));
-    }
-
-    public LuceneQueryResults getResult() {
-      return result;
+    TopEntries mergedResult;
+    try {
+      mergedResult = manager.reduce(results);
+      resultSender.lastResult(mergedResult);
+    } catch (IOException e) {
+      logger.warn("", e);
+      resultSender.sendException(e);
+      return;
     }
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/a0155ef9/gemfire-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/distributed/LuceneQueryFunctionJUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/distributed/LuceneQueryFunctionJUnitTest.java
b/gemfire-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/distributed/LuceneQueryFunctionJUnitTest.java
index 94e088f..069ca90 100644
--- a/gemfire-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/distributed/LuceneQueryFunctionJUnitTest.java
+++ b/gemfire-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/distributed/LuceneQueryFunctionJUnitTest.java
@@ -22,10 +22,6 @@ import org.junit.experimental.categories.Category;
 import com.gemstone.gemfire.cache.Region;
 import com.gemstone.gemfire.cache.execute.RegionFunctionContext;
 import com.gemstone.gemfire.cache.execute.ResultSender;
-import com.gemstone.gemfire.cache.lucene.LuceneQueryResults;
-import com.gemstone.gemfire.cache.lucene.LuceneResultStruct;
-import com.gemstone.gemfire.cache.lucene.internal.LuceneResultStructImpl;
-import com.gemstone.gemfire.cache.lucene.internal.mergers.TopDocsMergeJUnitTest;
 import com.gemstone.gemfire.cache.lucene.internal.repository.IndexRepository;
 import com.gemstone.gemfire.cache.lucene.internal.repository.IndexResultCollector;
 import com.gemstone.gemfire.cache.lucene.internal.repository.RepositoryManager;
@@ -38,13 +34,13 @@ public class LuceneQueryFunctionJUnitTest {
 
   @Test
   public void testRepoQueryAndMerge() throws Exception {
-    final LuceneResultStructImpl r1_1 = new LuceneResultStructImpl("key-1-1", .5f);
-    final LuceneResultStructImpl r1_2 = new LuceneResultStructImpl("key-1-2", .4f);
-    final LuceneResultStructImpl r1_3 = new LuceneResultStructImpl("key-1-3", .3f);
-    final LuceneResultStructImpl r2_1 = new LuceneResultStructImpl("key-2-1", .45f);
-    final LuceneResultStructImpl r2_2 = new LuceneResultStructImpl("key-2-2", .35f);
+    final EntryScore r1_1 = new EntryScore("key-1-1", .5f);
+    final EntryScore r1_2 = new EntryScore("key-1-2", .4f);
+    final EntryScore r1_3 = new EntryScore("key-1-3", .3f);
+    final EntryScore r2_1 = new EntryScore("key-2-1", .45f);
+    final EntryScore r2_2 = new EntryScore("key-2-2", .35f);
 
-    final AtomicReference<LuceneQueryResults> result = new AtomicReference<>();
+    final AtomicReference<TopEntries> result = new AtomicReference<>();
 
     final QueryMocks m = new QueryMocks();
     mocker.checking(new Expectations() {
@@ -65,9 +61,9 @@ public class LuceneQueryFunctionJUnitTest {
           @Override
           public Object invoke(Invocation invocation) throws Throwable {
             IndexResultCollector collector = (IndexResultCollector) invocation.getParameter(2);
-            collector.collect(r1_1.getKey(), r1_1.getScore());
-            collector.collect(r1_2.getKey(), r1_2.getScore());
-            collector.collect(r1_3.getKey(), r1_3.getScore());
+            collector.collect(r1_1.key, r1_1.score);
+            collector.collect(r1_2.key, r1_2.score);
+            collector.collect(r1_3.key, r1_3.score);
             return null;
           }
         });
@@ -77,17 +73,17 @@ public class LuceneQueryFunctionJUnitTest {
           @Override
           public Object invoke(Invocation invocation) throws Throwable {
             IndexResultCollector collector = (IndexResultCollector) invocation.getParameter(2);
-            collector.collect(r2_1.getKey(), r2_1.getScore());
-            collector.collect(r2_2.getKey(), r2_2.getScore());
+            collector.collect(r2_1.key, r2_1.score);
+            collector.collect(r2_2.key, r2_2.score);
             return null;
           }
         });
 
-        oneOf(m.mockResultSender).lastResult(with(any(LuceneQueryResults.class)));
+        oneOf(m.mockResultSender).lastResult(with(any(TopEntries.class)));
         will(new CustomAction("collectResult") {
           @Override
           public Object invoke(Invocation invocation) throws Throwable {
-            result.set((LuceneQueryResults) invocation.getParameter(0));
+            result.set((TopEntries) invocation.getParameter(0));
             return null;
           }
         });
@@ -98,9 +94,9 @@ public class LuceneQueryFunctionJUnitTest {
     function.setRepositoryManager(m.mockRepoManager);
 
     function.execute(m.mockContext);
-    List<LuceneResultStruct> hits = result.get().getHits();
+    List<EntryScore> hits = result.get().getHits();
     assertEquals(5, hits.size());
-    TopDocsMergeJUnitTest.verifyResultOrder(result.get(), r1_1, r2_1, r1_2, r2_2, r1_3);
+    TopEntriesJUnitTest.verifyResultOrder(result.get().getHits(), r1_1, r2_1, r1_2, r2_2,
r1_3);
   }
 
   @Test
@@ -164,7 +160,7 @@ public class LuceneQueryFunctionJUnitTest {
 
   class QueryMocks {
     RegionFunctionContext mockContext = mocker.mock(RegionFunctionContext.class);
-    ResultSender<LuceneQueryResults> mockResultSender = mocker.mock(ResultSender.class);
+    ResultSender<TopEntries> mockResultSender = mocker.mock(ResultSender.class);
     Region<Object, Object> mockRegion = mocker.mock(Region.class);
 
     RepositoryManager mockRepoManager = mocker.mock(RepositoryManager.class);


Mime
View raw message