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

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@928133 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yonik Seeley 2010-03-27 03:44:06 +00:00
parent b83700b51e
commit fc98d80345
4 changed files with 16 additions and 2 deletions

View File

@ -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
----------------------

View File

@ -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);
}

View File

@ -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() {

View File

@ -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" });