Clover Coverage Report
Coverage timestamp: Fri May 9 2008 10:54:27 EST
../../../img/srcFileCovDistChart0.png 86% of files have more coverage
33   96   8   16.5
6   58   0.24   2
2     4  
1    
 
  SearchTestForDuplicates       Line # 28 33 8 0% 0.0
 
No Tests
 
1    package org.apache.lucene;
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.store.*;
22    import org.apache.lucene.document.*;
23    import org.apache.lucene.analysis.*;
24    import org.apache.lucene.index.*;
25    import org.apache.lucene.search.*;
26    import org.apache.lucene.queryParser.*;
27   
 
28    class SearchTestForDuplicates {
29   
30    static final String PRIORITY_FIELD ="priority";
31    static final String ID_FIELD ="id";
32    static final String HIGH_PRIORITY ="high";
33    static final String MED_PRIORITY ="medium";
34    static final String LOW_PRIORITY ="low";
35   
 
36  0 toggle public static void main(String[] args) {
37  0 try {
38  0 Directory directory = new RAMDirectory();
39  0 Analyzer analyzer = new SimpleAnalyzer();
40  0 IndexWriter writer = new IndexWriter(directory, analyzer, true);
41   
42  0 final int MAX_DOCS = 225;
43   
44  0 for (int j = 0; j < MAX_DOCS; j++) {
45  0 Document d = new Document();
46  0 d.add(new Field(PRIORITY_FIELD, HIGH_PRIORITY, Field.Store.YES, Field.Index.TOKENIZED));
47  0 d.add(new Field(ID_FIELD, Integer.toString(j), Field.Store.YES, Field.Index.TOKENIZED));
48  0 writer.addDocument(d);
49    }
50  0 writer.close();
51   
52    // try a search without OR
53  0 Searcher searcher = new IndexSearcher(directory);
54  0 Hits hits = null;
55   
56  0 QueryParser parser = new QueryParser(PRIORITY_FIELD, analyzer);
57   
58  0 Query query = parser.parse(HIGH_PRIORITY);
59  0 System.out.println("Query: " + query.toString(PRIORITY_FIELD));
60   
61  0 hits = searcher.search(query);
62  0 printHits(hits);
63   
64  0 searcher.close();
65   
66    // try a new search with OR
67  0 searcher = new IndexSearcher(directory);
68  0 hits = null;
69   
70  0 parser = new QueryParser(PRIORITY_FIELD, analyzer);
71   
72  0 query = parser.parse(HIGH_PRIORITY + " OR " + MED_PRIORITY);
73  0 System.out.println("Query: " + query.toString(PRIORITY_FIELD));
74   
75  0 hits = searcher.search(query);
76  0 printHits(hits);
77   
78  0 searcher.close();
79   
80    } catch (Exception e) {
81  0 System.out.println(" caught a " + e.getClass() +
82    "\n with message: " + e.getMessage());
83    }
84    }
85   
 
86  0 toggle private static void printHits( Hits hits ) throws IOException {
87  0 System.out.println(hits.length() + " total results\n");
88  0 for (int i = 0 ; i < hits.length(); i++) {
89  0 if ( i < 10 || (i > 94 && i < 105) ) {
90  0 Document d = hits.doc(i);
91  0 System.out.println(i + " " + d.get(ID_FIELD));
92    }
93    }
94    }
95   
96    }