incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amccu...@apache.org
Subject [12/27] git commit: Refactoring some code.
Date Mon, 29 Jul 2013 12:57:43 GMT
Refactoring some code.


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

Branch: refs/heads/0.2.0-newtypesystem
Commit: 9c34b27b737daa4afb832dcc8c03b265b06f5fd4
Parents: 17aa07d
Author: Aaron McCurry <amccurry@gmail.com>
Authored: Tue Jul 23 13:19:04 2013 -0400
Committer: Aaron McCurry <amccurry@gmail.com>
Committed: Tue Jul 23 13:19:04 2013 -0400

----------------------------------------------------------------------
 .../indexserver/AbstractIndexServer.java        | 31 ++------------------
 .../apache/blur/manager/writer/BlurIndex.java   | 30 +++++++++++++++++++
 .../blur/manager/writer/BlurIndexReader.java    |  1 -
 3 files changed, 32 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/9c34b27b/blur-core/src/main/java/org/apache/blur/manager/indexserver/AbstractIndexServer.java
----------------------------------------------------------------------
diff --git a/blur-core/src/main/java/org/apache/blur/manager/indexserver/AbstractIndexServer.java
b/blur-core/src/main/java/org/apache/blur/manager/indexserver/AbstractIndexServer.java
index db1599c..e183a0b 100644
--- a/blur-core/src/main/java/org/apache/blur/manager/indexserver/AbstractIndexServer.java
+++ b/blur-core/src/main/java/org/apache/blur/manager/indexserver/AbstractIndexServer.java
@@ -21,12 +21,6 @@ import java.util.Map;
 
 import org.apache.blur.manager.IndexServer;
 import org.apache.blur.manager.writer.BlurIndex;
-import org.apache.blur.server.IndexSearcherClosable;
-import org.apache.blur.utils.BlurUtil;
-import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.search.IndexSearcher;
-import org.apache.lucene.search.TermQuery;
-import org.apache.lucene.search.TopDocs;
 
 public abstract class AbstractIndexServer implements IndexServer {
 
@@ -34,15 +28,7 @@ public abstract class AbstractIndexServer implements IndexServer {
     long recordCount = 0;
     Map<String, BlurIndex> indexes = getIndexes(table);
     for (Map.Entry<String, BlurIndex> index : indexes.entrySet()) {
-      IndexSearcherClosable searcher = null;
-      try {
-        searcher = index.getValue().getIndexReader();
-        recordCount += searcher.getIndexReader().numDocs();
-      } finally {
-        if (searcher != null) {
-          searcher.close();
-        }
-      }
+      recordCount += index.getValue().getRecordCount();
     }
     return recordCount;
   }
@@ -51,22 +37,9 @@ public abstract class AbstractIndexServer implements IndexServer {
     long rowCount = 0;
     Map<String, BlurIndex> indexes = getIndexes(table);
     for (Map.Entry<String, BlurIndex> index : indexes.entrySet()) {
-      IndexSearcherClosable searcher = null;
-      try {
-        searcher = index.getValue().getIndexReader();
-        rowCount += getRowCount(searcher.getIndexReader());
-      } finally {
-        if (searcher != null) {
-          searcher.close();
-        }
-      }
+      rowCount += index.getValue().getRowCount();
     }
     return rowCount;
   }
 
-  private long getRowCount(IndexReader indexReader) throws IOException {
-    IndexSearcher searcher = new IndexSearcher(indexReader);
-    TopDocs topDocs = searcher.search(new TermQuery(BlurUtil.PRIME_DOC_TERM), 1);
-    return topDocs.totalHits;
-  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/9c34b27b/blur-core/src/main/java/org/apache/blur/manager/writer/BlurIndex.java
----------------------------------------------------------------------
diff --git a/blur-core/src/main/java/org/apache/blur/manager/writer/BlurIndex.java b/blur-core/src/main/java/org/apache/blur/manager/writer/BlurIndex.java
index 23c3241..90f5c96 100644
--- a/blur-core/src/main/java/org/apache/blur/manager/writer/BlurIndex.java
+++ b/blur-core/src/main/java/org/apache/blur/manager/writer/BlurIndex.java
@@ -21,6 +21,10 @@ import java.util.concurrent.atomic.AtomicBoolean;
 
 import org.apache.blur.server.IndexSearcherClosable;
 import org.apache.blur.thrift.generated.Row;
+import org.apache.blur.utils.BlurUtil;
+import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.TermQuery;
+import org.apache.lucene.search.TopDocs;
 
 public abstract class BlurIndex {
 
@@ -38,5 +42,31 @@ public abstract class BlurIndex {
 
   public abstract void optimize(int numberOfSegmentsPerShard) throws IOException;
 
+  public long getRecordCount() throws IOException {
+    IndexSearcherClosable searcher = getIndexReader();
+    try {
+      return searcher.getIndexReader().numDocs();
+    } finally {
+      if (searcher != null) {
+        searcher.close();
+      }
+    }
+  }
+
+  public long getRowCount() throws IOException {
+    IndexSearcherClosable searcher = getIndexReader();
+    try {
+      return getRowCount(searcher);
+    } finally {
+      if (searcher != null) {
+        searcher.close();
+      }
+    }
+  }
+
+  protected long getRowCount(IndexSearcher searcher) throws IOException {
+    TopDocs topDocs = searcher.search(new TermQuery(BlurUtil.PRIME_DOC_TERM), 1);
+    return topDocs.totalHits;
+  }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/9c34b27b/blur-core/src/main/java/org/apache/blur/manager/writer/BlurIndexReader.java
----------------------------------------------------------------------
diff --git a/blur-core/src/main/java/org/apache/blur/manager/writer/BlurIndexReader.java b/blur-core/src/main/java/org/apache/blur/manager/writer/BlurIndexReader.java
index e2e3bf6..6d90990 100644
--- a/blur-core/src/main/java/org/apache/blur/manager/writer/BlurIndexReader.java
+++ b/blur-core/src/main/java/org/apache/blur/manager/writer/BlurIndexReader.java
@@ -129,5 +129,4 @@ public class BlurIndexReader extends BlurIndex {
   public AtomicBoolean isClosed() {
     return _isClosed;
   }
-
 }


Mime
View raw message