lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ehatc...@apache.org
Subject svn commit: r329384 - /lucene/java/trunk/src/test/org/apache/lucene/search/spans/TestSpans.java
Date Sat, 29 Oct 2005 09:48:25 GMT
Author: ehatcher
Date: Sat Oct 29 02:48:22 2005
New Revision: 329384

URL: http://svn.apache.org/viewcvs?rev=329384&view=rev
Log:
additional span tests that have been lingering in my working copy for ages

Modified:
    lucene/java/trunk/src/test/org/apache/lucene/search/spans/TestSpans.java

Modified: lucene/java/trunk/src/test/org/apache/lucene/search/spans/TestSpans.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/src/test/org/apache/lucene/search/spans/TestSpans.java?rev=329384&r1=329383&r2=329384&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/spans/TestSpans.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/spans/TestSpans.java Sat Oct 29 02:48:22
2005
@@ -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 @@
     }
     writer.close();
     searcher = new IndexSearcher(directory);
+//System.out.println("set up " + getName());
   }
 
   private String[] docFields = {
@@ -51,7 +52,14 @@
     "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 @@
     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 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());
+  }
+
 }



Mime
View raw message