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

« back to all changes in this revision

Viewing changes to solr/core/src/test/org/apache/solr/analysis/TestLuceneMatchVersion.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.lang.reflect.Field;
21
 
 
22
 
import org.apache.lucene.analysis.standard.StandardTokenizer;
23
 
import org.apache.solr.SolrTestCaseJ4;
24
 
import org.apache.solr.core.Config;
25
 
import org.apache.solr.schema.IndexSchema;
26
 
import org.apache.solr.schema.FieldType;
27
 
import org.apache.lucene.analysis.Analyzer;
28
 
import org.apache.lucene.analysis.standard.StandardAnalyzer;
29
 
import org.apache.lucene.util.Version;
30
 
import org.junit.BeforeClass;
31
 
 
32
 
/**
33
 
 * Tests for luceneMatchVersion property for analyzers
34
 
 */
35
 
public class TestLuceneMatchVersion extends SolrTestCaseJ4 {
36
 
 
37
 
  @BeforeClass
38
 
  public static void beforeClass() throws Exception {
39
 
    initCore("solrconfig.xml","schema-luceneMatchVersion.xml");
40
 
  }
41
 
  
42
 
  // this must match the solrconfig.xml version for this test
43
 
  public static final Version DEFAULT_VERSION =
44
 
    Config.parseLuceneVersionString(System.getProperty("tests.luceneMatchVersion", "LUCENE_CURRENT"));
45
 
 
46
 
  public void testStandardTokenizerVersions() throws Exception {
47
 
    assertEquals(DEFAULT_VERSION, solrConfig.luceneMatchVersion);
48
 
    
49
 
    final IndexSchema schema = h.getCore().getSchema();
50
 
    
51
 
    FieldType type = schema.getFieldType("textDefault");
52
 
    TokenizerChain ana = (TokenizerChain) type.getAnalyzer();
53
 
    assertEquals(DEFAULT_VERSION, ((BaseTokenizerFactory) ana.getTokenizerFactory()).luceneMatchVersion);
54
 
    assertEquals(DEFAULT_VERSION, ((BaseTokenFilterFactory) ana.getTokenFilterFactories()[2]).luceneMatchVersion);
55
 
    TokenizerChain.TokenStreamInfo tsi = ana.getStream("textDefault",new StringReader(""));
56
 
    StandardTokenizer tok = (StandardTokenizer) tsi.getTokenizer();
57
 
    assertTrue(tok.isReplaceInvalidAcronym());
58
 
    
59
 
    type = schema.getFieldType("text20");
60
 
    ana = (TokenizerChain) type.getAnalyzer();
61
 
    assertEquals(Version.LUCENE_20, ((BaseTokenizerFactory) ana.getTokenizerFactory()).luceneMatchVersion);
62
 
    assertEquals(Version.LUCENE_24, ((BaseTokenFilterFactory) ana.getTokenFilterFactories()[2]).luceneMatchVersion);
63
 
    tsi = ana.getStream("text20",new StringReader(""));
64
 
    tok = (StandardTokenizer) tsi.getTokenizer();
65
 
    assertFalse(tok.isReplaceInvalidAcronym());
66
 
 
67
 
    // this is a hack to get the private matchVersion field in StandardAnalyzer's superclass, may break in later lucene versions - we have no getter :(
68
 
    final Field matchVersionField = StandardAnalyzer.class.getSuperclass().getDeclaredField("matchVersion");
69
 
    matchVersionField.setAccessible(true);
70
 
 
71
 
    type = schema.getFieldType("textStandardAnalyzerDefault");
72
 
    Analyzer ana1 = type.getAnalyzer();
73
 
    assertTrue(ana1 instanceof StandardAnalyzer);
74
 
    assertEquals(DEFAULT_VERSION, matchVersionField.get(ana1));
75
 
 
76
 
    type = schema.getFieldType("textStandardAnalyzer20");
77
 
    ana1 = type.getAnalyzer();
78
 
    assertTrue(ana1 instanceof StandardAnalyzer);
79
 
    assertEquals(Version.LUCENE_20, matchVersionField.get(ana1));
80
 
  }
81
 
}