Clover Coverage Report
Coverage timestamp: Fri May 9 2008 10:54:27 EST
../../../../../img/srcFileCovDistChart8.png 55% of files have more coverage
69   181   44   4.06
34   118   0.64   17
17     2.59  
1    
 
  SpanNotQuery       Line # 29 69 44 75.8% 0.7583333
 
  (25)
 
1    package org.apache.lucene.search.spans;
2   
3    /**
4    * Copyright 2004 The Apache Software Foundation
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10    * http://www.apache.org/licenses/LICENSE-2.0
11    *
12    * Unless required by applicable law or agreed to in writing, software
13    * distributed under the License is distributed on an "AS IS" BASIS,
14    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15    * See the License for the specific language governing permissions and
16    * limitations under the License.
17    */
18   
19    import java.io.IOException;
20   
21    import java.util.Collection;
22    import java.util.Set;
23   
24    import org.apache.lucene.index.IndexReader;
25    import org.apache.lucene.search.Query;
26    import org.apache.lucene.util.ToStringUtils;
27   
28    /** Removes matches which overlap with another SpanQuery. */
 
29    public class SpanNotQuery extends SpanQuery {
30    private SpanQuery include;
31    private SpanQuery exclude;
32   
33    /** Construct a SpanNotQuery matching spans from <code>include</code> which
34    * have no overlap with spans from <code>exclude</code>.*/
 
35  25 toggle public SpanNotQuery(SpanQuery include, SpanQuery exclude) {
36  25 this.include = include;
37  25 this.exclude = exclude;
38   
39  25 if (!include.getField().equals(exclude.getField()))
40  0 throw new IllegalArgumentException("Clauses must have same field.");
41    }
42   
43    /** Return the SpanQuery whose matches are filtered. */
 
44  0 toggle public SpanQuery getInclude() { return include; }
45   
46    /** Return the SpanQuery whose matches must not overlap those returned. */
 
47  0 toggle public SpanQuery getExclude() { return exclude; }
48   
 
49  185 toggle public String getField() { return include.getField(); }
50   
51    /** Returns a collection of all terms matched by this query.
52    * @deprecated use extractTerms instead
53    * @see #extractTerms(Set)
54    */
 
55  0 toggle public Collection getTerms() { return include.getTerms(); }
56   
 
57  129 toggle public void extractTerms(Set terms) { include.extractTerms(terms); }
58   
 
59  209 toggle public String toString(String field) {
60  209 StringBuffer buffer = new StringBuffer();
61  209 buffer.append("spanNot(");
62  209 buffer.append(include.toString(field));
63  209 buffer.append(", ");
64  209 buffer.append(exclude.toString(field));
65  209 buffer.append(")");
66  209 buffer.append(ToStringUtils.boost(getBoost()));
67  209 return buffer.toString();
68    }
69   
70   
 
71  129 toggle public Spans getSpans(final IndexReader reader) throws IOException {
72  129 return new Spans() {
73    private Spans includeSpans = include.getSpans(reader);
74    private boolean moreInclude = true;
75   
76    private Spans excludeSpans = exclude.getSpans(reader);
77    private boolean moreExclude = excludeSpans.next();
78   
 
79