diff --git a/contrib/CHANGES.txt b/contrib/CHANGES.txt index 60552bc1a5a..822e8cfca46 100644 --- a/contrib/CHANGES.txt +++ b/contrib/CHANGES.txt @@ -33,6 +33,9 @@ API Changes * LUCENE-2108: Add SpellChecker.close, to close the underlying reader. (Eirik Bjørsnøs via Mike McCandless) + * LUCENE-2165: Add a constructor to SnowballAnalyzer that takes a Set of + stopwords, and deprecate the String[] one. (Nick Burch via Robert Muir) + New features * LUCENE-2102: Add a Turkish LowerCase Filter. TurkishLowerCaseFilter handles diff --git a/contrib/snowball/src/java/org/apache/lucene/analysis/snowball/SnowballAnalyzer.java b/contrib/snowball/src/java/org/apache/lucene/analysis/snowball/SnowballAnalyzer.java index c0260fa79d8..4f2cbf797d7 100644 --- a/contrib/snowball/src/java/org/apache/lucene/analysis/snowball/SnowballAnalyzer.java +++ b/contrib/snowball/src/java/org/apache/lucene/analysis/snowball/SnowballAnalyzer.java @@ -51,11 +51,21 @@ public final class SnowballAnalyzer extends Analyzer { this.matchVersion = matchVersion; } - /** Builds the named analyzer with the given stop words. */ + /** + * Builds the named analyzer with the given stop words. + * @deprecated Use {@link #SnowballAnalyzer(Version, String, Set)} instead. + */ public SnowballAnalyzer(Version matchVersion, String name, String[] stopWords) { this(matchVersion, name); stopSet = StopFilter.makeStopSet(matchVersion, stopWords); } + + /** Builds the named analyzer with the given stop words. */ + public SnowballAnalyzer(Version matchVersion, String name, Set stopWords) { + this(matchVersion, name); + stopSet = CharArraySet.unmodifiableSet(CharArraySet.copy(matchVersion, + stopWords)); + } /** Constructs a {@link StandardTokenizer} filtered by a {@link StandardFilter}, a {@link LowerCaseFilter}, a {@link StopFilter}, diff --git a/contrib/snowball/src/test/org/apache/lucene/analysis/snowball/TestSnowball.java b/contrib/snowball/src/test/org/apache/lucene/analysis/snowball/TestSnowball.java index bc960779ffd..04ea14d328f 100644 --- a/contrib/snowball/src/test/org/apache/lucene/analysis/snowball/TestSnowball.java +++ b/contrib/snowball/src/test/org/apache/lucene/analysis/snowball/TestSnowball.java @@ -21,6 +21,7 @@ import org.apache.lucene.analysis.BaseTokenStreamTestCase; import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.index.Payload; import org.apache.lucene.analysis.TokenStream; +import org.apache.lucene.analysis.standard.StandardAnalyzer; import org.apache.lucene.analysis.tokenattributes.FlagsAttribute; import org.apache.lucene.analysis.tokenattributes.OffsetAttribute; import org.apache.lucene.analysis.tokenattributes.PayloadAttribute; @@ -36,6 +37,13 @@ public class TestSnowball extends BaseTokenStreamTestCase { assertAnalyzesTo(a, "he abhorred accents", new String[]{"he", "abhor", "accent"}); } + + public void testStopwords() throws Exception { + Analyzer a = new SnowballAnalyzer(Version.LUCENE_CURRENT, "English", + StandardAnalyzer.STOP_WORDS_SET); + assertAnalyzesTo(a, "the quick brown fox jumped", + new String[]{"quick", "brown", "fox", "jump"}); + } /** * Test english lowercasing. Test both cases (pre-3.1 and post-3.1) to ensure