lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sim...@apache.org
Subject svn commit: r1363198 [2/2] - in /lucene/dev/branches/LUCENE-2878/lucene: core/src/java/org/apache/lucene/search/ core/src/java/org/apache/lucene/search/payloads/ core/src/java/org/apache/lucene/search/positions/ core/src/java/org/apache/lucene/search/s...
Date Thu, 19 Jul 2012 01:13:59 GMT
Added: lucene/dev/branches/LUCENE-2878/lucene/core/src/test/org/apache/lucene/search/positions/TestPositionFilterQueries.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/test/org/apache/lucene/search/positions/TestPositionFilterQueries.java?rev=1363198&view=auto
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/test/org/apache/lucene/search/positions/TestPositionFilterQueries.java
(added)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/test/org/apache/lucene/search/positions/TestPositionFilterQueries.java
Thu Jul 19 01:13:58 2012
@@ -0,0 +1,98 @@
+package org.apache.lucene.search.positions;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.lucene.analysis.MockAnalyzer;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.document.TextField;
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.RandomIndexWriter;
+import org.apache.lucene.index.Term;
+import org.apache.lucene.search.*;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.util.LuceneTestCase;
+
+import java.io.IOException;
+
+public class TestPositionFilterQueries extends LuceneTestCase {
+
+  private IndexSearcher searcher;
+  private IndexReader reader;
+  private Directory directory;
+
+  public static final String field = "field";
+
+  @Override
+  public void setUp() throws Exception {
+    super.setUp();
+    directory = newDirectory();
+    RandomIndexWriter writer = new RandomIndexWriter(random(), directory,
+        newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random()))
+            .setMergePolicy(newLogMergePolicy()));
+    for (int i = 0; i < docFields.length; i++) {
+      Document doc = new Document();
+      doc.add(newField(field, docFields[i], TextField.TYPE_STORED));
+      writer.addDocument(doc);
+    }
+    writer.forceMerge(1);
+    reader = writer.getReader();
+    writer.close();
+    searcher = newSearcher(reader);
+  }
+
+  @Override
+  public void tearDown() throws Exception {
+    reader.close();
+    directory.close();
+    super.tearDown();
+  }
+
+  private String[] docFields = {
+    "w1 w2 w3 w4 w5 w6 w7 w8 w9 w10 w11 w12", //0
+    "w1 w3 w4 w5 w6 w7 w8", //1
+    "w1 w3 w10 w4 w5 w6 w7 w8", //2
+    "w1 w3 w2 w4 w5 w6 w7 w8", //3
+  };
+
+  public TermQuery makeTermQuery(String text) {
+    return new TermQuery(new Term(field, text));
+  }
+
+  private void checkHits(Query query, int[] results) throws IOException {
+    CheckHits.checkHits(random(), query, field, searcher, results);
+  }
+
+  // or(w1 pre/2 w2, w1 pre/3 w10)
+  public void testOrNearNearQuery() throws IOException {
+    Query near1 = new OrderedConjunctionQuery(2, makeTermQuery("w1"), makeTermQuery("w2"));
+    Query near2 = new OrderedConjunctionQuery(3, makeTermQuery("w1"), makeTermQuery("w10"));
+    BooleanQuery bq = new BooleanQuery();
+    bq.add(near1, BooleanClause.Occur.SHOULD);
+    bq.add(near2, BooleanClause.Occur.SHOULD);
+
+    checkHits(bq, new int[] { 0, 2, 3 });
+  }
+
+  // (a pre/2 b) pre/6 (c pre/2 d)
+  public void testNearNearNearQuery() throws IOException {
+    Query near1 = new OrderedConjunctionQuery(2, makeTermQuery("w1"), makeTermQuery("w4"));
+    Query near2 = new OrderedConjunctionQuery(2, makeTermQuery("w10"), makeTermQuery("w12"));
+    Query near3 = new OrderedConjunctionQuery(6, near1, near2);
+    checkHits(near3, new int[] { 0 });
+  }
+}

Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/test/org/apache/lucene/search/positions/TestSimplePositions.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/test/org/apache/lucene/search/positions/TestSimplePositions.java?rev=1363198&r1=1363197&r2=1363198&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/test/org/apache/lucene/search/positions/TestSimplePositions.java
(original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/test/org/apache/lucene/search/positions/TestSimplePositions.java
Thu Jul 19 01:13:58 2012
@@ -17,8 +17,6 @@ package org.apache.lucene.search.positio
  * limitations under the License.
  */
 
-import java.io.IOException;
-
 import org.apache.lucene.analysis.MockAnalyzer;
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.TextField;
@@ -26,20 +24,15 @@ import org.apache.lucene.index.AtomicRea
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.RandomIndexWriter;
 import org.apache.lucene.index.Term;
-import org.apache.lucene.search.BooleanClause;
+import org.apache.lucene.search.*;
 import org.apache.lucene.search.BooleanClause.Occur;
-import org.apache.lucene.search.BooleanQuery;
-import org.apache.lucene.search.CheckHits;
-import org.apache.lucene.search.IndexSearcher;
-import org.apache.lucene.search.Query;
-import org.apache.lucene.search.Scorer;
-import org.apache.lucene.search.TermQuery;
-import org.apache.lucene.search.Weight;
 import org.apache.lucene.search.positions.PositionIntervalIterator.PositionInterval;
 import org.apache.lucene.search.positions.PositionIntervalIterator.PositionIntervalFilter;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.util.LuceneTestCase;
 
+import java.io.IOException;
+
 public class TestSimplePositions extends LuceneTestCase {
   private IndexSearcher searcher;
   private IndexReader reader;
@@ -100,8 +93,7 @@ public class TestSimplePositions extends
     query.add(q1, Occur.MUST);
     query.add(q2, Occur.MUST);
     query.add(q3, Occur.MUST);
-    Query snq = new PositionFilterQuery(query, new WithinOrderedFilter(slop
-        + query.clauses().size() - 1));
+    Query snq = new PositionFilterQuery(query, new WithinOrderedFilter(slop));
     checkHits(snq, expectedDocs);
   }
   
@@ -211,22 +203,7 @@ public class TestSimplePositions extends
   
    assertNull("third range", positions.next());
    }
-  public static class WithinOrderedFilter implements PositionIntervalFilter {
-    
-    private int slop;
-    
-    public WithinOrderedFilter(int slop) {
-      this.slop = slop;
-    }
-    
-    @Override
-    public PositionIntervalIterator filter(PositionIntervalIterator iter) {
-      return new WithinPositionIterator(slop,
-          new OrderedConjunctionPositionIterator(false, iter));
-    }
-    
-  }
-  
+
   public static class BlockPositionIteratorFilter implements PositionIntervalFilter {
 
     @Override
@@ -241,7 +218,7 @@ public class TestSimplePositions extends
       query.add(makeTermQuery("u1"), Occur.MUST);
       query.add(makeTermQuery("u2"), Occur.MUST);
       Query snq = new PositionFilterQuery(query, new WithinPositionIterator(
-          query.clauses().size() - 1));
+          0));
       Query rewrite = this.searcher.rewrite(snq);
       AtomicReader r = this.reader.getTopReaderContext().leaves().get(0).reader();
       Weight createWeight = rewrite.createWeight(new IndexSearcher(r));
@@ -283,6 +260,8 @@ public class TestSimplePositions extends
       assertEquals("doc", 10, positions.docID());
       assertEquals("start", 0, interval.begin);
       assertEquals("end", 1, interval.end);
+      
+     
       assertNull("Has next and it shouldn't: " + positions.docID(), positions.next());
     }
     
@@ -292,7 +271,7 @@ public class TestSimplePositions extends
       query.add(makeTermQuery("u1"), Occur.MUST);
       query.add(makeTermQuery("u2"), Occur.MUST);
       Query nearQuery = new PositionFilterQuery(query,
-          new WithinPositionIterator(1));
+          new WithinPositionIterator(0));
       
       BooleanQuery topLevel = new BooleanQuery();
       topLevel.add(nearQuery, Occur.MUST);
@@ -300,14 +279,14 @@ public class TestSimplePositions extends
 
 
       Query rewrite = this.searcher.rewrite(new PositionFilterQuery(topLevel,
-          new WithinPositionIterator(3)));
+          new WithinPositionIterator(1)));
       AtomicReader r = this.reader.getTopReaderContext().leaves().get(0).reader();
       Weight createWeight = rewrite.createWeight(new IndexSearcher(r));
       Scorer scorer = createWeight.scorer(r.getTopReaderContext(), random()
           .nextBoolean(), true, r.getLiveDocs());
       
       PositionIntervalIterator iterator = scorer.positions(false, false, false);
-      iterator.advanceTo(4);
+      assertEquals(4,iterator.advanceTo(4));
       PositionInterval interval = iterator.next();
       assertNotNull("Does not have next and it should", interval);
       assertEquals("doc", 4, iterator.docID());
@@ -371,7 +350,7 @@ public class TestSimplePositions extends
       assertEquals("end", 1, interval.end);
       
       interval = iterator.next();
-      assertNull("Has next and it shouldn't", interval);
+      assertNull("Has next and it shouldn't " + interval, interval);
     }
   }
   

Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/test/org/apache/lucene/search/spans/TestNearSpansOrdered.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/test/org/apache/lucene/search/spans/TestNearSpansOrdered.java?rev=1363198&r1=1363197&r2=1363198&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/test/org/apache/lucene/search/spans/TestNearSpansOrdered.java
(original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/test/org/apache/lucene/search/spans/TestNearSpansOrdered.java
Thu Jul 19 01:13:58 2012
@@ -25,19 +25,11 @@ import org.apache.lucene.index.IndexRead
 import org.apache.lucene.index.RandomIndexWriter;
 import org.apache.lucene.index.IndexReaderContext;
 import org.apache.lucene.index.Term;
-import org.apache.lucene.search.BooleanClause;
-import org.apache.lucene.search.BooleanClause.Occur;
-import org.apache.lucene.search.BooleanQuery;
 import org.apache.lucene.search.CheckHits;
 import org.apache.lucene.search.Explanation;
 import org.apache.lucene.search.IndexSearcher;
-import org.apache.lucene.search.TermQuery;
 import org.apache.lucene.search.Weight;
 import org.apache.lucene.search.Scorer;
-import org.apache.lucene.search.positions.OrderedConjunctionPositionIterator;
-import org.apache.lucene.search.positions.PositionIntervalIterator;
-import org.apache.lucene.search.positions.PositionIntervalIterator.PositionIntervalFilter;
-import org.apache.lucene.search.positions.WithinPositionIterator;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.util.LuceneTestCase;
 
@@ -77,44 +69,22 @@ public class TestNearSpansOrdered extend
     "w1 w3 xx w2 yy w3 zz"
   };
 
-  protected SpanQuery makeQuery(String s1, String s2, String s3,
+  protected SpanNearQuery makeQuery(String s1, String s2, String s3,
                                     int slop, boolean inOrder) {
-//    return new SpanNearQuery
-//      (new SpanQuery[] {
-//        new SpanTermQuery(new Term(FIELD, s1)),
-//        new SpanTermQuery(new Term(FIELD, s2)),
-//        new SpanTermQuery(new Term(FIELD, s3)) },
-//       slop,
-//       inOrder);
-//    
-    BooleanQuery query = new BooleanQuery();
-    query.add(new BooleanClause(new TermQuery(new Term(FIELD, s1)), Occur.MUST));
-        query.add(new BooleanClause(new TermQuery(new Term(FIELD, s2)), Occur.MUST));
-        query.add(new BooleanClause(new TermQuery(new Term(FIELD, s3)), Occur.MUST));
-        return new MockSpanQuery(query, false, FIELD, new Filter(3 + slop-1));
-  }
-  
-  public static class Filter implements PositionIntervalFilter {
-    
-    private int slop;
-    
-    public Filter(int slop) {
-      this.slop = slop;
-    }
-    
-    @Override
-    public PositionIntervalIterator filter(PositionIntervalIterator iter) {
-      return new WithinPositionIterator(slop,
-          new OrderedConjunctionPositionIterator(false, iter));
-    }
-    
+    return new SpanNearQuery
+      (new SpanQuery[] {
+        new SpanTermQuery(new Term(FIELD, s1)),
+        new SpanTermQuery(new Term(FIELD, s2)),
+        new SpanTermQuery(new Term(FIELD, s3)) },
+       slop,
+       inOrder);
   }
-  protected SpanQuery makeQuery() {
+  protected SpanNearQuery makeQuery() {
     return makeQuery("w1","w2","w3",1,true);
   }
   
   public void testSpanNearQuery() throws Exception {
-    SpanQuery q = makeQuery();
+    SpanNearQuery q = makeQuery();
     CheckHits.checkHits(random(), q, FIELD, searcher, new int[] {0,1});
   }
 
@@ -126,7 +96,7 @@ public class TestNearSpansOrdered extend
   }
   
   public void testNearSpansNext() throws Exception {
-    SpanQuery q = makeQuery();
+    SpanNearQuery q = makeQuery();
     Spans span = MultiSpansWrapper.wrap(searcher.getTopReaderContext(), q);
     assertEquals(true, span.next());
     assertEquals(s(0,0,3), s(span));
@@ -141,7 +111,7 @@ public class TestNearSpansOrdered extend
    * does not contain more than one span
    */
   public void testNearSpansSkipToLikeNext() throws Exception {
-    SpanQuery q = makeQuery();
+    SpanNearQuery q = makeQuery();
     Spans span =  MultiSpansWrapper.wrap(searcher.getTopReaderContext(), q);
     assertEquals(true, span.skipTo(0));
     assertEquals(s(0,0,3), s(span));
@@ -151,7 +121,7 @@ public class TestNearSpansOrdered extend
   }
   
   public void testNearSpansNextThenSkipTo() throws Exception {
-    SpanQuery q = makeQuery();
+    SpanNearQuery q = makeQuery();
     Spans span =  MultiSpansWrapper.wrap(searcher.getTopReaderContext(), q);
     assertEquals(true, span.next());
     assertEquals(s(0,0,3), s(span));
@@ -161,7 +131,7 @@ public class TestNearSpansOrdered extend
   }
   
   public void testNearSpansNextThenSkipPast() throws Exception {
-    SpanQuery q = makeQuery();
+    SpanNearQuery q = makeQuery();
     Spans span =  MultiSpansWrapper.wrap(searcher.getTopReaderContext(), q);
     assertEquals(true, span.next());
     assertEquals(s(0,0,3), s(span));
@@ -169,20 +139,20 @@ public class TestNearSpansOrdered extend
   }
   
   public void testNearSpansSkipPast() throws Exception {
-    SpanQuery q = makeQuery();
+    SpanNearQuery q = makeQuery();
     Spans span =  MultiSpansWrapper.wrap(searcher.getTopReaderContext(), q);
     assertEquals(false, span.skipTo(2));
   }
   
   public void testNearSpansSkipTo0() throws Exception {
-    SpanQuery q = makeQuery();
+    SpanNearQuery q = makeQuery();
     Spans span = MultiSpansWrapper.wrap(searcher.getTopReaderContext(), q);
     assertEquals(true, span.skipTo(0));
     assertEquals(s(0,0,3), s(span));
   }
 
   public void testNearSpansSkipTo1() throws Exception {
-    SpanQuery q = makeQuery();
+    SpanNearQuery q = makeQuery();
     Spans span =  MultiSpansWrapper.wrap(searcher.getTopReaderContext(), q);
     assertEquals(true, span.skipTo(1));
     assertEquals(s(1,0,4), s(span));
@@ -193,7 +163,7 @@ public class TestNearSpansOrdered extend
    * this causes problems
    */
   public void testSpanNearScorerSkipTo1() throws Exception {
-    SpanQuery q = makeQuery();
+    SpanNearQuery q = makeQuery();
     Weight w = searcher.createNormalizedWeight(q);
     IndexReaderContext topReaderContext = searcher.getTopReaderContext();
     AtomicReaderContext leave = topReaderContext.leaves().get(0);
@@ -206,7 +176,7 @@ public class TestNearSpansOrdered extend
    * this causes problems
    */
   public void testSpanNearScorerExplain() throws Exception {
-    SpanQuery q = makeQuery();
+    SpanNearQuery q = makeQuery();
     Explanation e = searcher.explain(q, 1);
     assertTrue("Scorer explanation value for doc#1 isn't positive: "
                + e.toString(),

Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/test/org/apache/lucene/search/spans/TestPayloadSpans.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/test/org/apache/lucene/search/spans/TestPayloadSpans.java?rev=1363198&r1=1363197&r2=1363198&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/test/org/apache/lucene/search/spans/TestPayloadSpans.java
(original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/test/org/apache/lucene/search/spans/TestPayloadSpans.java
Thu Jul 19 01:13:58 2012
@@ -408,7 +408,7 @@ public class TestPayloadSpans extends Lu
       //See payload helper, for the PayloadHelper.FIELD field, there is a single byte payload
at every token
       if (spans.isPayloadAvailable()) {
         Collection<byte[]> payload = spans.getPayload();
-        assertTrue("payload Size: " + payload.size() + " is not: " + expectedNumPayloads
+ " span: " + spans.doc() + " " + spans.start(), payload.size() == expectedNumPayloads);
+        assertTrue("payload Size: " + payload.size() + " is not: " + expectedNumPayloads,
payload.size() == expectedNumPayloads);
         for (final byte [] thePayload : payload) {
           assertTrue("payload[0] Size: " + thePayload.length + " is not: " + expectedPayloadLength,
                   thePayload.length == expectedPayloadLength);

Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/test/org/apache/lucene/search/spans/TestSpanFirstQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/test/org/apache/lucene/search/spans/TestSpanFirstQuery.java?rev=1363198&r1=1363197&r2=1363198&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/test/org/apache/lucene/search/spans/TestSpanFirstQuery.java
(original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/test/org/apache/lucene/search/spans/TestSpanFirstQuery.java
Thu Jul 19 01:13:58 2012
@@ -22,13 +22,10 @@ import org.apache.lucene.analysis.MockAn
 import org.apache.lucene.analysis.MockTokenizer;
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.Field;
-import org.apache.lucene.document.TextField;
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.RandomIndexWriter;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.search.IndexSearcher;
-import org.apache.lucene.search.TermQuery;
-import org.apache.lucene.search.positions.RangePositionsIterator;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.util.LuceneTestCase;
 import org.apache.lucene.util.automaton.CharacterRunAutomaton;
@@ -66,36 +63,4 @@ public class TestSpanFirstQuery extends 
     reader.close();
     dir.close();
   }
-  
-  public void testStartPositionsAlt() throws Exception {
-    Directory dir = newDirectory();
-    
-    // mimic StopAnalyzer
-    CharacterRunAutomaton stopSet = new CharacterRunAutomaton(new RegExp("the|a|of").toAutomaton());
-    Analyzer analyzer = new MockAnalyzer(random(), MockTokenizer.SIMPLE, true, stopSet, true);
-    
-    RandomIndexWriter writer = new RandomIndexWriter(random(), dir, analyzer);
-    Document doc = new Document();
-    doc.add(newField("field", "the quick brown fox", TextField.TYPE_NOT_STORED));
-    writer.addDocument(doc);
-    Document doc2 = new Document();
-    doc2.add(newField("field", "quick brown fox", TextField.TYPE_NOT_STORED));
-    writer.addDocument(doc2);
-    
-    IndexReader reader = writer.getReader();
-    IndexSearcher searcher = new IndexSearcher(reader);
-    
-    // user queries on "starts-with quick"
-    SpanQuery sfq = new MockSpanQuery(new TermQuery(new Term("field", "quick")), false,"field",
new RangePositionsIterator(0, 0));
-    assertEquals(1, searcher.search(sfq, 10).totalHits);
-    
-    // user queries on "starts-with the quick"
-    SpanQuery include =  new MockSpanQuery(new TermQuery(new Term("field", "quick")), false,"field",
new RangePositionsIterator(0, 1));
-    sfq = new SpanNotQuery(include, sfq);
-    assertEquals(1, searcher.search(sfq, 10).totalHits);
-    
-    writer.close();
-    reader.close();
-    dir.close();
-  }
 }

Modified: lucene/dev/branches/LUCENE-2878/lucene/core/src/test/org/apache/lucene/search/spans/TestSpans.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/core/src/test/org/apache/lucene/search/spans/TestSpans.java?rev=1363198&r1=1363197&r2=1363198&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/core/src/test/org/apache/lucene/search/spans/TestSpans.java
(original)
+++ lucene/dev/branches/LUCENE-2878/lucene/core/src/test/org/apache/lucene/search/spans/TestSpans.java
Thu Jul 19 01:13:58 2012
@@ -32,19 +32,12 @@ import org.apache.lucene.index.IndexWrit
 import org.apache.lucene.index.RandomIndexWriter;
 import org.apache.lucene.index.ReaderUtil;
 import org.apache.lucene.index.Term;
-import org.apache.lucene.search.BooleanClause;
-import org.apache.lucene.search.BooleanClause.Occur;
-import org.apache.lucene.search.BooleanQuery;
 import org.apache.lucene.search.CheckHits;
 import org.apache.lucene.search.DocIdSetIterator;
 import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.search.Query;
 import org.apache.lucene.search.Scorer;
 import org.apache.lucene.search.TermQuery;
-import org.apache.lucene.search.positions.OrderedConjunctionPositionIterator;
-import org.apache.lucene.search.positions.PositionIntervalIterator;
-import org.apache.lucene.search.positions.PositionIntervalIterator.PositionIntervalFilter;
-import org.apache.lucene.search.positions.WithinPositionIterator;
 import org.apache.lucene.search.similarities.DefaultSimilarity;
 import org.apache.lucene.search.similarities.Similarity;
 import org.apache.lucene.store.Directory;
@@ -199,19 +192,13 @@ public class TestSpans extends LuceneTes
   public void testSpanNearOrderedOverlap() throws Exception {
     boolean ordered = true;
     int slop = 1;
-    
-    BooleanQuery query = new BooleanQuery();
-    query.add(new BooleanClause(new TermQuery(new Term(field, "t1")), Occur.MUST));
-    query.add(new BooleanClause(new TermQuery(new Term(field, "t2")), Occur.MUST));
-    query.add(new BooleanClause(new TermQuery(new Term(field, "t3")), Occur.MUST));
-    SpanQuery snq =  new MockSpanQuery(query, false, field, new Filter(3 + slop-1));
-//    SpanNearQuery snq = new SpanNearQuery(
-//                              new SpanQuery[] {
-//                                makeSpanTermQuery("t1"),
-//                                makeSpanTermQuery("t2"),
-//                                makeSpanTermQuery("t3") },
-//                              slop,
-//                              ordered);
+    SpanNearQuery snq = new SpanNearQuery(
+                              new SpanQuery[] {
+                                makeSpanTermQuery("t1"),
+                                makeSpanTermQuery("t2"),
+                                makeSpanTermQuery("t3") },
+                              slop,
+                              ordered);
     Spans spans = MultiSpansWrapper.wrap(searcher.getTopReaderContext(), snq);
 
     assertTrue("first range", spans.next());
@@ -226,19 +213,7 @@ public class TestSpans extends LuceneTes
 
     assertFalse("third range", spans.next());
   }
-  public static class Filter implements PositionIntervalFilter {
 
-    private int slop;
-    public Filter(int slop) {
-      this.slop = slop;
-    }
-    @Override
-    public PositionIntervalIterator filter(PositionIntervalIterator iter) {
-      return new WithinPositionIterator(slop, new OrderedConjunctionPositionIterator(false,
iter));
-//      return new OrderedConjunctionPositionIterator(iter);
-    }
-    
-  }
 
   public void testSpanNearUnOrdered() throws Exception {
 

Modified: lucene/dev/branches/LUCENE-2878/lucene/highlighter/src/java/org/apache/lucene/search/poshighlight/PositionIntervalArrayIterator.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/highlighter/src/java/org/apache/lucene/search/poshighlight/PositionIntervalArrayIterator.java?rev=1363198&r1=1363197&r2=1363198&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/highlighter/src/java/org/apache/lucene/search/poshighlight/PositionIntervalArrayIterator.java
(original)
+++ lucene/dev/branches/LUCENE-2878/lucene/highlighter/src/java/org/apache/lucene/search/poshighlight/PositionIntervalArrayIterator.java
Thu Jul 19 01:13:58 2012
@@ -58,5 +58,10 @@ public class PositionIntervalArrayIterat
   public int advanceTo(int docId) throws IOException {
     return 0;
   }
+
+  @Override
+  public int matchDistance() {
+    return 0;
+  }
   
 }
\ No newline at end of file

Modified: lucene/dev/branches/LUCENE-2878/lucene/highlighter/src/test/org/apache/lucene/search/poshighlight/PosHighlighterTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/LUCENE-2878/lucene/highlighter/src/test/org/apache/lucene/search/poshighlight/PosHighlighterTest.java?rev=1363198&r1=1363197&r2=1363198&view=diff
==============================================================================
--- lucene/dev/branches/LUCENE-2878/lucene/highlighter/src/test/org/apache/lucene/search/poshighlight/PosHighlighterTest.java
(original)
+++ lucene/dev/branches/LUCENE-2878/lucene/highlighter/src/test/org/apache/lucene/search/poshighlight/PosHighlighterTest.java
Thu Jul 19 01:13:58 2012
@@ -41,6 +41,7 @@ import org.apache.lucene.search.highligh
 import org.apache.lucene.search.highlight.SimpleFragmenter;
 import org.apache.lucene.search.highlight.TextFragment;
 import org.apache.lucene.search.positions.BlockPositionIterator;
+import org.apache.lucene.search.positions.BrouwerianQuery;
 import org.apache.lucene.search.positions.PositionFilterQuery;
 import org.apache.lucene.search.positions.PositionIntervalIterator;
 import org.apache.lucene.search.positions.PositionIntervalIterator.PositionIntervalFilter;
@@ -382,6 +383,22 @@ public class PosHighlighterTest extends 
     close();
   }
   
+  public void testBrouwerianQuery() throws Exception {
+    BooleanQuery query = new BooleanQuery();
+    query.add(new BooleanClause(new TermQuery(new Term(F, "the")), Occur.MUST));
+    query.add(new BooleanClause(new TermQuery(new Term(F, "quick")), Occur.MUST));
+    query.add(new BooleanClause(new TermQuery(new Term(F, "jumps")), Occur.MUST));
+    BooleanQuery sub = new BooleanQuery();
+    sub.add(new BooleanClause(new TermQuery(new Term(F, "fox")), Occur.MUST));
+    insertDocs(analyzer, "the quick brown duck jumps over the lazy dog with the quick brown
fox");
+
+    BrouwerianQuery q = new BrouwerianQuery(query, sub);
+    String[] frags = doSearch(q, Integer.MAX_VALUE);
+    assertEquals("<B>the</B> <B>quick</B> brown duck <B>jumps</B>
over <B>the</B> lazy dog with the <B>quick</B> brown fox", frags[0]);
+
+    close();
+  }
+  
   public void testMultiPhraseQuery() throws Exception {
     MultiPhraseQuery query = new MultiPhraseQuery();
     insertDocs(analyzer, "pease porridge hot but not too hot or otherwise pease porridge
cold");



Mime
View raw message