Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

additional span tests that have been lingering in my working copy for ages

Erik Hatcher9713d6c30e34
diff --git a/src/test/org/apache/lucene/search/spans/TestSpans.java b/src/test/org/apache/lucene/search/spans/TestSpans.java
index fad44ca5718..fe8cb90aad2 100644
--- a/src/test/org/apache/lucene/search/spans/TestSpans.java
+++ b/src/test/org/apache/lucene/search/spans/TestSpans.java
@@ -1,7 +1,7 @@
package org.apache.lucene.search.spans;
/**
- * Copyright 2004 The Apache Software Foundation
+ * Copyright 2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -44,6 +44,7 @@ public class TestSpans extends TestCase {
}
writer.close();
searcher = new IndexSearcher(directory);
+//System.out.println("set up " + getName());
}
private String[] docFields = {
@@ -51,7 +52,14 @@ public class TestSpans extends TestCase {
"w1 w3 w2 w3",
"w1 xx w2 yy w3",
"w1 w3 xx w2 yy w3",
- ""
+ "u2 u2 u1",
+ "u2 xx u2 u1",
+ "u2 u2 xx u1",
+ "u2 xx u2 yy u1",
+ "u2 xx u1 u2",
+ "u2 u1 xx u2",
+ "u1 u2 xx u2",
+ "t1 t2 t1 t3 t2 t3"
};
public SpanTermQuery makeSpanTermQuery(String text) {
@@ -62,15 +70,44 @@ public class TestSpans extends TestCase {
CheckHits.checkHits(query, field, searcher, results);
}
- public void orderedSlopTest3(int slop, int[] expectedDocs) throws IOException {
- SpanTermQuery w1 = makeSpanTermQuery("w1");
- SpanTermQuery w2 = makeSpanTermQuery("w2");
- SpanTermQuery w3 = makeSpanTermQuery("w3");
+ private void orderedSlopTest3SQ(
+ SpanQuery q1,
+ SpanQuery q2,
+ SpanQuery q3,
+ int slop,
+ int[] expectedDocs) throws IOException {
boolean ordered = true;
- SpanNearQuery snq = new SpanNearQuery( new SpanQuery[]{w1,w2,w3}, slop, ordered);
+ SpanNearQuery snq = new SpanNearQuery( new SpanQuery[]{q1,q2,q3}, slop, ordered);
checkHits(snq, expectedDocs);
}
+ public void orderedSlopTest3(int slop, int[] expectedDocs) throws IOException {
+ orderedSlopTest3SQ(
+ makeSpanTermQuery("w1"),
+ makeSpanTermQuery("w2"),
+ makeSpanTermQuery("w3"),
+ slop,
+ expectedDocs);
+ }
+
+ public void orderedSlopTest3Equal(int slop, int[] expectedDocs) throws IOException {
+ orderedSlopTest3SQ(
+ makeSpanTermQuery("w1"),
+ makeSpanTermQuery("w3"),
+ makeSpanTermQuery("w3"),
+ slop,
+ expectedDocs);
+ }
+
+ public void orderedSlopTest1Equal(int slop, int[] expectedDocs) throws IOException {
+ orderedSlopTest3SQ(
+ makeSpanTermQuery("u2"),
+ makeSpanTermQuery("u2"),
+ makeSpanTermQuery("u1"),
+ slop,
+ expectedDocs);
+ }
+
public void testSpanNearOrdered01() throws Exception {
orderedSlopTest3(0, new int[] {0});
}
@@ -90,4 +127,66 @@ public class TestSpans extends TestCase {
public void testSpanNearOrdered05() throws Exception {
orderedSlopTest3(4, new int[] {0,1,2,3});
}
+
+ public void testSpanNearOrderedEqual01() throws Exception {
+ orderedSlopTest3Equal(0, new int[] {});
+ }
+
+ public void testSpanNearOrderedEqual02() throws Exception {
+ orderedSlopTest3Equal(1, new int[] {1});
+ }
+
+ public void testSpanNearOrderedEqual03() throws Exception {
+ orderedSlopTest3Equal(2, new int[] {1});
+ }
+
+ public void testSpanNearOrderedEqual04() throws Exception {
+ orderedSlopTest3Equal(3, new int[] {1,3});
+ }
+
+ public void testSpanNearOrderedEqual11() throws Exception {
+ orderedSlopTest1Equal(0, new int[] {4});
+ }
+
+ public void testSpanNearOrderedEqual12() throws Exception {
+ orderedSlopTest1Equal(0, new int[] {4});
+ }
+
+ public void testSpanNearOrderedEqual13() throws Exception {
+ orderedSlopTest1Equal(1, new int[] {4,5,6});
+ }
+
+ public void testSpanNearOrderedEqual14() throws Exception {
+ orderedSlopTest1Equal(2, new int[] {4,5,6,7});
+ }
+
+ public void testSpanNearOrderedEqual15() throws Exception {
+ orderedSlopTest1Equal(3, new int[] {4,5,6,7});
+ }
+
+ public void testSpanNearOrderedOverlap() throws Exception {
+ boolean ordered = true;
+ int slop = 1;
+ SpanNearQuery snq = new SpanNearQuery(
+ new SpanQuery[] {
+ makeSpanTermQuery("t1"),
+ makeSpanTermQuery("t2"),
+ makeSpanTermQuery("t3") },
+ slop,
+ ordered);
+ Spans spans = snq.getSpans(searcher.getIndexReader());
+
+ assertTrue("first range", spans.next());
+ assertEquals("first doc", 11, spans.doc());
+ assertEquals("first start", 0, spans.start());
+ assertEquals("first end", 4, spans.end());
+
+ assertTrue("second range", spans.next());
+ assertEquals("second doc", 11, spans.doc());
+ assertEquals("second start", 2, spans.start());
+ assertEquals("second end", 6, spans.end());
+
+ assertFalse("third range", spans.next());
+ }
+
}