public void testNearSpansNextThenSkipPast() throws Exception {
   SpanNearQuery q = makeQuery();
   Spans span = q.getSpans(searcher.getIndexReader());
   assertEquals(true, span.next());
   assertEquals(s(0, 0, 3), s(span));
   assertEquals(false, span.skipTo(2));
 }
Example #2
0
  public NearSpans(SpanNearQuery query, IndexReader reader) throws IOException {
    this.query = query;
    this.slop = query.getSlop();
    this.inOrder = query.isInOrder();

    SpanQuery[] clauses = query.getClauses(); // initialize spans & list
    queue = new CellQueue(clauses.length);
    for (int i = 0; i < clauses.length; i++) {
      SpansCell cell = // construct clause spans
          new SpansCell(clauses[i].getSpans(reader), i);
      ordered.add(cell); // add to ordered
    }
  }
 public NearSpansOrdered(SpanNearQuery spanNearQuery, IndexReader reader) throws IOException {
   if (spanNearQuery.getClauses().length < 2) {
     throw new IllegalArgumentException("Less than 2 clauses: " + spanNearQuery);
   }
   allowedSlop = spanNearQuery.getSlop();
   SpanQuery[] clauses = spanNearQuery.getClauses();
   subSpans = new PayloadSpans[clauses.length];
   matchPayload = new LinkedList();
   subSpansByDoc = new PayloadSpans[clauses.length];
   for (int i = 0; i < clauses.length; i++) {
     subSpans[i] = clauses[i].getPayloadSpans(reader);
     subSpansByDoc[i] = subSpans[i]; // used in toSameDoc()
   }
   query = spanNearQuery; // kept for toString() only.
 }
 public String toString() {
   return getClass().getName()
       + "("
       + query.toString()
       + ")@"
       + (firstTime ? "START" : (more ? (doc() + ":" + start() + "-" + end()) : "END"));
 }
  public void testBuilder() throws Exception {

    // Can't add subclauses from different fields
    try {
      SpanNearQuery.newOrderedNearQuery("field1")
          .addClause(new SpanTermQuery(new Term("field2", "term")));
      fail("Expected an error when adding a clause with a different field");
    } catch (IllegalArgumentException e) {
    }

    // Can't add gaps to unordered queries
    try {
      SpanNearQuery.newUnorderedNearQuery("field1").addGap(1);
      fail("Expected an error when adding a gap to an unordered query");
    } catch (IllegalArgumentException e) {
    }
  }
 /** not a direct test of NearSpans, but a demonstration of how/when this causes problems */
 public void testSpanNearScorerExplain() throws Exception {
   SpanNearQuery q = makeQuery();
   Explanation e = q.weight(searcher).explain(searcher.getIndexReader(), 1);
   assertTrue(
       "Scorer explanation value for doc#1 isn't positive: " + e.toString(), 0.0f < e.getValue());
 }
 /** not a direct test of NearSpans, but a demonstration of how/when this causes problems */
 public void testSpanNearScorerSkipTo1() throws Exception {
   SpanNearQuery q = makeQuery();
   Weight w = q.weight(searcher);
   Scorer s = w.scorer(searcher.getIndexReader(), true, false);
   assertEquals(1, s.advance(1));
 }
 public void testNearSpansSkipTo1() throws Exception {
   SpanNearQuery q = makeQuery();
   Spans span = q.getSpans(searcher.getIndexReader());
   assertEquals(true, span.skipTo(1));
   assertEquals(s(1, 0, 4), s(span));
 }
 public void testNearSpansSkipPast() throws Exception {
   SpanNearQuery q = makeQuery();
   Spans span = q.getSpans(searcher.getIndexReader());
   assertEquals(false, span.skipTo(2));
 }
Example #10
0
 public String toString() {
   return "spans("
       + query.toString()
       + ")@"
       + (firstTime ? "START" : (more ? (doc() + ":" + start() + "-" + end()) : "END"));
 }