Clover Coverage Report
Coverage timestamp: Fri May 9 2008 10:54:27 EST
31   84   3   10.33
0   48   0.1   3
3     1  
1    
 
  TestMatchAllDocsQuery       Line # 34 31 3 100% 1.0
 
  (2)
 
1    /**
2    * Copyright 2005 The Apache Software Foundation
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10    * Unless required by applicable law or agreed to in writing, software
11    * distributed under the License is distributed on an "AS IS" BASIS,
12    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13    * See the License for the specific language governing permissions and
14    * limitations under the License.
15    */
16    package org.apache.lucene.search;
17   
18    import java.io.IOException;
19   
20    import org.apache.lucene.analysis.standard.StandardAnalyzer;
21    import org.apache.lucene.document.Document;
22    import org.apache.lucene.document.Field;
23    import org.apache.lucene.index.IndexWriter;
24    import org.apache.lucene.index.Term;
25    import org.apache.lucene.store.RAMDirectory;
26   
27    import junit.framework.TestCase;
28   
29    /**
30    * Tests MatchAllDocsQuery.
31    *
32    * @author Daniel Naber
33    */
 
34    public class TestMatchAllDocsQuery extends TestCase {
35   
 
36  1 toggle public void testQuery() throws IOException {
37  1 RAMDirectory dir = new RAMDirectory();
38  1 IndexWriter iw = new IndexWriter(dir, new StandardAnalyzer(), true);
39  1 addDoc("one", iw);
40  1 addDoc("two", iw);
41  1 addDoc("three four", iw);
42  1 iw.close();
43   
44  1 IndexSearcher is = new IndexSearcher(dir);
45  1 Hits hits = is.search(new MatchAllDocsQuery());
46  1 assertEquals(3, hits.length());
47   
48    // some artificial queries to trigger the use of skipTo():
49   
50  1 BooleanQuery bq = new BooleanQuery();
51  1 bq.add(new MatchAllDocsQuery(), BooleanClause.Occur.MUST);
52  1 bq.add(new MatchAllDocsQuery(), BooleanClause.Occur.MUST);
53  1 hits = is.search(bq);
54  1 assertEquals(3, hits.length());
55   
56  1 bq = new BooleanQuery();
57  1 bq.add(new MatchAllDocsQuery(), BooleanClause.Occur.MUST);
58  1 bq.add(new TermQuery(new Term("key", "three")), BooleanClause.Occur.MUST);
59  1 hits = is.search(bq);
60  1 assertEquals(1, hits.length());
61   
62    // delete a document:
63  1 is.getIndexReader().deleteDocument(0);
64  1 hits = is.search(new MatchAllDocsQuery());
65  1 assertEquals(2, hits.length());
66   
67  1 is.close();
68    }
69   
 
70  1 toggle public void testEquals() {
71  1 Query q1 = new MatchAllDocsQuery();
72  1 Query q2 = new MatchAllDocsQuery();
73  1 assertTrue(q1.equals(q2));
74  1 q1.setBoost(1.5f);
75  1 assertFalse(q1.equals(q2));
76    }
77   
 
78  3 toggle private void addDoc(String text, IndexWriter iw) throws IOException {
79  3 Document doc = new Document();
80  3 doc.add(new Field("key", text, Field.Store.YES, Field.Index.TOKENIZED));
81  3 iw.addDocument(doc);
82    }
83   
84    }