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 2014/12/09 15:07:00 UTC

svn commit: r1644050 - in /lucene/dev/branches/lucene2878/lucene/core/src: java/org/apache/lucene/search/posfilter/ test/org/apache/lucene/search/posfilter/

Author: romseygeek
Date: Tue Dec  9 14:06:59 2014
New Revision: 1644050

URL: http://svn.apache.org/r1644050
Log:
LUCENE-2878: UnorderedNearQuery scoring

Modified:
    lucene/dev/branches/lucene2878/lucene/core/src/java/org/apache/lucene/search/posfilter/Interval.java
    lucene/dev/branches/lucene2878/lucene/core/src/java/org/apache/lucene/search/posfilter/UnorderedNearQuery.java
    lucene/dev/branches/lucene2878/lucene/core/src/test/org/apache/lucene/search/posfilter/TestIntervalScoring.java

Modified: lucene/dev/branches/lucene2878/lucene/core/src/java/org/apache/lucene/search/posfilter/Interval.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2878/lucene/core/src/java/org/apache/lucene/search/posfilter/Interval.java?rev=1644050&r1=1644049&r2=1644050&view=diff
==============================================================================
--- lucene/dev/branches/lucene2878/lucene/core/src/java/org/apache/lucene/search/posfilter/Interval.java (original)
+++ lucene/dev/branches/lucene2878/lucene/core/src/java/org/apache/lucene/search/posfilter/Interval.java Tue Dec  9 14:06:59 2014
@@ -62,13 +62,6 @@ class Interval implements Cloneable {
     this(Integer.MIN_VALUE, Integer.MIN_VALUE, -1, -1);
   }
 
-  public Interval(DocsEnum docsEnum) throws IOException {
-    this.begin = docsEnum.startPosition();
-    this.end = docsEnum.endPosition();
-    this.offsetBegin = docsEnum.startOffset();
-    this.offsetEnd = docsEnum.endOffset();
-  }
-
   /**
    * Update to span the range defined by two other Intervals.
    * @param start the first Interval
@@ -106,36 +99,6 @@ class Interval implements Cloneable {
   }
 
   /**
-   * Compare with another Interval.
-   * @param other the comparator
-   * @return true if both start and end positions are less than
-   *              or equal to the comparator's.
-   */
-  public boolean lessThan(Interval other) {
-    return begin <= other.begin && end <= other.end;
-  }
-
-  /**
-   * Compare with another Interval
-   * @param other the comparator
-   * @return true if both start and end positions are greater then
-   *              the comparator's.
-   */
-  public boolean greaterThanExclusive(Interval other) {
-    return begin > other.begin && end > other.end;
-  }
-
-  /**
-   * Compare with another Interval
-   * @param other the comparator
-   * @return true if both start and end positions are greater then
-   *              of equal to the comparator's.
-   */
-  public boolean greaterThan(Interval other) {
-    return begin >= other.begin && end >= other.end;
-  }
-
-  /**
    * Compare with another Interval
    * @param other the comparator
    * @return true if this Interval contains the comparator
@@ -154,17 +117,6 @@ class Interval implements Cloneable {
   }
 
   /**
-   * Set all values of this Interval to be equal to another's
-   * @param other the Interval to copy
-   */
-  public void copy(Interval other) {
-    begin = other.begin;
-    end = other.end;
-    offsetBegin = other.offsetBegin;
-    offsetEnd = other.offsetEnd;
-  }
-
-  /**
    * Set to a state that will always compare as less than any
    * other Interval.
    */

Modified: lucene/dev/branches/lucene2878/lucene/core/src/java/org/apache/lucene/search/posfilter/UnorderedNearQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2878/lucene/core/src/java/org/apache/lucene/search/posfilter/UnorderedNearQuery.java?rev=1644050&r1=1644049&r2=1644050&view=diff
==============================================================================
--- lucene/dev/branches/lucene2878/lucene/core/src/java/org/apache/lucene/search/posfilter/UnorderedNearQuery.java (original)
+++ lucene/dev/branches/lucene2878/lucene/core/src/java/org/apache/lucene/search/posfilter/UnorderedNearQuery.java Tue Dec  9 14:06:59 2014
@@ -176,6 +176,18 @@ public class UnorderedNearQuery extends
 
     }
 
+    @Override
+    public float score() throws IOException {
+      return this.simScorer.score(docID(), sloppyFreq());
+    }
+
+    private float sloppyFreq() throws IOException {
+      float f = 0.0f;
+      while (nextPosition() != NO_MORE_POSITIONS) {
+        f += this.simScorer.computeSlopFactor(matchDistance);
+      }
+      return f;
+    }
   }
 
 }

Modified: lucene/dev/branches/lucene2878/lucene/core/src/test/org/apache/lucene/search/posfilter/TestIntervalScoring.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2878/lucene/core/src/test/org/apache/lucene/search/posfilter/TestIntervalScoring.java?rev=1644050&r1=1644049&r2=1644050&view=diff
==============================================================================
--- lucene/dev/branches/lucene2878/lucene/core/src/test/org/apache/lucene/search/posfilter/TestIntervalScoring.java (original)
+++ lucene/dev/branches/lucene2878/lucene/core/src/test/org/apache/lucene/search/posfilter/TestIntervalScoring.java Tue Dec  9 14:06:59 2014
@@ -23,6 +23,7 @@ import org.apache.lucene.document.Docume
 import org.apache.lucene.document.TextField;
 import org.apache.lucene.index.RandomIndexWriter;
 import org.apache.lucene.index.Term;
+import org.apache.lucene.search.Query;
 import org.apache.lucene.search.RegexpQuery;
 import org.apache.lucene.search.TopDocs;
 
@@ -38,10 +39,10 @@ public class TestIntervalScoring extends
   }
 
   private String[] docFields = {
-      "Should we, could we, would we?",
+      "Should we could we would we?",
       "It should -  would it?",
       "It shouldn't",
-      "Should we, should we, should we"
+      "Should we should we should we"
   };
 
   public void testOrderedNearQueryScoring() throws IOException {
@@ -50,6 +51,13 @@ public class TestIntervalScoring extends
     checkScores(q, searcher, 1, 0);
   }
 
+  public void testUnorderedNearQueryScoring() throws IOException {
+
+    Query q = new UnorderedNearQuery(10, makeTermQuery("we"), makeTermQuery("should"));
+    checkScores(q, searcher, 3, 0);
+
+  }
+
   public void testEmptyMultiTermQueryScoring() throws IOException {
     OrderedNearQuery q = new OrderedNearQuery(10, new RegexpQuery(new Term("field", "bar.*")),
                                                   new RegexpQuery(new Term("field", "foo.*")));