incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amccu...@apache.org
Subject [4/6] git commit: Adding new position method to the bluriterator, this will be used for deep paging cache.
Date Thu, 10 Jul 2014 00:56:20 GMT
Adding new position method to the bluriterator, this will be used for deep paging cache.


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

Branch: refs/heads/apache-blur-0.2
Commit: a19ad8c2b6ff22849bb16c52bd7a1d3584c93478
Parents: cf55569
Author: Aaron McCurry <amccurry@gmail.com>
Authored: Sat Jul 5 13:02:48 2014 -0400
Committer: Aaron McCurry <amccurry@gmail.com>
Committed: Sat Jul 5 13:02:48 2014 -0400

----------------------------------------------------------------------
 .../org/apache/blur/manager/IndexManager.java   |  5 ++++
 .../results/BlurResultIterableClient.java       | 19 +++++++++-----
 .../results/BlurResultIterableMultiple.java     | 27 ++++++++++++--------
 .../blur/manager/results/PeekableIterator.java  | 14 ++++++----
 .../java/org/apache/blur/utils/BlurUtil.java    | 10 ++++++++
 .../apache/blur/utils/IteratorConverter.java    | 17 +++++++-----
 .../blur/lucene/search/IterablePaging.java      |  7 ++++-
 .../org/apache/blur/utils/BlurIterator.java     |  2 ++
 8 files changed, 72 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/a19ad8c2/blur-core/src/main/java/org/apache/blur/manager/IndexManager.java
----------------------------------------------------------------------
diff --git a/blur-core/src/main/java/org/apache/blur/manager/IndexManager.java b/blur-core/src/main/java/org/apache/blur/manager/IndexManager.java
index 1b266f4..0bc23d2 100644
--- a/blur-core/src/main/java/org/apache/blur/manager/IndexManager.java
+++ b/blur-core/src/main/java/org/apache/blur/manager/IndexManager.java
@@ -618,6 +618,11 @@ public class IndexManager {
           public boolean hasNext() throws BlurException {
             return iterator.hasNext();
           }
+
+          @Override
+          public long getPosition() throws BlurException {
+            return iterator.getPosition();
+          }
         };
       }
 

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/a19ad8c2/blur-core/src/main/java/org/apache/blur/manager/results/BlurResultIterableClient.java
----------------------------------------------------------------------
diff --git a/blur-core/src/main/java/org/apache/blur/manager/results/BlurResultIterableClient.java
b/blur-core/src/main/java/org/apache/blur/manager/results/BlurResultIterableClient.java
index fdda6e3..a8dc32a 100644
--- a/blur-core/src/main/java/org/apache/blur/manager/results/BlurResultIterableClient.java
+++ b/blur-core/src/main/java/org/apache/blur/manager/results/BlurResultIterableClient.java
@@ -139,12 +139,12 @@ public class BlurResultIterableClient implements BlurResultIterable
{
 
   public class SearchIterator implements BlurIterator<BlurResult, BlurException> {
 
-    private int position = 0;
-    private int relposition = 0;
+    private long _position = 0;
+    private int _relposition = 0;
 
     @Override
     public boolean hasNext() {
-      if (position < _originalQuery.minimumNumberOfResults && position < _totalResults)
{
+      if (_position < _originalQuery.minimumNumberOfResults && _position <
_totalResults) {
         return true;
       }
       return false;
@@ -152,12 +152,17 @@ public class BlurResultIterableClient implements BlurResultIterable
{
 
     @Override
     public BlurResult next() throws BlurException {
-      if (relposition >= _results.results.size()) {
+      if (_relposition >= _results.results.size()) {
         performSearch();
-        relposition = 0;
+        _relposition = 0;
       }
-      position++;
-      return _results.results.get(relposition++);
+      _position++;
+      return _results.results.get(_relposition++);
+    }
+
+    @Override
+    public long getPosition() throws BlurException {
+      return _position;
     }
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/a19ad8c2/blur-core/src/main/java/org/apache/blur/manager/results/BlurResultIterableMultiple.java
----------------------------------------------------------------------
diff --git a/blur-core/src/main/java/org/apache/blur/manager/results/BlurResultIterableMultiple.java
b/blur-core/src/main/java/org/apache/blur/manager/results/BlurResultIterableMultiple.java
index d55737f..d67dc86 100644
--- a/blur-core/src/main/java/org/apache/blur/manager/results/BlurResultIterableMultiple.java
+++ b/blur-core/src/main/java/org/apache/blur/manager/results/BlurResultIterableMultiple.java
@@ -27,6 +27,8 @@ import org.apache.blur.log.Log;
 import org.apache.blur.log.LogFactory;
 import org.apache.blur.thrift.generated.BlurException;
 import org.apache.blur.thrift.generated.BlurResult;
+import org.apache.blur.trace.Trace;
+import org.apache.blur.trace.Tracer;
 import org.apache.blur.utils.BlurIterator;
 import org.apache.blur.utils.BlurUtil;
 import org.apache.hadoop.io.IOUtils;
@@ -65,31 +67,34 @@ public class BlurResultIterableMultiple implements BlurResultIterable
{
   public BlurIterator<BlurResult, BlurException> iterator() throws BlurException {
     MultipleHitsIterator iterator = new MultipleHitsIterator(results);
     long start = 0;
+    Tracer trace = Trace.trace("blurResultsIterable - iterator - skipping", Trace.param("skipTo",
skipTo));
     while (iterator.hasNext() && start < skipTo) {
       iterator.next();
       start++;
     }
+    trace.done();
     return iterator;
   }
 
   public static class MultipleHitsIterator implements BlurIterator<BlurResult, BlurException>
{
 
-    private List<PeekableIterator<BlurResult, BlurException>> iterators = new
ArrayList<PeekableIterator<BlurResult, BlurException>>();
-    private int length;
+    private final List<PeekableIterator<BlurResult, BlurException>> _iterators
= new ArrayList<PeekableIterator<BlurResult, BlurException>>();
+    private final int _length;
+    private long _position = 0;
 
     public MultipleHitsIterator(List<BlurResultIterable> hits) throws BlurException
{
       for (BlurResultIterable hitsIterable : hits) {
         BlurIterator<BlurResult, BlurException> iterator = hitsIterable.iterator();
         PeekableIterator<BlurResult, BlurException> peekableIterator = PeekableIterator.wrap(iterator);
-        iterators.add(peekableIterator);
+        _iterators.add(peekableIterator);
       }
-      length = iterators.size();
+      _length = _iterators.size();
     }
 
     @Override
     public boolean hasNext() throws BlurException {
-      for (int i = 0; i < length; i++) {
-        if (iterators.get(i).hasNext()) {
+      for (int i = 0; i < _length; i++) {
+        if (_iterators.get(i).hasNext()) {
           return true;
         }
       }
@@ -98,12 +103,14 @@ public class BlurResultIterableMultiple implements BlurResultIterable
{
 
     @Override
     public BlurResult next() throws BlurException {
-      Collections.sort(iterators, BlurUtil.HITS_PEEKABLE_ITERATOR_COMPARATOR);
-      return fetchResult(iterators.get(0).next());
+      Collections.sort(_iterators, BlurUtil.HITS_PEEKABLE_ITERATOR_COMPARATOR);
+      _position++;
+      return _iterators.get(0).next();
     }
 
-    public BlurResult fetchResult(BlurResult next) {
-      return next;
+    @Override
+    public long getPosition() throws BlurException {
+      return _position;
     }
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/a19ad8c2/blur-core/src/main/java/org/apache/blur/manager/results/PeekableIterator.java
----------------------------------------------------------------------
diff --git a/blur-core/src/main/java/org/apache/blur/manager/results/PeekableIterator.java
b/blur-core/src/main/java/org/apache/blur/manager/results/PeekableIterator.java
index 81e5ff7..d67fe56 100644
--- a/blur-core/src/main/java/org/apache/blur/manager/results/PeekableIterator.java
+++ b/blur-core/src/main/java/org/apache/blur/manager/results/PeekableIterator.java
@@ -2,7 +2,6 @@ package org.apache.blur.manager.results;
 
 import org.apache.blur.utils.BlurIterator;
 
-
 /**
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
@@ -27,13 +26,13 @@ public class PeekableIterator<T, E extends Exception> implements
BlurIterator<T,
 
   private final BlurIterator<T, E> _iterator;
   private T _current;
-  
-  private PeekableIterator(BlurIterator<T, E> iterator,T current) {
+
+  private PeekableIterator(BlurIterator<T, E> iterator, T current) {
     _iterator = iterator;
     _current = current;
   }
-  
-  public static<T,E extends Exception> PeekableIterator<T, E> wrap(BlurIterator<T,
E> iterator) throws E {
+
+  public static <T, E extends Exception> PeekableIterator<T, E> wrap(BlurIterator<T,
E> iterator) throws E {
     if (iterator.hasNext()) {
       return new PeekableIterator<T, E>(iterator, iterator.next());
     }
@@ -68,4 +67,9 @@ public class PeekableIterator<T, E extends Exception> implements BlurIterator<T,
     return result;
   }
 
+  @Override
+  public long getPosition() throws E {
+    return _iterator.getPosition() - 1;
+  }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/a19ad8c2/blur-core/src/main/java/org/apache/blur/utils/BlurUtil.java
----------------------------------------------------------------------
diff --git a/blur-core/src/main/java/org/apache/blur/utils/BlurUtil.java b/blur-core/src/main/java/org/apache/blur/utils/BlurUtil.java
index f4f63df..52fd09f 100644
--- a/blur-core/src/main/java/org/apache/blur/utils/BlurUtil.java
+++ b/blur-core/src/main/java/org/apache/blur/utils/BlurUtil.java
@@ -552,7 +552,9 @@ public class BlurUtil {
     results.setTotalResults(hitsIterable.getTotalResults());
     results.setShardInfo(hitsIterable.getShardInfo());
     if (query.minimumNumberOfResults > 0) {
+      Tracer trace = Trace.trace("convertToHits - skipTo", Trace.param("start", query.start));
       hitsIterable.skipTo(query.start);
+      trace.done();
       BlurIterator<BlurResult, BlurException> iterator = hitsIterable.iterator();
       for (int count = 0; count < query.fetch && iterator.hasNext(); count++)
{
         results.addToResults(iterator.next());
@@ -1191,6 +1193,8 @@ public class BlurUtil {
   public static <T, E extends Exception> BlurIterator<T, E> convert(final Iterator<T>
iterator) {
     return new BlurIterator<T, E>() {
 
+      private long _position = 0;
+
       @Override
       public boolean hasNext() throws E {
         return iterator.hasNext();
@@ -1198,8 +1202,14 @@ public class BlurUtil {
 
       @Override
       public T next() throws E {
+        _position++;
         return iterator.next();
       }
+
+      @Override
+      public long getPosition() throws E {
+        return _position;
+      }
     };
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/a19ad8c2/blur-core/src/main/java/org/apache/blur/utils/IteratorConverter.java
----------------------------------------------------------------------
diff --git a/blur-core/src/main/java/org/apache/blur/utils/IteratorConverter.java b/blur-core/src/main/java/org/apache/blur/utils/IteratorConverter.java
index 5d7ac78..ec7ea1e 100644
--- a/blur-core/src/main/java/org/apache/blur/utils/IteratorConverter.java
+++ b/blur-core/src/main/java/org/apache/blur/utils/IteratorConverter.java
@@ -22,22 +22,27 @@ package org.apache.blur.utils;
  */
 public class IteratorConverter<F, T, E extends Exception> implements BlurIterator<T,
E> {
 
-  private Converter<F, T, E> converter;
-  private BlurIterator<F,E> iterator;
+  private Converter<F, T, E> _converter;
+  private BlurIterator<F,E> _iterator;
 
   public IteratorConverter(BlurIterator<F,E> iterator, Converter<F, T, E> converter)
{
-    this.converter = converter;
-    this.iterator = iterator;
+    _converter = converter;
+    _iterator = iterator;
   }
 
   @Override
   public boolean hasNext() throws E {
-    return iterator.hasNext();
+    return _iterator.hasNext();
   }
 
   @Override
   public T next() throws E {
-      return converter.convert(iterator.next());
+      return _converter.convert(_iterator.next());
+  }
+
+  @Override
+  public long getPosition() throws E {
+    return _iterator.getPosition();
   }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/a19ad8c2/blur-query/src/main/java/org/apache/blur/lucene/search/IterablePaging.java
----------------------------------------------------------------------
diff --git a/blur-query/src/main/java/org/apache/blur/lucene/search/IterablePaging.java b/blur-query/src/main/java/org/apache/blur/lucene/search/IterablePaging.java
index 1c638fc..ed99fdb 100644
--- a/blur-query/src/main/java/org/apache/blur/lucene/search/IterablePaging.java
+++ b/blur-query/src/main/java/org/apache/blur/lucene/search/IterablePaging.java
@@ -50,7 +50,7 @@ public class IterablePaging implements BlurIterable<ScoreDoc, BlurException>
{
 
   private static final Log LOG = LogFactory.getLog(IterablePaging.class);
 
-  private static final boolean DISABLED = true;
+  private static final boolean DISABLED = false;
 
   private final DeepPagingCache _deepPagingCache;
   private final IndexSearcher _searcher;
@@ -284,6 +284,11 @@ public class IterablePaging implements BlurIterable<ScoreDoc, BlurException>
{
     private boolean isCurrentCollectorExhausted() {
       return offset < scoreDocs.length ? false : true;
     }
+
+    @Override
+    public long getPosition() throws BlurException {
+      return counter;
+    }
   }
 
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/a19ad8c2/blur-util/src/main/java/org/apache/blur/utils/BlurIterator.java
----------------------------------------------------------------------
diff --git a/blur-util/src/main/java/org/apache/blur/utils/BlurIterator.java b/blur-util/src/main/java/org/apache/blur/utils/BlurIterator.java
index 7f6b618..0ecf1e4 100644
--- a/blur-util/src/main/java/org/apache/blur/utils/BlurIterator.java
+++ b/blur-util/src/main/java/org/apache/blur/utils/BlurIterator.java
@@ -25,5 +25,7 @@ public interface BlurIterator<T, E extends Exception> {
   public boolean hasNext() throws E;
 
   public T next() throws E;
+  
+  public long getPosition() throws E;
 
 }


Mime
View raw message