LUCENE-6393: add equivalence tests for SpanFirstQuery.

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1671137 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2015-04-03 19:43:41 +00:00
parent dcdb496bef
commit 7ee772616f
2 changed files with 122 additions and 0 deletions

View File

@ -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 extends SearchEquivalenceTestBase {
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);
}
}

View File

@ -263,6 +263,9 @@ public abstract class SearchEquivalenceTestBase extends LuceneTestCase {
* 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);