incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amccu...@apache.org
Subject [3/8] git commit: Clean up of the paging code.
Date Sun, 31 Mar 2013 01:46:17 GMT
Clean up of the paging 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/4ef6e5ce
Tree: http://git-wip-us.apache.org/repos/asf/incubator-blur/tree/4ef6e5ce
Diff: http://git-wip-us.apache.org/repos/asf/incubator-blur/diff/4ef6e5ce

Branch: refs/heads/0.1.5
Commit: 4ef6e5ce6390a767690d1fa6ca8ccd0a65cbc0b1
Parents: 61b184a
Author: Aaron McCurry <amccurry@gmail.com>
Authored: Sat Mar 30 21:38:59 2013 -0400
Committer: Aaron McCurry <amccurry@gmail.com>
Committed: Sat Mar 30 21:38:59 2013 -0400

----------------------------------------------------------------------
 .../apache/blur/lucene/search/IterablePaging.java  |   37 ++++++---------
 .../apache/blur/lucene/search/PagingCollector.java |   12 ++---
 .../apache/blur/search/TestingPagingCollector.java |    8 ++--
 3 files changed, 23 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/4ef6e5ce/src/blur-core/src/main/java/org/apache/blur/lucene/search/IterablePaging.java
----------------------------------------------------------------------
diff --git a/src/blur-core/src/main/java/org/apache/blur/lucene/search/IterablePaging.java
b/src/blur-core/src/main/java/org/apache/blur/lucene/search/IterablePaging.java
index 4e2cbc5..586b68a 100644
--- a/src/blur-core/src/main/java/org/apache/blur/lucene/search/IterablePaging.java
+++ b/src/blur-core/src/main/java/org/apache/blur/lucene/search/IterablePaging.java
@@ -25,6 +25,7 @@ import java.util.concurrent.atomic.AtomicLong;
 import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.search.Query;
 import org.apache.lucene.search.ScoreDoc;
+import org.apache.lucene.search.TopDocs;
 import org.apache.lucene.search.TopScoreDocCollector;
 
 /**
@@ -32,31 +33,25 @@ import org.apache.lucene.search.TopScoreDocCollector;
  */
 public class IterablePaging implements Iterable<ScoreDoc> {
 
-  private static int DEFAULT_NUMBER_OF_HITS_TO_COLLECT = 1000;
-  private IndexSearcher searcher;
-  private Query query;
-  private TotalHitsRef totalHitsRef = new TotalHitsRef();
-  private ProgressRef progressRef = new ProgressRef();
+  private final IndexSearcher searcher;
+  private final Query query;
+  private final AtomicBoolean running;
+  private final int numHitsToCollect;
+
+  private TotalHitsRef totalHitsRef;
+  private ProgressRef progressRef;
   private int skipTo;
-  private int numHitsToCollect = DEFAULT_NUMBER_OF_HITS_TO_COLLECT;
   private int gather = -1;
-  private AtomicBoolean running;
-
-  public IterablePaging(AtomicBoolean running, IndexSearcher searcher, Query query) throws
IOException {
-    this(running, searcher, query, DEFAULT_NUMBER_OF_HITS_TO_COLLECT, null, null);
-  }
 
-  public IterablePaging(AtomicBoolean running, IndexSearcher searcher, Query query, int numHitsToCollect)
throws IOException {
-    this(running, searcher, query, numHitsToCollect, null, null);
-  }
-
-  public IterablePaging(AtomicBoolean running, IndexSearcher searcher, Query query, int numHitsToCollect,
TotalHitsRef totalHitsRef, ProgressRef progressRef) throws IOException {
+  public IterablePaging(AtomicBoolean running, IndexSearcher searcher, Query query,
+      int numHitsToCollect, TotalHitsRef totalHitsRef, ProgressRef progressRef) throws IOException
{
     this.running = running;
     this.query = searcher.rewrite(query);
     this.searcher = searcher;
     this.numHitsToCollect = numHitsToCollect;
-    this.totalHitsRef = totalHitsRef == null ? this.totalHitsRef : totalHitsRef;
-    this.progressRef = progressRef == null ? this.progressRef : progressRef;
+    this.totalHitsRef = totalHitsRef == null ? new TotalHitsRef() : totalHitsRef;
+    this.progressRef = progressRef == null ? new ProgressRef() : progressRef;
+
   }
 
   public static class TotalHitsRef {
@@ -178,7 +173,8 @@ public class IterablePaging implements Iterable<ScoreDoc> {
         StopExecutionCollector stopExecutionCollector = new StopExecutionCollector(collector,
running);
         searcher.search(query, stopExecutionCollector);
         totalHitsRef.totalHits.set(collector.getTotalHits());
-        scoreDocs = collector.topDocs().scoreDocs;
+        TopDocs topDocs = collector.topDocs();
+        scoreDocs = topDocs.scoreDocs;
       } catch (IOException e) {
         e.printStackTrace();
         throw new RuntimeException(e);
@@ -228,7 +224,4 @@ public class IterablePaging implements Iterable<ScoreDoc> {
     return iterator;
   }
 
-  public static void setDefaultNumberOfHitsToCollect(int num) {
-    DEFAULT_NUMBER_OF_HITS_TO_COLLECT = num;
-  }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/4ef6e5ce/src/blur-core/src/main/java/org/apache/blur/lucene/search/PagingCollector.java
----------------------------------------------------------------------
diff --git a/src/blur-core/src/main/java/org/apache/blur/lucene/search/PagingCollector.java
b/src/blur-core/src/main/java/org/apache/blur/lucene/search/PagingCollector.java
index 385c29d..fec888c 100644
--- a/src/blur-core/src/main/java/org/apache/blur/lucene/search/PagingCollector.java
+++ b/src/blur-core/src/main/java/org/apache/blur/lucene/search/PagingCollector.java
@@ -95,25 +95,21 @@ public class PagingCollector extends TopDocsCollector<ScoreDoc>
{
 
   public static class HitQueue extends PriorityQueue<ScoreDoc> {
 
-    private boolean prePopulate;
-
     HitQueue(int size, boolean prePopulate) {
-      super(size);
-      this.prePopulate = prePopulate;
+      super(size, prePopulate);
     }
 
     @Override
     protected ScoreDoc getSentinelObject() {
-      return !prePopulate ? null : new ScoreDoc(Integer.MAX_VALUE, Float.NEGATIVE_INFINITY);
+      return new ScoreDoc(Integer.MAX_VALUE, Float.NEGATIVE_INFINITY);
     }
 
     @Override
     protected final boolean lessThan(ScoreDoc hitA, ScoreDoc hitB) {
-      if (hitA.score == hitB.score) {
+      if (hitA.score == hitB.score)
         return hitA.doc > hitB.doc;
-      } else {
+      else
         return hitA.score < hitB.score;
-      }
     }
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/4ef6e5ce/src/blur-core/src/test/java/org/apache/blur/search/TestingPagingCollector.java
----------------------------------------------------------------------
diff --git a/src/blur-core/src/test/java/org/apache/blur/search/TestingPagingCollector.java
b/src/blur-core/src/test/java/org/apache/blur/search/TestingPagingCollector.java
index 14ae610..5eaad3f 100644
--- a/src/blur-core/src/test/java/org/apache/blur/search/TestingPagingCollector.java
+++ b/src/blur-core/src/test/java/org/apache/blur/search/TestingPagingCollector.java
@@ -39,7 +39,6 @@ import org.apache.lucene.search.TermQuery;
 import org.apache.lucene.store.RAMDirectory;
 import org.junit.Test;
 
-
 /**
  * Testing the paging collector.
  * 
@@ -60,12 +59,13 @@ public class TestingPagingCollector {
     ProgressRef progressRef = new ProgressRef();
 
     TermQuery query = new TermQuery(new Term("f1", "value"));
-    IterablePaging paging = new IterablePaging(new AtomicBoolean(true), searcher, query,
100);
+    IterablePaging paging = new IterablePaging(new AtomicBoolean(true), searcher, query,
100, null, null);
 
     for (ScoreDoc sd : paging.skipTo(90).gather(20).totalHits(totalHitsRef).progress(progressRef))
{
 
-      System.out.println("time [" + progressRef.queryTime() + "] " + "total hits [" + totalHitsRef.totalHits()
+ "] " + "searches [" + progressRef.searchesPerformed() + "] "
-          + "position [" + progressRef.currentHitPosition() + "] " + "doc id [" + sd.doc
+ "] " + "score [" + sd.score + "]");
+      System.out.println("time [" + progressRef.queryTime() + "] " + "total hits [" + totalHitsRef.totalHits()
+ "] "
+          + "searches [" + progressRef.searchesPerformed() + "] " + "position [" + progressRef.currentHitPosition()
+          + "] " + "doc id [" + sd.doc + "] " + "score [" + sd.score + "]");
     }
   }
 


Mime
View raw message