Clover Coverage Report
Coverage timestamp: Fri May 9 2008 10:54:27 EST
51   163   7   7.29
0   96   0.14   7
7     1  
1    
 
  TestBooleanOr       Line # 38 51 7 100% 1.0
 
  (5)
 
1    package org.apache.lucene.search;
2    /**
3    * Copyright 2005 Apache Software Foundation
4    *
5    * Licensed under the Apache License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    *
9    * http://www.apache.org/licenses/LICENSE-2.0
10    *
11    * Unless required by applicable law or agreed to in writing, software
12    * distributed under the License is distributed on an "AS IS" BASIS,
13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    * See the License for the specific language governing permissions and
15    * limitations under the License.
16    */
17    import java.io.IOException;
18   
19    import junit.framework.TestCase;
20   
21    import org.apache.lucene.analysis.standard.StandardAnalyzer;
22    import org.apache.lucene.document.Document;
23    import org.apache.lucene.document.Field;
24    import org.apache.lucene.index.IndexWriter;
25    import org.apache.lucene.index.Term;
26    import org.apache.lucene.search.BooleanClause;
27    import org.apache.lucene.search.BooleanQuery;
28    import org.apache.lucene.search.IndexSearcher;
29    import org.apache.lucene.search.Query;
30    import org.apache.lucene.search.TermQuery;
31    import org.apache.lucene.store.RAMDirectory;
32   
33    /**
34    * Created on 2005. 2. 9.
35    * <br>Adapted to Lucene testcase by Paul Elschot.
36    * @author appler@gmail.com
37    */
 
38    public class TestBooleanOr extends TestCase {
39   
40    private static String FIELD_T = "T";
41    private static String FIELD_C = "C";
42   
43    private TermQuery t1 = new TermQuery(new Term(FIELD_T, "files"));
44    private TermQuery t2 = new TermQuery(new Term(FIELD_T, "deleting"));
45    private TermQuery c1 = new TermQuery(new Term(FIELD_C, "production"));
46    private TermQuery c2 = new TermQuery(new Term(FIELD_C, "optimize"));
47   
48    private IndexSearcher searcher = null;
49   
 
50  8 toggle private int search(Query q) throws IOException {
51  8 QueryUtils.check(q,searcher);
52  8 return searcher.search(q).length();
53    }
54   
 
55  1 toggle public void testElements() throws IOException {
56  1 assertEquals(1, search(t1));
57  1 assertEquals(1, search(t2));
58  1 assertEquals(1, search(c1));
59  1 assertEquals(1, search(c2));
60    }
61   
62    /**
63    * <code>T:files T:deleting C:production C:optimize </code>
64    * it works.
65    *
66    * @throws IOException
67    */
 
68  1 toggle public void testFlat() throws IOException {
69  1 BooleanQuery q = new BooleanQuery();
70  1 q.add(new BooleanClause(t1, BooleanClause.Occur.SHOULD));
71  1 q.add(new BooleanClause(t2, BooleanClause.Occur.SHOULD));
72  1 q.add(new BooleanClause(c1, BooleanClause.Occur.SHOULD));
73  1 q.add(new BooleanClause(c2, BooleanClause.Occur.SHOULD));
74  1 assertEquals(1, search(q));
75    }
76   
77    /**
78    * <code>(T:files T:deleting) (+C:production +C:optimize)</code>
79    * it works.
80    *
81    * @throws IOException
82    */
 
83  1 toggle public void testParenthesisMust() throws IOException {
84  1 BooleanQuery q3 = new BooleanQuery();
85  1 q3.add(new BooleanClause(t1, BooleanClause.Occur.SHOULD));
86  1 q3.add(new BooleanClause(t2, BooleanClause.Occur.SHOULD));
87  1 BooleanQuery q4 = new BooleanQuery();
88  1 q4.add(new BooleanClause(c1, BooleanClause.Occur.MUST));
89  1 q4.add(new BooleanClause(c2, BooleanClause.Occur.MUST));
90  1 BooleanQuery q2 = new BooleanQuery();
91  1 q2.add(q3, BooleanClause.Occur.SHOULD);
92  1 q2.add(q4, BooleanClause.Occur.SHOULD);
93  1 assertEquals(1, search(q2));
94    }
95   
96    /**
97    * <code>(T:files T:deleting) +(C:production C:optimize)</code>
98    * not working. results NO HIT.
99    *
100    * @throws IOException
101    */
 
102  1 toggle public void testParenthesisMust2() throws IOException {
103  1 BooleanQuery q3 = new BooleanQuery();
104  1 q3.add(new BooleanClause(t1, BooleanClause.Occur.SHOULD));
105  1 q3.add(new BooleanClause(t2, BooleanClause.Occur.SHOULD));
106  1 BooleanQuery q4 = new BooleanQuery();
107  1 q4.add(new BooleanClause(c1, BooleanClause.Occur.SHOULD));
108  1 q4.add(new BooleanClause(c2, BooleanClause.Occur.SHOULD));
109  1 BooleanQuery q2 = new BooleanQuery();
110  1 q2.add(q3, BooleanClause.Occur.SHOULD);
111  1 q2.add(q4, BooleanClause.Occur.MUST);
112  1 assertEquals(1, search(q2));
113    }
114   
115    /**
116    * <code>(T:files T:deleting) (C:production C:optimize)</code>
117    * not working. results NO HIT.
118    *
119    * @throws IOException
120    */
 
121  1 toggle public void testParenthesisShould() throws IOException {
122  1 BooleanQuery q3 = new BooleanQuery();
123  1 q3.add(new BooleanClause(t1, BooleanClause.Occur.SHOULD));
124  1 q3.add(new BooleanClause(t2, BooleanClause.Occur.SHOULD));
125  1 BooleanQuery q4 = new BooleanQuery();
126  1 q4.add(new BooleanClause(c1, BooleanClause.Occur.SHOULD));
127  1 q4.add(new BooleanClause(c2, BooleanClause.Occur.SHOULD));
128  1 BooleanQuery q2 = new BooleanQuery();
129  1 q2.add(q3, BooleanClause.Occur.SHOULD);
130  1 q2.add(q4, BooleanClause.Occur.SHOULD);
131  1 assertEquals(1, search(q2));
132    }
133   
 
134  5 toggle protected void setUp() throws Exception {
135  5 super.setUp();
136   
137    //
138  5 RAMDirectory rd = new RAMDirectory();
139   
140    //
141  5 IndexWriter writer = new IndexWriter(rd, new StandardAnalyzer(), true);
142   
143    //
144  5 Document d = new Document();
145  5 d.add(new Field(
146    FIELD_T,
147    "Optimize not deleting all files",
148    Field.Store.YES,
149    Field.Index.TOKENIZED));
150  5 d.add(new Field(
151    FIELD_C,
152    "Deleted When I run an optimize in our production environment.",
153    Field.Store.YES,
154    Field.Index.TOKENIZED));
155   
156    //
157  5 writer.addDocument(d);
158  5 writer.close();
159   
160    //
161  5 searcher = new IndexSearcher(rd);
162    }
163    }