Clover Coverage Report
Coverage timestamp: Fri May 9 2008 10:54:27 EST
../../../../img/srcFileCovDistChart9.png 37% of files have more coverage
61   188   30   3.05
20   112   0.49   20
20     1.5  
1    
 
  FilteredQuery       Line # 41 61 30 82.2% 0.8217822
 
  (21)
 
1    package org.apache.lucene.search;
2   
3    /**
4    * Copyright 2004,2006 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 org.apache.lucene.index.IndexReader;
20    import org.apache.lucene.util.ToStringUtils;
21   
22    import java.io.IOException;
23    import java.util.BitSet;
24    import java.util.Set;
25   
26   
27    /**
28    * A query that applies a filter to the results of another query.
29    *
30    * <p>Note: the bits are retrieved from the filter each time this
31    * query is used in a search - use a CachingWrapperFilter to avoid
32    * regenerating the bits every time.
33    *
34    * <p>Created: Apr 20, 2004 8:58:29 AM
35    *
36    * @author Tim Jones
37    * @since 1.4
38    * @version $Id: FilteredQuery.java 467559 2006-10-25 04:24:10Z yonik $
39    * @see CachingWrapperFilter
40    */
 
41    public class FilteredQuery
42    extends Query {
43   
44    Query query;
45    Filter filter;
46   
47    /**
48    * Constructs a new query which applies a filter to the results of the original query.
49    * Filter.bits() will be called every time this query is used in a search.
50    * @param query Query to be filtered, cannot be <code>null</code>.
51    * @param filter Filter to apply to query results, cannot be <code>null</code>.
52    */
 
53  25 toggle public FilteredQuery (Query query, Filter filter) {
54  25 this.query = query;
55  25 this.filter = filter;
56    }
57   
58   
59   
60    /**
61    * Returns a Weight that applies the filter to the enclosed query's Weight.
62    * This is accomplished by overriding the Scorer returned by the Weight.
63    */
 
64  100 toggle protected Weight createWeight (final Searcher searcher) throws IOException {
65  100 final Weight weight = query.createWeight (searcher);
66  100 final Similarity similarity = query.getSimilarity(searcher);
67  100 return new Weight() {
68   
69    // pass these methods through to enclosed query's weight
 
70  0 toggle public float getValue() { return weight.getValue(); }
 
71  100 toggle public float sumOfSquaredWeights() throws IOException { return weight.sumOfSquaredWeights(); }
 
72  100 toggle public void normalize (float v) { weight.normalize(v); }
 
73  40 toggle public Explanation explain (IndexReader ir, int i) throws IOException {
74  40 Explanation inner = weight.explain (ir, i);
75  40 Filter f = FilteredQuery.this.filter;
76  40 BitSet matches = f.bits(ir);
77  40 if (matches.get(i))
78  23 return inner;
79  17 Explanation result = new Explanation
80    (0.0f, "failure to match filter: " + f.toString());
81  17 result.addDetail(inner);
82  17 return result;
83    }
84   
85    // return this query
 
86  0 toggle public Query getQuery() { return FilteredQuery.this; }
87   
88    // return a filtering scorer
 
89