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

« back to all changes in this revision

Viewing changes to solr/core/src/java/org/apache/solr/analysis/CommonGramsQueryFilterFactory.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.IOException;
20
 
import java.util.Map;
21
 
import java.util.Set;
22
 
 
23
 
import org.apache.lucene.analysis.CharArraySet;
24
 
import org.apache.lucene.analysis.StopAnalyzer;
25
 
import org.apache.lucene.analysis.TokenStream;
26
 
import org.apache.solr.common.ResourceLoader;
27
 
import org.apache.solr.util.plugin.ResourceLoaderAware;
28
 
 
29
 
/**
30
 
 * Construct {@link CommonGramsQueryFilter}.
31
 
 * 
32
 
 * This is pretty close to a straight copy from {@link StopFilterFactory}.
33
 
 * 
34
 
 * <pre class="prettyprint" >
35
 
 * &lt;fieldType name="text_cmmngrmsqry" class="solr.TextField" positionIncrementGap="100"&gt;
36
 
 *   &lt;analyzer&gt;
37
 
 *     &lt;tokenizer class="solr.WhitespaceTokenizerFactory"/&gt;
38
 
 *     &lt;filter class="solr.CommonGramsQueryFilterFactory" words="commongramsquerystopwords.txt" ignoreCase="false"/&gt;
39
 
 *   &lt;/analyzer&gt;
40
 
 * &lt;/fieldType&gt;</pre>
41
 
 * @version $Id: CommonGramsQueryFilterFactory.java 1073344 2011-02-22 14:35:02Z koji $
42
 
 */
43
 
public class CommonGramsQueryFilterFactory extends BaseTokenFilterFactory
44
 
    implements ResourceLoaderAware {
45
 
 
46
 
  @Override
47
 
  public void init(Map<String,String> args) {
48
 
    super.init(args);
49
 
    assureMatchVersion();
50
 
  }
51
 
 
52
 
  public void inform(ResourceLoader loader) {
53
 
    String commonWordFiles = args.get("words");
54
 
    ignoreCase = getBoolean("ignoreCase", false);
55
 
 
56
 
    if (commonWordFiles != null) {
57
 
      try {
58
 
        commonWords = getWordSet(loader, commonWordFiles, ignoreCase);
59
 
      } catch (IOException e) {
60
 
        throw new RuntimeException(e);
61
 
      }
62
 
    } else {
63
 
      commonWords = (CharArraySet) StopAnalyzer.ENGLISH_STOP_WORDS_SET;
64
 
    }
65
 
  }
66
 
 
67
 
  // Force the use of a char array set, as it is the most performant, although
68
 
  // this may break things if Lucene ever goes away from it. See SOLR-1095
69
 
  private CharArraySet commonWords;
70
 
 
71
 
  private boolean ignoreCase;
72
 
 
73
 
  public boolean isIgnoreCase() {
74
 
    return ignoreCase;
75
 
  }
76
 
 
77
 
  public Set<?> getCommonWords() {
78
 
    return commonWords;
79
 
  }
80
 
 
81
 
  /**
82
 
   * Create a CommonGramsFilter and wrap it with a CommonGramsQueryFilter
83
 
   */
84
 
  public CommonGramsQueryFilter create(TokenStream input) {
85
 
    CommonGramsFilter commonGrams = new CommonGramsFilter(luceneMatchVersion, input, commonWords,
86
 
        ignoreCase);
87
 
    CommonGramsQueryFilter commonGramsQuery = new CommonGramsQueryFilter(
88
 
        commonGrams);
89
 
    return commonGramsQuery;
90
 
  }
91
 
}