Clover Coverage Report
Coverage timestamp: Fri May 9 2008 10:54:27 EST
15   62   2   7.5
0   36   0.13   2
2     1  
1    
 
  TestKeywordAnalyzer       Line # 29 15 2 100% 1.0
 
  (1)
 
1    package org.apache.lucene.analysis;
2   
3    /**
4    * Copyright 2005 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 junit.framework.TestCase;
20    import org.apache.lucene.index.IndexWriter;
21    import org.apache.lucene.store.RAMDirectory;
22    import org.apache.lucene.document.Document;
23    import org.apache.lucene.document.Field;
24    import org.apache.lucene.search.IndexSearcher;
25    import org.apache.lucene.search.Query;
26    import org.apache.lucene.search.Hits;
27    import org.apache.lucene.queryParser.QueryParser;
28   
 
29    public class TestKeywordAnalyzer extends TestCase {
30   
31    private RAMDirectory directory;
32    private IndexSearcher searcher;
33   
 
34  1 toggle public void setUp() throws Exception {
35  1 directory = new RAMDirectory();
36  1 IndexWriter writer = new IndexWriter(directory,
37    new SimpleAnalyzer(),
38    true);
39   
40  1 Document doc = new Document();
41  1 doc.add(new Field("partnum", "Q36", Field.Store.YES, Field.Index.UN_TOKENIZED));
42  1 doc.add(new Field("description", "Illidium Space Modulator", Field.Store.YES, Field.Index.TOKENIZED));
43  1 writer.addDocument(doc);
44   
45  1 writer.close();
46   
47  1 searcher = new IndexSearcher(directory);
48    }
49   
 
50  1 toggle public void testPerFieldAnalyzer() throws Exception {
51  1 PerFieldAnalyzerWrapper analyzer = new PerFieldAnalyzerWrapper(new SimpleAnalyzer());
52  1 analyzer.addAnalyzer("partnum", new KeywordAnalyzer());
53   
54  1 QueryParser queryParser = new QueryParser("description", analyzer);
55  1 Query query = queryParser.parse("partnum:Q36 AND SPACE");
56   
57  1 Hits hits = searcher.search(query);
58  1 assertEquals("Q36 kept as-is",
59    "+partnum:Q36 +space", query.toString("description"));
60  1 assertEquals("doc found!", 1, hits.length());
61    }
62    }