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

« back to all changes in this revision

Viewing changes to solr/core/src/test/org/apache/solr/analysis/CommonGramsFilterFactoryTest.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
 
package org.apache.solr.analysis;
2
 
 
3
 
/**
4
 
 * Licensed to the Apache Software Foundation (ASF) under one or more
5
 
 * contributor license agreements.  See the NOTICE file distributed with
6
 
 * this work for additional information regarding copyright ownership.
7
 
 * The ASF licenses this file to You under the Apache License, Version 2.0
8
 
 * (the "License"); you may not use this file except in compliance with
9
 
 * the License.  You may obtain a copy of the License at
10
 
 *
11
 
 *     http://www.apache.org/licenses/LICENSE-2.0
12
 
 *
13
 
 * Unless required by applicable law or agreed to in writing, software
14
 
 * distributed under the License is distributed on an "AS IS" BASIS,
15
 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
 
 * See the License for the specific language governing permissions and
17
 
 * limitations under the License.
18
 
 */
19
 
 
20
 
import org.apache.lucene.analysis.MockTokenizer;
21
 
import org.apache.lucene.analysis.TokenStream;
22
 
import org.apache.lucene.analysis.Tokenizer;
23
 
import org.apache.solr.common.ResourceLoader;
24
 
import org.apache.solr.core.SolrResourceLoader;
25
 
 
26
 
import java.io.StringReader;
27
 
import java.util.Set;
28
 
import java.util.Map;
29
 
import java.util.HashMap;
30
 
 
31
 
/**
32
 
 * Tests pretty much copied from StopFilterFactoryTest We use the test files
33
 
 * used by the StopFilterFactoryTest TODO: consider creating separate test files
34
 
 * so this won't break if stop filter test files change
35
 
 **/
36
 
public class CommonGramsFilterFactoryTest extends BaseTokenTestCase {
37
 
 
38
 
  public void testInform() throws Exception {
39
 
    ResourceLoader loader = new SolrResourceLoader(null, null);
40
 
    assertTrue("loader is null and it shouldn't be", loader != null);
41
 
    CommonGramsFilterFactory factory = new CommonGramsFilterFactory();
42
 
    Map<String, String> args = new HashMap<String, String>(DEFAULT_VERSION_PARAM);
43
 
    args.put("words", "stop-1.txt");
44
 
    args.put("ignoreCase", "true");
45
 
    factory.init(args);
46
 
    factory.inform(loader);
47
 
    Set<?> words = factory.getCommonWords();
48
 
    assertTrue("words is null and it shouldn't be", words != null);
49
 
    assertTrue("words Size: " + words.size() + " is not: " + 2,
50
 
        words.size() == 2);
51
 
    assertTrue(factory.isIgnoreCase() + " does not equal: " + true, factory
52
 
        .isIgnoreCase() == true);
53
 
 
54
 
    factory = new CommonGramsFilterFactory();
55
 
    args.put("words", "stop-1.txt, stop-2.txt");
56
 
    factory.init(args);
57
 
    factory.inform(loader);
58
 
    words = factory.getCommonWords();
59
 
    assertTrue("words is null and it shouldn't be", words != null);
60
 
    assertTrue("words Size: " + words.size() + " is not: " + 4,
61
 
        words.size() == 4);
62
 
    assertTrue(factory.isIgnoreCase() + " does not equal: " + true, factory
63
 
        .isIgnoreCase() == true);
64
 
 
65
 
  }
66
 
  
67
 
  /**
68
 
   * If no words are provided, then a set of english default stopwords is used.
69
 
   */
70
 
  public void testDefaults() throws Exception {
71
 
    ResourceLoader loader = new SolrResourceLoader(null, null);
72
 
    assertTrue("loader is null and it shouldn't be", loader != null);
73
 
    CommonGramsFilterFactory factory = new CommonGramsFilterFactory();
74
 
    Map<String, String> args = new HashMap<String, String>(DEFAULT_VERSION_PARAM);
75
 
    factory.init(args);
76
 
    factory.inform(loader);
77
 
    Set<?> words = factory.getCommonWords();
78
 
    assertTrue("words is null and it shouldn't be", words != null);
79
 
    assertTrue(words.contains("the"));
80
 
    Tokenizer tokenizer = new MockTokenizer(new StringReader("testing the factory"), MockTokenizer.WHITESPACE, false);
81
 
    TokenStream stream = factory.create(tokenizer);
82
 
    assertTokenStreamContents(stream, 
83
 
        new String[] { "testing", "testing_the", "the", "the_factory", "factory" });
84
 
  }
85
 
}