incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amccu...@apache.org
Subject git commit: Fix to the shardIndex in the TopFieldDocs object.
Date Tue, 30 Oct 2012 13:44:33 GMT
Updated Branches:
  refs/heads/0.2-dev afaa6c403 -> fdfd698a2


Fix to the shardIndex in the TopFieldDocs object.


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

Branch: refs/heads/0.2-dev
Commit: fdfd698a2c45aed55bf4d8d8af91f9a80427157b
Parents: afaa6c4
Author: Aaron McCurry <amccurry@gmail.com>
Authored: Tue Oct 30 09:44:06 2012 -0400
Committer: Aaron McCurry <amccurry@gmail.com>
Committed: Tue Oct 30 09:44:06 2012 -0400

----------------------------------------------------------------------
 .../org/apache/blur/thrift/BlurShardServer.java    |   55 ++++++++++++---
 1 files changed, 45 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/fdfd698a/src/blur-core/src/main/java/org/apache/blur/thrift/BlurShardServer.java
----------------------------------------------------------------------
diff --git a/src/blur-core/src/main/java/org/apache/blur/thrift/BlurShardServer.java b/src/blur-core/src/main/java/org/apache/blur/thrift/BlurShardServer.java
index 1cfb9d4..1085579 100644
--- a/src/blur-core/src/main/java/org/apache/blur/thrift/BlurShardServer.java
+++ b/src/blur-core/src/main/java/org/apache/blur/thrift/BlurShardServer.java
@@ -22,6 +22,7 @@ import static org.apache.blur.utils.BlurConstants.BLUR_SHARD_DATA_FETCH_THREAD_C
 
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
@@ -403,7 +404,7 @@ public class BlurShardServer extends TableAdmin implements Iface {
     try {
       Map<Integer, IndexSearcher> searchers = info.getSearchers();
       List<Integer> shardIndexes = queryArgs.getShardIndexes();
-      List<IndexSearcher> searchersToSearch = getSearchers(shardIndexes, searchers);
+      Collection<Entry<Integer, IndexSearcher>> searchersToSearch = getSearchers(shardIndexes,
searchers);
 
       List<Future<TopFieldDocs>> futures = new ArrayList<Future<TopFieldDocs>>(searchersToSearch.size());
       Query query = BlurUtil.getQuery(queryArgs);
@@ -413,8 +414,9 @@ public class BlurShardServer extends TableAdmin implements Iface {
       boolean doDocScores = queryArgs.isDoDocScores();
       boolean doMaxScore = queryArgs.isDoMaxScore();
       int numberToFetch = queryArgs.getNumberToFetch();
-      for (IndexSearcher searcher : searchersToSearch) {
-        Future<TopFieldDocs> future = _searchExecutor.submit(new SearchCallable(searcher,
after, query, filter, sort, numberToFetch, doDocScores, doMaxScore));
+      for (Entry<Integer, IndexSearcher> entry : searchersToSearch) {
+        Future<TopFieldDocs> future = _indexSearcherExecutor.submit(new SearchCallable(entry.getKey(),
entry.getValue(), after, query, filter, sort, numberToFetch, doDocScores,
+            doMaxScore));
         futures.add(future);
       }
 
@@ -438,8 +440,9 @@ public class BlurShardServer extends TableAdmin implements Iface {
     private final int count;
     private final boolean doDocScores;
     private final boolean doMaxScore;
+    private final int shardIndex;
 
-    SearchCallable(IndexSearcher searcher, ScoreDoc after, Query query, Filter filter, Sort
sort, int count, boolean doDocScores, boolean doMaxScore) {
+    SearchCallable(int shardIndex, IndexSearcher searcher, ScoreDoc after, Query query, Filter
filter, Sort sort, int count, boolean doDocScores, boolean doMaxScore) {
       this.after = after;
       this.searcher = searcher;
       this.query = query;
@@ -448,10 +451,25 @@ public class BlurShardServer extends TableAdmin implements Iface {
       this.count = count;
       this.doDocScores = doDocScores;
       this.doMaxScore = doMaxScore;
+      this.shardIndex = shardIndex;
     }
 
     @Override
     public TopFieldDocs call() throws Exception {
+      return addShardIndex(doSearch());
+    }
+
+    private TopFieldDocs addShardIndex(TopFieldDocs topFieldDocs) {
+      topFieldDocs.setShardIndex(shardIndex);
+      List<org.apache.blur.thrift.generated.ScoreDoc> scoreDocs = topFieldDocs.getScoreDocs();
+      for (org.apache.blur.thrift.generated.ScoreDoc sd : scoreDocs) {
+        DocLocation docLocation = sd.getDocLocation();
+        docLocation.setShardIndex(shardIndex);
+      }
+      return topFieldDocs;
+    }
+
+    private TopFieldDocs doSearch() throws IOException {
       if (after == null) {
         if (sort == null) {
           return BlurUtil.convert(searcher.search(query, filter, count));
@@ -468,16 +486,33 @@ public class BlurShardServer extends TableAdmin implements Iface {
     }
   }
 
-  private List<IndexSearcher> getSearchers(List<Integer> shardIndexes, Map<Integer,
IndexSearcher> searchers) {
-    List<IndexSearcher> searchersToSearch = new ArrayList<IndexSearcher>();
+  private Collection<Entry<Integer, IndexSearcher>> getSearchers(List<Integer>
shardIndexes, Map<Integer, IndexSearcher> searchers) {
+    Collection<Entry<Integer, IndexSearcher>> searchersToSearch = new ArrayList<Map.Entry<Integer,
IndexSearcher>>();
     if (shardIndexes == null) {
       // all indexes
-      searchersToSearch.addAll(searchers.values());
+      searchersToSearch.addAll(searchers.entrySet());
     } else {
-      for (Integer index : shardIndexes) {
-        IndexSearcher searcher = searchers.get(index);
+      for (Integer i : shardIndexes) {
+        final Integer index = i;
+        final IndexSearcher searcher = searchers.get(index);
         if (searcher != null) {
-          searchersToSearch.add(searcher);
+          searchersToSearch.add(new Entry<Integer, IndexSearcher>() {
+
+            @Override
+            public IndexSearcher setValue(IndexSearcher value) {
+              throw new RuntimeException("Not Supported");
+            }
+
+            @Override
+            public IndexSearcher getValue() {
+              return searcher;
+            }
+
+            @Override
+            public Integer getKey() {
+              return index;
+            }
+          });
         }
       }
     }


Mime
View raw message