Skip to content

Commit

Permalink
Respect ignoreCase flag in CommonGramsFilterFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
chenhh021 committed Dec 12, 2022
1 parent c0c4804 commit e603350
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace Lucene.Net.Analysis.CommonGrams
/// </summary>
public class CommonGramsFilterFactory : TokenFilterFactory, IResourceLoaderAware
{
// TODO: shared base class for Stop/Keep/CommonGrams?
// TODO: shared base class for Stop/Keep/CommonGrams?
private CharArraySet commonWords;
private readonly string commonWordFiles;
private readonly string format;
Expand Down Expand Up @@ -71,7 +71,7 @@ public virtual void Inform(IResourceLoader loader)
}
else
{
commonWords = StopAnalyzer.ENGLISH_STOP_WORDS_SET;
commonWords = new CharArraySet(m_luceneMatchVersion,StopAnalyzer.ENGLISH_STOP_WORDS_SET, ignoreCase);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace Lucene.Net.Analysis.CommonGrams
/// Tests pretty much copied from StopFilterFactoryTest We use the test files
/// used by the StopFilterFactoryTest TODO: consider creating separate test files
/// so this won't break if stop filter test files change
///
///
/// </summary>
public class TestCommonGramsFilterFactory : BaseTokenStreamFactoryTestCase
{
Expand Down Expand Up @@ -79,6 +79,22 @@ public virtual void TestDefaults()
AssertTokenStreamContents(stream, new string[] { "testing", "testing_the", "the", "the_factory", "factory" });
}

[Test]
public void TestIgnoreCase()
{
IResourceLoader loader = new ClasspathResourceLoader(typeof(TestAnalyzers));
CommonGramsFilterFactory factory =
(CommonGramsFilterFactory)
TokenFilterFactory("CommonGrams", TEST_VERSION_CURRENT, loader, "ignoreCase", "true");
CharArraySet words = factory.CommonWords;
assertTrue("words is null and it shouldn't be", words != null);
assertTrue(words.contains("the"));
assertTrue(words.contains("The"));
Tokenizer tokenizer = new MockTokenizer(new StringReader("testing The factory"),MockTokenizer.WHITESPACE, false);
TokenStream stream = factory.Create(tokenizer);
AssertTokenStreamContents(
stream, new String[] {"testing", "testing_The", "The", "The_factory", "factory"});
}
/// <summary>
/// Test that bogus arguments result in exception </summary>
[Test]
Expand Down

0 comments on commit e603350

Please sign in to comment.