Clover Coverage Report
Coverage timestamp: Fri May 9 2008 10:54:27 EST
../../../img/srcFileCovDistChart0.png 86% of files have more coverage
28   97   7   14
6   59   0.25   2
2     3.5  
1    
 
  SearchTest       Line # 28 28 7 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.util.GregorianCalendar;
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 SearchTest {
 
29  0 toggle public static void main(String[] args) {
30  0 try {
31  0 Directory directory = new RAMDirectory();
32  0 Analyzer analyzer = new SimpleAnalyzer();
33  0 IndexWriter writer = new IndexWriter(directory, analyzer, true);
34   
35  0 String[] docs = {
36    "a b c d e",
37    "a b c d e a b c d e",
38    "a b c d e f g h i j",
39    "a c e",
40    "e c a",
41    "a c e a c e",
42    "a c e a b c"
43    };
44  0 for (int j = 0; j < docs.length; j++) {
45  0 Document d = new Document();
46  0 d.add(new Field("contents", docs[j], Field.Store.YES, Field.Index.TOKENIZED));
47  0 writer.addDocument(d);
48    }
49  0 writer.close();
50   
51  0 Searcher searcher = new IndexSearcher(directory);
52   
53  0 String[] queries = {
54    // "a b",
55    // "\"a b\"",
56    // "\"a b c\"",
57    // "a c",
58    // "\"a c\"",
59    "\"a c e\"",
60    };
61  0 Hits hits = null;
62   
63  0 QueryParser parser = new QueryParser("contents", analyzer);
64  0 parser.setPhraseSlop(4);
65  0 for (int j = 0; j < queries.length; j++) {
66  0 Query query = parser.parse(queries[j]);
67  0 System.out.println("Query: " + query.toString("contents"));
68   
69    //DateFilter filter =
70    // new DateFilter("modified", Time(1997,0,1), Time(1998,0,1));
71    //DateFilter filter = DateFilter.Before("modified", Time(1997,00,01));
72    //System.out.println(filter);
73   
74  0 hits = searcher.search(query);
75   
76  0 System.out.println(hits.length() + " total results");
77  0 for (int i = 0 ; i < hits.length() && i < 10; i++) {
78  0 Document d = hits.doc(i);
79  0 System.out.println(i + " " + hits.score(i)
80    // + " " + DateField.stringToDate(d.get("modified"))
81    + " " + d.get("contents"));
82    }
83    }
84  0 searcher.close();
85   
86    } catch (Exception e) {
87  0 System.out.println(" caught a " + e.getClass() +
88    "\n with message: " + e.getMessage());
89    }
90    }
91   
 
92  0 toggle static long Time(int year, int month, int day) {
93  0 GregorianCalendar calendar = new GregorianCalendar();
94  0 calendar.set(year, month, day);
95  0 return calendar.getTime().getTime();
96    }
97    }