Clover Coverage Report
Coverage timestamp: Fri May 9 2008 10:54:27 EST
88   186   4   22
0   102   0.05   4
4     1  
1    
 
  TestRangeFilter       Line # 33 88 4 97.8% 0.9782609
 
  (2)
 
1    package org.apache.lucene.search;
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 org.apache.lucene.index.IndexReader;
22    import org.apache.lucene.index.Term;
23   
24    /**
25    * A basic 'positive' Unit test class for the RangeFilter class.
26    *
27    * <p>
28    * NOTE: at the moment, this class only tests for 'positive' results,
29    * it does not verify the results to ensure there are no 'false positives',
30    * nor does it adequately test 'negative' results. It also does not test
31    * that garbage in results in an Exception.
32    */
 
33    public class TestRangeFilter extends BaseTestRangeFilter {
34   
 
35  3 toggle public TestRangeFilter(String name) {
36  3 super(name);
37    }
 
38  0 toggle public TestRangeFilter() {
39  0 super();
40    }
41   
 
42  1 toggle public void testRangeFilterId() throws IOException {
43   
44  1 IndexReader reader = IndexReader.open(index);
45  1 IndexSearcher search = new IndexSearcher(reader);
46   
47  1 int medId = ((maxId - minId) / 2);
48   
49  1 String minIP = pad(minId);
50  1 String maxIP = pad(maxId);
51  1 String medIP = pad(medId);
52   
53  1 int numDocs = reader.numDocs();
54   
55  1 assertEquals("num of docs", numDocs, 1+ maxId - minId);
56   
57  1 Hits result;
58  1 Query q = new TermQuery(new Term("body","body"));
59   
60    // test id, bounded on both ends
61   
62  1 result = search.search(q,new RangeFilter("id",minIP,maxIP,T,T));
63  1 assertEquals("find all", numDocs, result.length());
64   
65  1 result = search.search(q,new RangeFilter("id",minIP,maxIP,T,F));
66  1 assertEquals("all but last", numDocs-1, result.length());
67   
68  1 result = search.search(q,new RangeFilter("id",minIP,maxIP,F,T));
69  1 assertEquals("all but first", numDocs-1, result.length());
70   
71  1 result = search.search(q,new RangeFilter("id",minIP,maxIP,F,F));
72  1 assertEquals("all but ends", numDocs-2, result.length());
73   
74  1 result = search.search(q,new RangeFilter("id",medIP,maxIP,T,T));
75  1 assertEquals("med and up", 1+ maxId-medId, result.length());
76   
77  1 result = search.search(q,new RangeFilter("id",minIP,medIP,T,T));
78  1 assertEquals("up to med", 1+ medId-minId, result.length());
79   
80    // unbounded id
81   
82  1 result = search.search(q,new RangeFilter("id",minIP,null,T,F));
83  1 assertEquals("min and up", numDocs, result.length());
84   
85  1 result = search.search(q,new RangeFilter("id",null,maxIP,F,T));
86  1 assertEquals("max and down", numDocs, result.length());
87   
88  1 result = search.search(q,new RangeFilter("id",minIP,null,F,F));
89  1 assertEquals("not min, but up", numDocs-1, result.length());
90   
91  1 result = search.search(q,new RangeFilter("id",null,maxIP,F,F));
92  1 assertEquals("not max, but down", numDocs-1, result.length());
93   
94  1 result = search.search(q,new RangeFilter("id",medIP,maxIP,T,F));
95  1 assertEquals("med and up, not max", maxId-medId, result.length());
96   
97  1 result = search.search(q,new RangeFilter("id",minIP,medIP,F,T));
98  1 assertEquals("not min, up to med", medId-minId, result.length());
99   
100    // very small sets
101   
102  1 result = search.search(q,new RangeFilter("id",minIP,minIP,F,F));
103  1 assertEquals("min,min,F,F", 0, result.length());
104  1 result = search.search(q,new RangeFilter("id",medIP,medIP,F,F));
105  1 assertEquals("med,med,F,F", 0, result.length());
106  1 result = search.search(q,new RangeFilter("id",maxIP,maxIP,F,F));
107  1 assertEquals("max,max,F,F", 0, result.length());
108   
109  1 result = search.search(q,new RangeFilter("id",minIP,minIP,T,T));
110  1 assertEquals("min,min,T,T", 1, result.length());
111  1 result = search.search(q,new RangeFilter("id",null,minIP,F,T));
112  1 assertEquals("nul,min,F,T", 1, result.length());
113   
114  1 result = search.search(q,new RangeFilter("id",maxIP,maxIP,T,T));
115  1 assertEquals("max,max,T,T", 1, result.length());
116  1 result = search.search(q,new RangeFilter("id",maxIP,null,T,F));
117  1 assertEquals("max,nul,T,T", 1, result.length());
118   
119  1 result = search.search(q,new RangeFilter("id",medIP,medIP,T,T));
120  1 assertEquals("med,med,T,T", 1, result.length());
121   
122    }
123   
 
124  1 toggle public void testRangeFilterRand() throws IOException {
125   
126  1 IndexReader reader = IndexReader.open(index);
127  1 IndexSearcher search = new IndexSearcher(reader);
128   
129  1 String minRP = pad(minR);
130  1 String maxRP = pad(maxR);
131   
132  1 int numDocs = reader.numDocs();
133   
134  1 assertEquals("num of docs", numDocs, 1+ maxId - minId);
135   
136  1 Hits result;
137  1 Query q = new TermQuery(new Term("body","body"));
138   
139    // test extremes, bounded on both ends
140   
141  1 result = search.search(q,new RangeFilter("rand",minRP,maxRP,T,T));
142  1 assertEquals("find all", numDocs, result.length());
143   
144  1 result = search.search(q,new RangeFilter("rand",minRP,maxRP,T,F));
145  1 assertEquals("all but biggest", numDocs-1, result.length());
146   
147  1 result = search.search(q,new RangeFilter("rand",minRP,maxRP,F,T));
148  1 assertEquals("all but smallest", numDocs-1, result.length());
149   
150  1 result = search.search(q,new RangeFilter("rand",minRP,maxRP,F,F));
151  1 assertEquals("all but extremes", numDocs-2, result.length());
152   
153    // unbounded
154   
155  1 result = search.search(q,new RangeFilter("rand",minRP,null,T,F));
156  1 assertEquals("smallest and up", numDocs, result.length());
157   
158  1 result = search.search(q,new RangeFilter("rand",null,maxRP,F,T));
159  1 assertEquals("biggest and down", numDocs, result.length());
160   
161  1 result = search.search(q,new RangeFilter("rand",minRP,null,F,F));
162  1 assertEquals("not smallest, but up", numDocs-1, result.length());
163   
164  1 result = search.search(q,new RangeFilter("rand",null,maxRP,F,F));
165  1 assertEquals("not biggest, but down", numDocs-1, result.length());
166   
167    // very small sets
168   
169  1 result = search.search(q,new RangeFilter("rand",minRP,minRP,F,F));
170  1 assertEquals("min,min,F,F", 0, result.length());
171  1 result = search.search(q,new RangeFilter("rand",maxRP,maxRP,F,F));
172  1 assertEquals("max,max,F,F", 0, result.length());
173   
174  1 result = search.search(q,new RangeFilter("rand",minRP,minRP,T,T));
175  1 assertEquals("min,min,T,T", 1, result.length());
176  1 result = search.search(q,new RangeFilter("rand",null,minRP,F,T));
177  1 assertEquals("nul,min,F,T", 1, result.length());
178   
179  1 result = search.search(q,new RangeFilter("rand",maxRP,maxRP,T,T));
180  1 assertEquals("max,max,T,T", 1, result.length());
181  1 result = search.search(q,new RangeFilter("rand",maxRP,null,T,F));
182  1 assertEquals("max,nul,T,T", 1, result.length());
183   
184    }
185   
186    }