lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rm...@apache.org
Subject svn commit: r1671137 - in /lucene/dev/trunk/lucene: core/src/test/org/apache/lucene/search/spans/TestSpanSearchEquivalence.java test-framework/src/java/org/apache/lucene/search/SearchEquivalenceTestBase.java
Date Fri, 03 Apr 2015 19:43:42 GMT
Author: rmuir
Date: Fri Apr  3 19:43:41 2015
New Revision: 1671137

URL: http://svn.apache.org/r1671137
Log:
LUCENE-6393: add equivalence tests for SpanFirstQuery.

Modified:
    lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/search/spans/TestSpanSearchEquivalence.java
    lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/search/SearchEquivalenceTestBase.java

Modified: lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/search/spans/TestSpanSearchEquivalence.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/search/spans/TestSpanSearchEquivalence.java?rev=1671137&r1=1671136&r2=1671137&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/search/spans/TestSpanSearchEquivalence.java
(original)
+++ lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/search/spans/TestSpanSearchEquivalence.java
Fri Apr  3 19:43:41 2015
@@ -21,6 +21,7 @@ import org.apache.lucene.index.Term;
 import org.apache.lucene.search.BooleanClause.Occur;
 import org.apache.lucene.search.BooleanQuery;
 import org.apache.lucene.search.PhraseQuery;
+import org.apache.lucene.search.Query;
 import org.apache.lucene.search.SearchEquivalenceTestBase;
 import org.apache.lucene.search.TermQuery;
 
@@ -106,4 +107,122 @@ public class TestSpanSearchEquivalence e
     SpanNearQuery q2 = new SpanNearQuery(subquery, 3, false);
     assertSubsetOf(q1, q2);
   }
+  
+  /** SpanNearQuery([A B], N, false) ⊆ SpanNearQuery([A B], N+1, false) */
+  public void testSpanNearIncreasingSloppiness() throws Exception {
+    Term t1 = randomTerm();
+    Term t2 = randomTerm();
+    SpanQuery subquery[] = new SpanQuery[] { new SpanTermQuery(t1), new SpanTermQuery(t2)
};
+    for (int i = 0; i < 10; i++) {
+      SpanNearQuery q1 = new SpanNearQuery(subquery, i, false);
+      SpanNearQuery q2 = new SpanNearQuery(subquery, i+1, false);
+      assertSubsetOf(q1, q2);
+    }
+  }
+  
+  /** SpanNearQuery([A B C], N, false) ⊆ SpanNearQuery([A B C], N+1, false) */
+  public void testSpanNearIncreasingSloppiness3() throws Exception {
+    Term t1 = randomTerm();
+    Term t2 = randomTerm();
+    Term t3 = randomTerm();
+    SpanQuery subquery[] = new SpanQuery[] { new SpanTermQuery(t1), new SpanTermQuery(t2),
new SpanTermQuery(t3) };
+    for (int i = 0; i < 10; i++) {
+      SpanNearQuery q1 = new SpanNearQuery(subquery, i, false);
+      SpanNearQuery q2 = new SpanNearQuery(subquery, i+1, false);
+      assertSubsetOf(q1, q2);
+    }
+  }
+  
+  /** SpanNearQuery([A B], N, true) ⊆ SpanNearQuery([A B], N+1, true) */
+  public void testSpanNearIncreasingOrderedSloppiness() throws Exception {
+    Term t1 = randomTerm();
+    Term t2 = randomTerm();
+    SpanQuery subquery[] = new SpanQuery[] { new SpanTermQuery(t1), new SpanTermQuery(t2)
};
+    for (int i = 0; i < 10; i++) {
+      SpanNearQuery q1 = new SpanNearQuery(subquery, i, false);
+      SpanNearQuery q2 = new SpanNearQuery(subquery, i+1, false);
+      assertSubsetOf(q1, q2);
+    }
+  }
+  
+  /** SpanNearQuery([A B C], N, true) ⊆ SpanNearQuery([A B C], N+1, true) */
+  public void testSpanNearIncreasingOrderedSloppiness3() throws Exception {
+    Term t1 = randomTerm();
+    Term t2 = randomTerm();
+    Term t3 = randomTerm();
+    SpanQuery subquery[] = new SpanQuery[] { new SpanTermQuery(t1), new SpanTermQuery(t2),
new SpanTermQuery(t3) };
+    for (int i = 0; i < 10; i++) {
+      SpanNearQuery q1 = new SpanNearQuery(subquery, i, true);
+      SpanNearQuery q2 = new SpanNearQuery(subquery, i+1, true);
+      assertSubsetOf(q1, q2);
+    }
+  }
+  
+  /** SpanFirstQuery(A, N) ⊆ TermQuery(A) */
+  public void testSpanFirstTerm() throws Exception {
+    Term t1 = randomTerm();
+    for (int i = 0; i < 10; i++) {
+      Query q1 = new SpanFirstQuery(new SpanTermQuery(t1), i);
+      Query q2 = new TermQuery(t1);
+      assertSubsetOf(q1, q2);
+    }
+  }
+  
+  /** SpanFirstQuery(A, N) ⊆ SpanFirstQuery(A, N+1) */
+  public void testSpanFirstTermIncreasing() throws Exception {
+    Term t1 = randomTerm();
+    for (int i = 0; i < 10; i++) {
+      Query q1 = new SpanFirstQuery(new SpanTermQuery(t1), i);
+      Query q2 = new SpanFirstQuery(new SpanTermQuery(t1), i+1);
+      assertSubsetOf(q1, q2);
+    }
+  }
+  
+  /** SpanFirstQuery(A, ∞) = TermQuery(A) */
+  public void testSpanFirstTermEverything() throws Exception {
+    Term t1 = randomTerm();
+    Query q1 = new SpanFirstQuery(new SpanTermQuery(t1), Integer.MAX_VALUE);
+    Query q2 = new TermQuery(t1);
+    assertSameSet(q1, q2);
+  }
+  
+  /** SpanFirstQuery([A B], N) ⊆ SpanNearQuery([A B]) */
+  @AwaitsFix(bugUrl = "https://issues.apache.org/jira/browse/LUCENE-6393")
+  public void testSpanFirstNear() throws Exception {
+    Term t1 = randomTerm();
+    Term t2 = randomTerm();
+    SpanQuery subquery[] = new SpanQuery[] { new SpanTermQuery(t1), new SpanTermQuery(t2)
};
+    SpanQuery nearQuery = new SpanNearQuery(subquery, 10, true);
+    for (int i = 0; i < 10; i++) {
+      Query q1 = new SpanFirstQuery(nearQuery, i);
+      Query q2 = nearQuery;
+      assertSubsetOf(q1, q2);
+    }
+  }
+  
+  /** SpanFirstQuery([A B], N) ⊆ SpanFirstQuery([A B], N+1) */
+  @AwaitsFix(bugUrl = "https://issues.apache.org/jira/browse/LUCENE-6393")
+  public void testSpanFirstNearIncreasing() throws Exception {
+    Term t1 = randomTerm();
+    Term t2 = randomTerm();
+    SpanQuery subquery[] = new SpanQuery[] { new SpanTermQuery(t1), new SpanTermQuery(t2)
};
+    SpanQuery nearQuery = new SpanNearQuery(subquery, 10, true);
+    for (int i = 0; i < 10; i++) {
+      Query q1 = new SpanFirstQuery(nearQuery, i);
+      Query q2 = new SpanFirstQuery(nearQuery, i+1);
+      assertSubsetOf(q1, q2);
+    }
+  }
+  
+  /** SpanFirstQuery([A B], ∞) = SpanNearQuery([A B]) */
+  @AwaitsFix(bugUrl = "https://issues.apache.org/jira/browse/LUCENE-6393")
+  public void testSpanFirstNearEverything() throws Exception {
+    Term t1 = randomTerm();
+    Term t2 = randomTerm();
+    SpanQuery subquery[] = new SpanQuery[] { new SpanTermQuery(t1), new SpanTermQuery(t2)
};
+    SpanQuery nearQuery = new SpanNearQuery(subquery, 10, true);
+    Query q1 = new SpanFirstQuery(nearQuery, Integer.MAX_VALUE);
+    Query q2 = nearQuery;
+    assertSameSet(q1, q2);
+  }
 }

Modified: lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/search/SearchEquivalenceTestBase.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/search/SearchEquivalenceTestBase.java?rev=1671137&r1=1671136&r2=1671137&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/search/SearchEquivalenceTestBase.java
(original)
+++ lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/search/SearchEquivalenceTestBase.java
Fri Apr  3 19:43:41 2015
@@ -263,6 +263,9 @@ public abstract class SearchEquivalenceT
    * Both queries will be filtered by <code>filter</code>
    */
   protected void assertSubsetOf(Query q1, Query q2, Filter filter) throws Exception {
+    QueryUtils.check(q1);
+    QueryUtils.check(q2);
+
     if (filter != null) {
       q1 = new FilteredQuery(q1, filter);
       q2 = new FilteredQuery(q2, filter);



Mime
View raw message