lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From romseyg...@apache.org
Subject svn commit: r1445045 - in /lucene/dev/branches/LUCENE-2878/lucene/core/src: java/org/apache/lucene/search/ java/org/apache/lucene/search/intervals/ test/org/apache/lucene/search/intervals/
Date Tue, 12 Feb 2013 07:52:37 GMT
Author: romseygeek
Date: Tue Feb 12 07:52:36 2013
New Revision: 1445045

URL: http://svn.apache.org/r1445045
Log:
LUCENE-2878: ConjunctionTermScorer implements next/start/endPosition()

Modified:
    lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/ConjunctionTermScorer.java
    lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/PositionQueue.java
    lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/intervals/Interval.java
    lucene/dev/branches/LUCENE-2878/lucene/core/src/test/org/apache/lucene/search/intervals/IntervalTestBase.java
    lucene/dev/branches/LUCENE-2878/lucene/core/src/test/org/apache/lucene/search/intervals/TestBasicIntervals.java

Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/ConjunctionTermScorer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/ConjunctionTermScorer.java?rev=1445045&r1=1445044&r2=1445045&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/ConjunctionTermScorer.java
(original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/ConjunctionTermScorer.java
Tue Feb 12 07:52:36 2013
@@ -36,6 +36,7 @@ class ConjunctionTermScorer extends Scor
   protected final DocsAndFreqs[] docsAndFreqs;
   private final DocsAndFreqs lead;
   private DocsAndFreqs[] origDocsAndFreqs;
+  final PositionQueue posQueue;
 
   ConjunctionTermScorer(Weight weight, float coord, DocsAndFreqs[] docsAndFreqs) {
     super(weight);
@@ -51,10 +52,18 @@ class ConjunctionTermScorer extends Scor
         return o1.docFreq - o2.docFreq;
       }
     });
-
+    posQueue = new PositionQueue(makeDocsEnumArray(docsAndFreqs));
     lead = docsAndFreqs[0]; // least frequent DocsEnum leads the intersection
   }
 
+  private DocsEnum[] makeDocsEnumArray(DocsAndFreqs[] docsAndFreqs) {
+    DocsEnum[] docsEnums = new DocsEnum[docsAndFreqs.length];
+    for (int i = 0; i < docsAndFreqs.length; i++) {
+      docsEnums[i] = docsAndFreqs[i].docs;
+    }
+    return docsEnums;
+  }
+
   private int doNext(int doc) throws IOException {
     do {
       if (lead.doc == DocIdSetIterator.NO_MORE_DOCS) {
@@ -71,6 +80,7 @@ class ConjunctionTermScorer extends Scor
           }
         }
         // success - all DocsEnums are on the same doc
+        posQueue.advanceTo(doc);
         return doc;
       } while (true);
       // advance head for next iteration
@@ -113,6 +123,31 @@ class ConjunctionTermScorer extends Scor
   }
 
   @Override
+  public int nextPosition() throws IOException {
+    return posQueue.nextPosition();
+  }
+
+  @Override
+  public int startPosition() throws IOException {
+    return posQueue.startPosition();
+  }
+
+  @Override
+  public int endPosition() throws IOException {
+    return posQueue.endPosition();
+  }
+
+  @Override
+  public int startOffset() throws IOException {
+    return posQueue.startOffset();
+  }
+
+  @Override
+  public int endOffset() throws IOException {
+    return posQueue.endOffset();
+  }
+
+  @Override
   public Collection<ChildScorer> getChildren() {
     ArrayList<ChildScorer> children = new ArrayList<ChildScorer>(docsAndFreqs.length);
     for (DocsAndFreqs docs : docsAndFreqs) {

Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/PositionQueue.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/PositionQueue.java?rev=1445045&r1=1445044&r2=1445045&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/PositionQueue.java
(original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/PositionQueue.java
Tue Feb 12 07:52:36 2013
@@ -21,23 +21,23 @@ import java.io.IOException;
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-public class PositionQueue extends PriorityQueue<PositionQueue.ScorerRef> {
+public class PositionQueue extends PriorityQueue<PositionQueue.DocsEnumRef> {
 
-  class ScorerRef {
+  class DocsEnumRef {
 
-    public final Scorer scorer;
+    public final DocsEnum docsEnum;
     public Interval interval = new Interval();
 
-    public ScorerRef(Scorer scorer) {
-      this.scorer = scorer;
+    public DocsEnumRef(DocsEnum docsEnum) {
+      this.docsEnum = docsEnum;
     }
 
     public int nextPosition() throws IOException {
-      if (scorer.docID() == DocsEnum.NO_MORE_DOCS || scorer.docID() != docId
-            || scorer.nextPosition() == DocsEnum.NO_MORE_POSITIONS)
+      if (docsEnum.docID() == DocsEnum.NO_MORE_DOCS || docsEnum.docID() != docId
+            || docsEnum.nextPosition() == DocsEnum.NO_MORE_POSITIONS)
         interval.update(Interval.EXHAUSTED_INTERVAL);
       else
-        interval.update(this.scorer);
+        interval.update(this.docsEnum);
       return interval.begin;
     }
 
@@ -47,10 +47,10 @@ public class PositionQueue extends Prior
   Interval current = new Interval();
   int docId = -1;
 
-  public PositionQueue(Scorer[] subScorers) {
-    super(subScorers.length);
-    for (int i = 0; i < subScorers.length; i++) {
-      add(new ScorerRef(subScorers[i]));
+  public PositionQueue(DocsEnum[] subDocsEnums) {
+    super(subDocsEnums.length);
+    for (int i = 0; i < subDocsEnums.length; i++) {
+      add(new DocsEnumRef(subDocsEnums[i]));
     }
   }
 
@@ -58,7 +58,7 @@ public class PositionQueue extends Prior
     if (!positioned) {
       for (Object scorerRef : getHeapArray()) {
         if (scorerRef != null)
-          ((ScorerRef) scorerRef).nextPosition();
+          ((DocsEnumRef) scorerRef).nextPosition();
       }
       positioned = true;
       updateTop();
@@ -74,10 +74,10 @@ public class PositionQueue extends Prior
   }
 
   @Override
-  protected boolean lessThan(ScorerRef a, ScorerRef b) {
-    if (a.scorer.docID() < b.scorer.docID())
+  protected boolean lessThan(DocsEnumRef a, DocsEnumRef b) {
+    if (a.docsEnum.docID() < b.docsEnum.docID())
       return true;
-    if (a.scorer.docID() > b.scorer.docID())
+    if (a.docsEnum.docID() > b.docsEnum.docID())
       return false;
     return a.interval.begin < b.interval.begin;
   }

Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/intervals/Interval.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/intervals/Interval.java?rev=1445045&r1=1445044&r2=1445045&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/intervals/Interval.java
(original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/java/org/apache/lucene/search/intervals/Interval.java
Tue Feb 12 07:52:36 2013
@@ -17,7 +17,6 @@ package org.apache.lucene.search.interva
  */
 
 import org.apache.lucene.index.DocsEnum;
-import org.apache.lucene.search.Scorer;
 
 import java.io.IOException;
 
@@ -187,11 +186,11 @@ public class Interval implements Cloneab
         + end + "(" + offsetEnd + ")]";
   }
 
-  public void update(Scorer scorer) throws IOException {
-    offsetBegin = scorer.startOffset();
-    offsetEnd = scorer.endOffset();
-    begin = scorer.startPosition();
-    end = scorer.endPosition();
+  public void update(DocsEnum docsEnum) throws IOException {
+    offsetBegin = docsEnum.startOffset();
+    offsetEnd = docsEnum.endOffset();
+    begin = docsEnum.startPosition();
+    end = docsEnum.endPosition();
   }
 
   public void update(Interval interval) {

Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/test/org/apache/lucene/search/intervals/IntervalTestBase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/test/org/apache/lucene/search/intervals/IntervalTestBase.java?rev=1445045&r1=1445044&r2=1445045&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/test/org/apache/lucene/search/intervals/IntervalTestBase.java
(original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/test/org/apache/lucene/search/intervals/IntervalTestBase.java
Tue Feb 12 07:52:36 2013
@@ -160,6 +160,14 @@ public abstract class IntervalTestBase e
     return q;
   }
 
+  protected Query makeAndQuery(Query... queries) {
+    BooleanQuery q = new BooleanQuery();
+    for (Query subquery : queries) {
+      q.add(subquery, BooleanClause.Occur.MUST);
+    }
+    return q;
+  }
+
   public static class Match implements Comparable<TestDisjunctionIntervalIterator.Match>
{
 
     public final int docid;

Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/test/org/apache/lucene/search/intervals/TestBasicIntervals.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/test/org/apache/lucene/search/intervals/TestBasicIntervals.java?rev=1445045&r1=1445044&r2=1445045&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/test/org/apache/lucene/search/intervals/TestBasicIntervals.java
(original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/test/org/apache/lucene/search/intervals/TestBasicIntervals.java
Tue Feb 12 07:52:36 2013
@@ -55,6 +55,25 @@ public class TestBasicIntervals extends 
       "v4 v2 v2 v4",//14
       "v3 v4 v3"};//15
 
+  public void testSimpleConjunction() throws IOException {
+    Query q = makeAndQuery(makeTermQuery("v2"), makeTermQuery("v4"));
+    checkIntervals(q, searcher, new int[][]{
+        { 13, 2, 2, 4, 4 },
+        { 14, 0, 0, 1, 1, 2, 2, 3, 3 }
+    });
+  }
+
+  /*
+  public void testNestedConjunctions() throws IOException {
+    Query q = makeAndQuery(makeTermQuery("v2"), makeOrQuery(makeTermQuery("v3"), makeTermQuery("v4")));
+    checkIntervals(q, searcher, new int[][]{
+        { 12, 1, 1, 2, 2 },
+        { 13, 1, 1, 2, 2, 3, 3, 4, 4 },
+        { 14, 0, 0, 1, 1, 2, 2, 3, 3 }
+    });
+  }
+  */
+
   public void testSimpleTerm() throws IOException {
     Query q = makeTermQuery("u2");
     checkIntervals(q, searcher, new int[][]{



Mime
View raw message