pylucene 3.5.0-3
[pylucene.git] / lucene-java-3.5.0 / lucene / src / test / org / apache / lucene / analysis / TestPerFieldAnalzyerWrapper.java
1 package org.apache.lucene.analysis;
2
3 import java.io.StringReader;
4 import java.util.HashMap;
5 import java.util.Map;
6
7 import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
8
9 /**
10  * Licensed to the Apache Software Foundation (ASF) under one or more
11  * contributor license agreements.  See the NOTICE file distributed with
12  * this work for additional information regarding copyright ownership.
13  * The ASF licenses this file to You under the Apache License, Version 2.0
14  * (the "License"); you may not use this file except in compliance with
15  * the License.  You may obtain a copy of the License at
16  *
17  *     http://www.apache.org/licenses/LICENSE-2.0
18  *
19  * Unless required by applicable law or agreed to in writing, software
20  * distributed under the License is distributed on an "AS IS" BASIS,
21  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22  * See the License for the specific language governing permissions and
23  * limitations under the License.
24  */
25
26 public class TestPerFieldAnalzyerWrapper extends BaseTokenStreamTestCase {
27   public void testPerField() throws Exception {
28     String text = "Qwerty";
29
30     Map<String, Analyzer> analyzerPerField = new HashMap<String, Analyzer>();
31     analyzerPerField.put("special", new SimpleAnalyzer(TEST_VERSION_CURRENT));
32
33     PerFieldAnalyzerWrapper analyzer =
34               new PerFieldAnalyzerWrapper(new WhitespaceAnalyzer(TEST_VERSION_CURRENT), analyzerPerField);
35
36     TokenStream tokenStream = analyzer.tokenStream("field",
37                                             new StringReader(text));
38     CharTermAttribute termAtt = tokenStream.getAttribute(CharTermAttribute.class);
39
40     assertTrue(tokenStream.incrementToken());
41     assertEquals("WhitespaceAnalyzer does not lowercase",
42                  "Qwerty",
43                  termAtt.toString());
44
45     tokenStream = analyzer.tokenStream("special",
46                                             new StringReader(text));
47     termAtt = tokenStream.getAttribute(CharTermAttribute.class);
48     assertTrue(tokenStream.incrementToken());
49     assertEquals("SimpleAnalyzer lowercases",
50                  "qwerty",
51                  termAtt.toString());
52   }
53 }