diff --git a/solr/core/src/java/org/apache/solr/analysis/TypeTokenFilterFactory.java b/solr/core/src/java/org/apache/solr/analysis/TypeTokenFilterFactory.java index 635393cf145..b6d46ff6025 100644 --- a/solr/core/src/java/org/apache/solr/analysis/TypeTokenFilterFactory.java +++ b/solr/core/src/java/org/apache/solr/analysis/TypeTokenFilterFactory.java @@ -27,31 +27,26 @@ import org.apache.solr.util.plugin.ResourceLoaderAware; import java.io.IOException; import java.util.HashSet; import java.util.List; -import java.util.Map; import java.util.Set; /** * Factory class for {@link TypeTokenFilter} *
  * <fieldType name="chars" class="solr.TextField" positionIncrementGap="100">
- *   <analyzer>
- *     <tokenizer class="solr.StandardTokenizerFactory"/>
- *     <filter class="solr.TypeTokenFilterFactory" types="stoptypes.txt" enablePositionIncrements="true"/>
- *   </analyzer>
+ * <analyzer>
+ * <tokenizer class="solr.StandardTokenizerFactory"/>
+ * <filter class="solr.TypeTokenFilterFactory" types="stoptypes.txt" enablePositionIncrements="true"
+ * useWhiteList="false"/>
+ * </analyzer>
  * </fieldType>
*/ public class TypeTokenFilterFactory extends BaseTokenFilterFactory implements ResourceLoaderAware { - @Override - public void init(Map args) { - super.init(args); - } - @Override public void inform(ResourceLoader loader) { String stopTypesFiles = args.get("types"); enablePositionIncrements = getBoolean("enablePositionIncrements", false); - + useWhitelist = getBoolean("useWhitelist", false); if (stopTypesFiles != null) { try { List files = StrUtils.splitFileNames(stopTypesFiles); @@ -70,6 +65,7 @@ public class TypeTokenFilterFactory extends BaseTokenFilterFactory implements Re } } + private boolean useWhitelist; private Set stopTypes; private boolean enablePositionIncrements; @@ -83,6 +79,6 @@ public class TypeTokenFilterFactory extends BaseTokenFilterFactory implements Re @Override public TokenStream create(TokenStream input) { - return new TypeTokenFilter(enablePositionIncrements, input, stopTypes); + return new TypeTokenFilter(enablePositionIncrements, input, stopTypes, useWhitelist); } } diff --git a/solr/core/src/test/org/apache/solr/analysis/TestTypeTokenFilterFactory.java b/solr/core/src/test/org/apache/solr/analysis/TestTypeTokenFilterFactory.java index 0e7f743e833..f2e4dea989f 100644 --- a/solr/core/src/test/org/apache/solr/analysis/TestTypeTokenFilterFactory.java +++ b/solr/core/src/test/org/apache/solr/analysis/TestTypeTokenFilterFactory.java @@ -49,6 +49,7 @@ public class TestTypeTokenFilterFactory extends BaseTokenTestCase { factory = new TypeTokenFilterFactory(); args.put("types", "stoptypes-1.txt, stoptypes-2.txt"); args.put("enablePositionIncrements", "false"); + args.put("useWhitelist","true"); factory.init(args); factory.inform(loader); types = factory.getStopTypes(); @@ -58,7 +59,7 @@ public class TestTypeTokenFilterFactory extends BaseTokenTestCase { } @Test - public void testCreation() throws Exception { + public void testCreationWithBlackList() throws Exception { TypeTokenFilterFactory typeTokenFilterFactory = new TypeTokenFilterFactory(); Map args = new HashMap(DEFAULT_VERSION_PARAM); args.put("types", "stoptypes-1.txt, stoptypes-2.txt"); @@ -68,6 +69,19 @@ public class TestTypeTokenFilterFactory extends BaseTokenTestCase { input.setIntValue(123); typeTokenFilterFactory.create(input); } + + @Test + public void testCreationWithWhiteList() throws Exception { + TypeTokenFilterFactory typeTokenFilterFactory = new TypeTokenFilterFactory(); + Map args = new HashMap(DEFAULT_VERSION_PARAM); + args.put("types", "stoptypes-1.txt, stoptypes-2.txt"); + args.put("enablePositionIncrements", "false"); + args.put("useWhitelist","true"); + typeTokenFilterFactory.init(args); + NumericTokenStream input = new NumericTokenStream(); + input.setIntValue(123); + typeTokenFilterFactory.create(input); + } @Test public void testMissingTypesParameter() throws Exception {