You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by Jean-Francois Halleux <ha...@skynet.be> on 2004/02/10 10:55:58 UTC

Wrong attachement to 6091

Hi,

	I attached a patch to bug 6091 by mistake. Somebody with enough manas could
try to cast a spell to remove it.

Sorry for that,

Jean-Francois Halleux

-----Original Message-----
From: cutting@apache.org [mailto:cutting@apache.org]
Sent: lundi 9 février 2004 23:26
To: jakarta-lucene-cvs@apache.org
Subject: cvs commit: jakarta-lucene/src/test/org/apache/lucene/search
TestBasics.java


cutting     2004/02/09 14:25:51

  Modified:    src/java/org/apache/lucene/search/spans NearSpans.java
               src/test/org/apache/lucene/search TestBasics.java
  Log:
  A span search optimization.

  Revision  Changes    Path
  1.4       +28 -17
jakarta-lucene/src/java/org/apache/lucene/search/spans/NearSpans.java

  Index: NearSpans.java
  ===================================================================
  RCS file:
/home/cvs/jakarta-lucene/src/java/org/apache/lucene/search/spans/NearSpans.j
ava,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- NearSpans.java	9 Feb 2004 22:03:42 -0000	1.3
  +++ NearSpans.java	9 Feb 2004 22:25:51 -0000	1.4
  @@ -175,11 +175,8 @@
           queueStale = false;
         }

  -      int matchLength = max.end() - min().start();
  -      if (((matchLength - totalLength) <= slop)   // check slop
  -          && (!inOrder || matchIsOrdered())) {    // check order
  +      if (atMatch())
           return true;
  -      }

         more = min().next();                        // trigger further
scanning
         if (more)
  @@ -189,24 +186,26 @@
     }

     public boolean skipTo(int target) throws IOException {
  -    if (firstTime) {
  +    if (firstTime) {                              // initialize
         initList(false);
  +      for (SpansCell cell = first; more && cell!=null; cell=cell.next) {
  +        more = cell.skipTo(target);               // skip all
  +      }
  +      if (more) {
  +        listToQueue();
  +      }
         firstTime = false;
  +    } else {                                      // normal case
  +      while (more && min().doc() < target) {      // skip as needed
  +        more = min().skipTo(target);
  +        if (more)
  +          queue.adjustTop();
  +      }
       }
  -
  -    for (SpansCell cell = first; more && cell!=null; cell=cell.next) {
  -      more = cell.skipTo(target);
  -    }
  -
       if (more) {
  -      listToQueue();

  -      if (min().doc() == max.doc()) {             // at a match?
  -        int matchLength = max.end() - min().start();
  -        if ((matchLength - totalLength) <= slop) {
  -          return true;
  -        }
  -      }
  +      if (atMatch())                              // at a match?
  +        return true;

         return next();                              // no, scan
       }
  @@ -220,6 +219,7 @@
     public int start() { return min().start(); }
     public int end() { return max.end(); }

  +
     public String toString() {
       return "spans("+query.toString()+")@"+
         (firstTime?"START":(more?(doc()+":"+start()+"-"+end()):"END"));
  @@ -264,6 +264,17 @@
       for (SpansCell cell = first; cell != null; cell = cell.next) {
         queue.put(cell);                      // build queue from list
       }
  +  }
  +
  +  private boolean atMatch() {
  +    if (min().doc() == max.doc()) {               // at a match?
  +      int matchLength = max.end() - min().start();
  +      if (((matchLength - totalLength) <= slop)   // check slop
  +          && (!inOrder || matchIsOrdered())) {    // check order
  +        return true;
  +      }
  +    }
  +    return false;
     }

     private boolean matchIsOrdered() {



  1.4       +33 -9
jakarta-lucene/src/test/org/apache/lucene/search/TestBasics.java

  Index: TestBasics.java
  ===================================================================
  RCS file:
/home/cvs/jakarta-lucene/src/test/org/apache/lucene/search/TestBasics.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TestBasics.java	9 Feb 2004 22:03:42 -0000	1.3
  +++ TestBasics.java	9 Feb 2004 22:25:51 -0000	1.4
  @@ -160,8 +160,8 @@
       checkHits(query, new int[]
         {77, 177, 277, 377, 477, 577, 677, 777, 877, 977});

  -    //System.out.println(searcher.explain(query, 77));
  -    //System.out.println(searcher.explain(query, 977));
  +    assertTrue(searcher.explain(query, 77).getValue() > 0.0f);
  +    assertTrue(searcher.explain(query, 977).getValue() > 0.0f);
     }

     public void testSpanNearUnordered() throws Exception {
  @@ -195,8 +195,8 @@
       checkHits(query, new int[]
         {801, 821, 831, 851, 861, 871, 881, 891});

  -    //System.out.println(searcher.explain(query, 801));
  -    //System.out.println(searcher.explain(query, 891));
  +    assertTrue(searcher.explain(query, 801).getValue() > 0.0f);
  +    assertTrue(searcher.explain(query, 891).getValue() > 0.0f);
     }

     public void testSpanFirst() throws Exception {
  @@ -213,8 +213,8 @@
          584, 585, 586, 587, 588, 589, 590, 591, 592, 593, 594, 595, 596,
597,
          598, 599});

  -    //System.out.println(searcher.explain(query, 5));
  -    //System.out.println(searcher.explain(query, 599));
  +    assertTrue(searcher.explain(query, 5).getValue() > 0.0f);
  +    assertTrue(searcher.explain(query, 599).getValue() > 0.0f);

     }

  @@ -234,8 +234,8 @@
         {33, 47, 133, 147, 233, 247, 333, 347, 433, 447, 533, 547, 633,
647, 733,
          747, 833, 847, 933, 947});

  -    //System.out.println(searcher.explain(query, 33));
  -    //System.out.println(searcher.explain(query, 947));
  +    assertTrue(searcher.explain(query, 33).getValue() > 0.0f);
  +    assertTrue(searcher.explain(query, 947).getValue() > 0.0f);
     }

     public void testSpanExactNested() throws Exception {
  @@ -253,7 +253,7 @@

       checkHits(query, new int[] {333});

  -    //System.out.println(searcher.explain(query, 333));
  +    assertTrue(searcher.explain(query, 333).getValue() > 0.0f);
     }

     public void testSpanNearOr() throws Exception {
  @@ -277,7 +277,31 @@
          756, 757, 766, 767, 776, 777, 786, 787, 796, 797});
     }

  +  public void testSpanComplex1() throws Exception {
  +
  +    SpanTermQuery t1 = new SpanTermQuery(new Term("field","six"));
  +    SpanTermQuery t2 = new SpanTermQuery(new Term("field","hundred"));
  +    SpanNearQuery tt1 = new SpanNearQuery(new SpanQuery[] {t1, t2},
0,true);
  +
  +    SpanTermQuery t3 = new SpanTermQuery(new Term("field","seven"));
  +    SpanTermQuery t4 = new SpanTermQuery(new Term("field","hundred"));
  +    SpanNearQuery tt2 = new SpanNearQuery(new SpanQuery[] {t3, t4},
0,true);
  +
  +    SpanTermQuery t5 = new SpanTermQuery(new Term("field","seven"));
  +    SpanTermQuery t6 = new SpanTermQuery(new Term("field","six"));

  +    SpanOrQuery to1 = new SpanOrQuery(new SpanQuery[] {tt1, tt2});
  +    SpanOrQuery to2 = new SpanOrQuery(new SpanQuery[] {t5, t6});
  +
  +    SpanNearQuery query = new SpanNearQuery(new SpanQuery[] {to1, to2},
  +                                            100, true);
  +
  +    checkHits(query, new int[]
  +      {606, 607, 626, 627, 636, 637, 646, 647,
  +       656, 657, 666, 667, 676, 677, 686, 687, 696, 697,
  +       706, 707, 726, 727, 736, 737, 746, 747,
  +       756, 757, 766, 767, 776, 777, 786, 787, 796, 797});
  +  }


     private void checkHits(Query query, int[] results) throws IOException {




---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-dev-help@jakarta.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-dev-help@jakarta.apache.org