Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-1850: don't copy word set for each KeepWordFilter instance

Yonik Seeleyfc98d803454d
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 035cff3539c..ad2ff43ccbd 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -235,6 +235,9 @@ Bug Fixes
* SOLR-1797: fix ConcurrentModificationException and potential memory
leaks in ResourceLoader. (yonik)
+* SOLR-1850: change KeepWordFilter so a new word set is not created for
+ each instance (John Wang via yonik)
+
Other Changes
----------------------
diff --git a/solr/src/java/org/apache/solr/analysis/KeepWordFilter.java b/solr/src/java/org/apache/solr/analysis/KeepWordFilter.java
index 74e9bb744bd..5ac3585bb7b 100644
--- a/solr/src/java/org/apache/solr/analysis/KeepWordFilter.java
+++ b/solr/src/java/org/apache/solr/analysis/KeepWordFilter.java
@@ -39,8 +39,14 @@ public final class KeepWordFilter extends TokenFilter {
private final TermAttribute termAtt;
public KeepWordFilter(TokenStream in, Set<String> words, boolean ignoreCase ) {
+ this(in, new CharArraySet(words, ignoreCase));
+ }
+
+ /** The words set passed to this constructor will be directly used by this filter
+ * and should not be modified, */
+ public KeepWordFilter(TokenStream in, CharArraySet words) {
super(in);
- this.words = new CharArraySet(words, ignoreCase);
+ this.words = words;
this.termAtt = (TermAttribute)addAttribute(TermAttribute.class);
}
diff --git a/solr/src/java/org/apache/solr/analysis/KeepWordFilterFactory.java b/solr/src/java/org/apache/solr/analysis/KeepWordFilterFactory.java
index aad797458e0..a2a12db67dd 100644
--- a/solr/src/java/org/apache/solr/analysis/KeepWordFilterFactory.java
+++ b/solr/src/java/org/apache/solr/analysis/KeepWordFilterFactory.java
@@ -72,10 +72,13 @@ public class KeepWordFilterFactory extends BaseTokenFilterFactory implements Res
public void setIgnoreCase(boolean ignoreCase) {
this.ignoreCase = ignoreCase;
+ if (words != null) {
+ words = new CharArraySet(words, ignoreCase);
+ }
}
public KeepWordFilter create(TokenStream input) {
- return new KeepWordFilter(input, (Set)words, ignoreCase);
+ return new KeepWordFilter(input, words);
}
public CharArraySet getWords() {
diff --git a/solr/src/test/org/apache/solr/analysis/TestKeepWordFilter.java b/solr/src/test/org/apache/solr/analysis/TestKeepWordFilter.java
index 2af750f9ebf..55ac2d72287 100644
--- a/solr/src/test/org/apache/solr/analysis/TestKeepWordFilter.java
+++ b/solr/src/test/org/apache/solr/analysis/TestKeepWordFilter.java
@@ -66,10 +66,12 @@ public class TestKeepWordFilter extends BaseTokenTestCase {
assertTokenStreamContents(stream, new String[] { "aaa", "BBB" });
// Now force case
+ factory = new KeepWordFilterFactory();
args = new HashMap<String, String>();
args.put( "ignoreCase", "false" );
factory.init( args );
factory.inform( loader );
+ factory.setWords( words );
assertFalse(factory.isIgnoreCase());
stream = factory.create(new WhitespaceTokenizer(new StringReader(input)));
assertTokenStreamContents(stream, new String[] { "aaa" });