public virtual void TestLUCENENET615() { var english = new EnglishAnalyzer(Lucene.Net.Util.LuceneVersion.LUCENE_48); var whitespace = new WhitespaceAnalyzer(Lucene.Net.Util.LuceneVersion.LUCENE_48); var pf = new PerFieldAnalyzerWrapper(english, new JCG.Dictionary <string, Analyzer>() { { "foo", whitespace } }); var test1 = english.GetTokenStream(null, "test"); // Does not throw var test2 = pf.GetTokenStream("", "test"); // works Assert.DoesNotThrow(() => pf.GetTokenStream(null, "test"), "GetTokenStream should not throw NullReferenceException with a null key"); }
public virtual void TestPerField() { string text = "Qwerty"; IDictionary <string, Analyzer> analyzerPerField = new Dictionary <string, Analyzer>(); analyzerPerField["special"] = new SimpleAnalyzer(TEST_VERSION_CURRENT); PerFieldAnalyzerWrapper analyzer = new PerFieldAnalyzerWrapper(new WhitespaceAnalyzer(TEST_VERSION_CURRENT), analyzerPerField); TokenStream tokenStream = analyzer.GetTokenStream("field", text); try { ICharTermAttribute termAtt = tokenStream.GetAttribute <ICharTermAttribute>(); tokenStream.Reset(); assertTrue(tokenStream.IncrementToken()); assertEquals("WhitespaceAnalyzer does not lowercase", "Qwerty", termAtt.ToString()); assertFalse(tokenStream.IncrementToken()); tokenStream.End(); } finally { IOUtils.DisposeWhileHandlingException(tokenStream); } tokenStream = analyzer.GetTokenStream("special", text); try { ICharTermAttribute termAtt = tokenStream.GetAttribute <ICharTermAttribute>(); tokenStream.Reset(); assertTrue(tokenStream.IncrementToken()); assertEquals("SimpleAnalyzer lowercases", "qwerty", termAtt.ToString()); assertFalse(tokenStream.IncrementToken()); tokenStream.End(); } finally { IOUtils.DisposeWhileHandlingException(tokenStream); } }