~slub.team/goobi-indexserver/3.x

« back to all changes in this revision

Viewing changes to solr/core/src/test/org/apache/solr/analysis/DoubleMetaphoneFilterFactoryTest.java

  • Committer: Sebastian Meyer
  • Date: 2012-08-03 09:12:40 UTC
  • Revision ID: sebastian.meyer@slub-dresden.de-20120803091240-x6861b0vabq1xror
Remove Lucene and Solr source code and add patches instead
Fix Bug #985487: Auto-suggestion for the search interface

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**
2
 
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 
 * contributor license agreements.  See the NOTICE file distributed with
4
 
 * this work for additional information regarding copyright ownership.
5
 
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 
 * (the "License"); you may not use this file except in compliance with
7
 
 * the License.  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
 
package org.apache.solr.analysis;
18
 
 
19
 
import java.io.StringReader;
20
 
import java.util.HashMap;
21
 
import java.util.Map;
22
 
 
23
 
import org.apache.lucene.analysis.MockTokenizer;
24
 
import org.apache.lucene.analysis.TokenStream;
25
 
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
26
 
 
27
 
public class DoubleMetaphoneFilterFactoryTest extends BaseTokenTestCase {
28
 
 
29
 
  public void testDefaults() throws Exception {
30
 
    DoubleMetaphoneFilterFactory factory = new DoubleMetaphoneFilterFactory();
31
 
    factory.init(new HashMap<String, String>());
32
 
    TokenStream inputStream = new MockTokenizer(new StringReader("international"), MockTokenizer.WHITESPACE, false);
33
 
 
34
 
    TokenStream filteredStream = factory.create(inputStream);
35
 
    assertEquals(DoubleMetaphoneFilter.class, filteredStream.getClass());
36
 
    assertTokenStreamContents(filteredStream, new String[] { "international", "ANTR" });
37
 
  }
38
 
 
39
 
  public void testSettingSizeAndInject() throws Exception {
40
 
    DoubleMetaphoneFilterFactory factory = new DoubleMetaphoneFilterFactory();
41
 
    Map<String, String> parameters = new HashMap<String, String>();
42
 
    parameters.put("inject", "false");
43
 
    parameters.put("maxCodeLength", "8");
44
 
    factory.init(parameters);
45
 
 
46
 
    TokenStream inputStream = new MockTokenizer(new StringReader("international"), MockTokenizer.WHITESPACE, false);
47
 
 
48
 
    TokenStream filteredStream = factory.create(inputStream);
49
 
    assertEquals(DoubleMetaphoneFilter.class, filteredStream.getClass());
50
 
    assertTokenStreamContents(filteredStream, new String[] { "ANTRNXNL" });
51
 
  }
52
 
  
53
 
  /**
54
 
   * Ensure that reset() removes any state (buffered tokens)
55
 
   */
56
 
  public void testReset() throws Exception {
57
 
    DoubleMetaphoneFilterFactory factory = new DoubleMetaphoneFilterFactory();
58
 
    factory.init(new HashMap<String, String>());
59
 
    TokenStream inputStream = new MockTokenizer(new StringReader("international"), MockTokenizer.WHITESPACE, false);
60
 
 
61
 
    TokenStream filteredStream = factory.create(inputStream);
62
 
    CharTermAttribute termAtt = filteredStream.addAttribute(CharTermAttribute.class);
63
 
    assertEquals(DoubleMetaphoneFilter.class, filteredStream.getClass());
64
 
    
65
 
    filteredStream.reset();
66
 
    assertTrue(filteredStream.incrementToken());
67
 
    assertEquals(13, termAtt.length());
68
 
    assertEquals("international", termAtt.toString());
69
 
    filteredStream.reset();
70
 
    
71
 
    // ensure there are no more tokens, such as ANTRNXNL
72
 
    assertFalse(filteredStream.incrementToken());
73
 
  }
74
 
}