You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ro...@apache.org on 2012/10/26 18:45:30 UTC

svn commit: r1402570 - /lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/positions/

Author: romseygeek
Date: Fri Oct 26 16:45:29 2012
New Revision: 1402570

URL: http://svn.apache.org/viewvc?rev=1402570&view=rev
Log:
LUCENE-2878: Javadocs; tidy up WithinOrderedFilter

Added:
    lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/positions/WithinIntervalFilter.java
      - copied, changed from r1402549, lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/positions/WithinIntervalIterator.java
Removed:
    lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/positions/BooleanIntervalIterator.java
    lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/positions/WithinIntervalIterator.java
Modified:
    lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/positions/IntervalFilter.java
    lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/positions/UnorderedNearQuery.java
    lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/positions/WithinOrderedFilter.java

Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/positions/IntervalFilter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/positions/IntervalFilter.java?rev=1402570&r1=1402569&r2=1402570&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/positions/IntervalFilter.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/positions/IntervalFilter.java Fri Oct 26 16:45:29 2012
@@ -19,6 +19,8 @@ package org.apache.lucene.search.positio
 
 /**
  * Filters an {@link IntervalIterator}
+ *
+ * @see IntervalFilterQuery
  */
 public interface IntervalFilter {
 

Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/positions/UnorderedNearQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/positions/UnorderedNearQuery.java?rev=1402570&r1=1402569&r2=1402570&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/positions/UnorderedNearQuery.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/positions/UnorderedNearQuery.java Fri Oct 26 16:45:29 2012
@@ -42,7 +42,7 @@ public class UnorderedNearQuery extends 
    * @param subqueries the subqueries to match.
    */
   public UnorderedNearQuery(int slop, Query... subqueries) {
-    super(buildBooleanQuery(subqueries), new WithinIntervalIterator(slop + subqueries.length - 1));
+    super(buildBooleanQuery(subqueries), new WithinIntervalFilter(slop + subqueries.length - 1));
   }
 
   private static BooleanQuery buildBooleanQuery(Query... queries) {

Copied: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/positions/WithinIntervalFilter.java (from r1402549, lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/positions/WithinIntervalIterator.java)
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/positions/WithinIntervalFilter.java?p2=lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/positions/WithinIntervalFilter.java&p1=lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/positions/WithinIntervalIterator.java&r1=1402549&r2=1402570&rev=1402570&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/positions/WithinIntervalIterator.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/positions/WithinIntervalFilter.java Fri Oct 26 16:45:29 2012
@@ -19,56 +19,78 @@ import java.io.IOException;
 
 
 /**
+ * An IntervalFilter that restricts Intervals returned by an IntervalIterator
+ * to those which have a matchDistance less than a defined slop.
+ *
  * @lucene.experimental
- */ // nocommit - javadoc
-public class WithinIntervalIterator extends IntervalIterator implements IntervalFilter {
-  private int howMany;
-  private IntervalIterator iterator;
-  private Interval interval;
-  
-  public WithinIntervalIterator(boolean collectPositions, int howMany, IntervalIterator iterator) {
-    super(iterator != null ? iterator.scorer : null, collectPositions);
-    this.howMany = howMany;
-    this.iterator = iterator;
-  }
-  
-  public WithinIntervalIterator(int howMany) {
-    this(false, howMany, null); // use this instance as a filter template
+ */
+public class WithinIntervalFilter implements IntervalFilter {
+
+  private final int slop;
+
+  /**
+   * Construct a new WithinIntervalFilter
+   * @param slop the maximum slop allowed for subintervals
+   */
+  public WithinIntervalFilter(int slop) {
+    this.slop = slop;
+  }
+
+  /**
+   * @return the slop
+   */
+  public int getSlop() {
+    return slop;
   }
+
   @Override
-  public Interval next() throws IOException {
-    while ((interval = iterator.next()) != null) {
-      if((iterator.matchDistance()) <= howMany){
-        return interval;
+  public IntervalIterator filter(boolean collectIntervals, IntervalIterator iter) {
+    return new WithinIntervalIterator(collectIntervals, iter);
+  }
+
+  class WithinIntervalIterator extends IntervalIterator {
+
+    private IntervalIterator iterator;
+    private Interval interval;
+
+    WithinIntervalIterator(boolean collectIntervals, IntervalIterator iter) {
+      super(iter == null ? null : iter.scorer, collectIntervals);
+      this.iterator = iter;
+    }
+
+    @Override
+    public Interval next() throws IOException {
+      while ((interval = iterator.next()) != null) {
+        if((iterator.matchDistance()) <= slop){
+          return interval;
+        }
       }
+      return null;
     }
-    return null;
-  }
 
-  @Override
-  public IntervalIterator[] subs(boolean inOrder) {
-    return new IntervalIterator[] {iterator};
-  }
+    @Override
+    public IntervalIterator[] subs(boolean inOrder) {
+      return new IntervalIterator[] {iterator};
+    }
 
-  public IntervalIterator filter(boolean collectPositions, IntervalIterator iter) {
-    return new WithinIntervalIterator(collectPositions, howMany, iter);
-  }
 
-  @Override
-  public void collect(IntervalCollector collector) {
-    assert collectPositions;
-    collector.collectComposite(null, interval, iterator.docID());
-    iterator.collect(collector);
-  }
+    @Override
+    public void collect(IntervalCollector collector) {
+      assert collectIntervals;
+      collector.collectComposite(null, interval, iterator.docID());
+      iterator.collect(collector);
+    }
 
-  @Override
-  public int scorerAdvanced(int docId) throws IOException {
-    return iterator.scorerAdvanced(docId);
-  }
+    @Override
+    public int scorerAdvanced(int docId) throws IOException {
+      return iterator.scorerAdvanced(docId);
+    }
+
+    @Override
+    public int matchDistance() {
+      return iterator.matchDistance();
+    }
 
-  @Override
-  public int matchDistance() {
-    return iterator.matchDistance();
   }
 
 }

Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/positions/WithinOrderedFilter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/positions/WithinOrderedFilter.java?rev=1402570&r1=1402569&r2=1402570&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/positions/WithinOrderedFilter.java (original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/positions/WithinOrderedFilter.java Fri Oct 26 16:45:29 2012
@@ -17,23 +17,33 @@ package org.apache.lucene.search.positio
  * limitations under the License.
  */
 
+/**
+ * An IntervalFilter that restricts an IntervalIterator to return
+ * only Intervals that occur in order within a given distance.
+ *
+ * @see WithinIntervalFilter
+ */
 public class WithinOrderedFilter implements IntervalFilter {
 
-  private int slop;
+  private final WithinIntervalFilter innerFilter;
 
+  /**
+   * Constructs a new WithinOrderedFilter with a given slop
+   * @param slop The maximum distance allowed between subintervals
+   */
   public WithinOrderedFilter(int slop) {
-    this.slop = slop;
+    this.innerFilter = new WithinIntervalFilter(slop);
   }
 
   @Override
   public IntervalIterator filter(boolean collectIntervals, IntervalIterator iter) {
-    return new WithinIntervalIterator(collectIntervals, slop,
-        new OrderedConjunctionIntervalIterator(collectIntervals, iter));
+    return innerFilter.filter(collectIntervals,
+                              new OrderedConjunctionIntervalIterator(collectIntervals, iter));
   }
 
   @Override
   public String toString() {
-    return "WithinOrderedFilter[" + slop + "]";
+    return "WithinOrderedFilter[" + this.innerFilter.getSlop() + "]";
   }
 
 }