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
9
* http://www.apache.org/licenses/LICENSE-2.0
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.
17
package org.apache.solr.analysis;
19
import java.io.IOException;
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;
30
* Construct {@link CommonGramsQueryFilter}.
32
* This is pretty close to a straight copy from {@link StopFilterFactory}.
34
* <pre class="prettyprint" >
35
* <fieldType name="text_cmmngrmsqry" class="solr.TextField" positionIncrementGap="100">
37
* <tokenizer class="solr.WhitespaceTokenizerFactory"/>
38
* <filter class="solr.CommonGramsQueryFilterFactory" words="commongramsquerystopwords.txt" ignoreCase="false"/>
40
* </fieldType></pre>
41
* @version $Id: CommonGramsQueryFilterFactory.java 1073344 2011-02-22 14:35:02Z koji $
43
public class CommonGramsQueryFilterFactory extends BaseTokenFilterFactory
44
implements ResourceLoaderAware {
47
public void init(Map<String,String> args) {
52
public void inform(ResourceLoader loader) {
53
String commonWordFiles = args.get("words");
54
ignoreCase = getBoolean("ignoreCase", false);
56
if (commonWordFiles != null) {
58
commonWords = getWordSet(loader, commonWordFiles, ignoreCase);
59
} catch (IOException e) {
60
throw new RuntimeException(e);
63
commonWords = (CharArraySet) StopAnalyzer.ENGLISH_STOP_WORDS_SET;
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;
71
private boolean ignoreCase;
73
public boolean isIgnoreCase() {
77
public Set<?> getCommonWords() {
82
* Create a CommonGramsFilter and wrap it with a CommonGramsQueryFilter
84
public CommonGramsQueryFilter create(TokenStream input) {
85
CommonGramsFilter commonGrams = new CommonGramsFilter(luceneMatchVersion, input, commonWords,
87
CommonGramsQueryFilter commonGramsQuery = new CommonGramsQueryFilter(
89
return commonGramsQuery;