You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by di...@apache.org on 2011/06/05 15:08:50 UTC
[Lucene.Net] svn commit: r1132394 - in /incubator/lucene.net/branches/Lucene.Net_2_9_4g:
src/core/Index/ReusableStringReader.cs test/core/Support/TestOldPatches.cs
Author: digy
Date: Sun Jun 5 13:08:49 2011
New Revision: 1132394
URL: http://svn.apache.org/viewvc?rev=1132394&view=rev
Log:
[LUCENENET-422] Custom tokenizers may fail when indexing due to ReusableStringReader not implement some method of TextReader
Modified:
incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Index/ReusableStringReader.cs
incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/core/Support/TestOldPatches.cs
Modified: incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Index/ReusableStringReader.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Index/ReusableStringReader.cs?rev=1132394&r1=1132393&r2=1132394&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Index/ReusableStringReader.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Index/ReusableStringReader.cs Sun Jun 5 13:08:49 2011
@@ -69,28 +69,62 @@ namespace Lucene.Net.Index
public override int Read()
{
- throw new NotImplementedException("ReusableStringReader: This method is not implemented");
+ if (left > 0)
+ {
+ char ch = s[upto];
+ upto += 1;
+ left -= 1;
+ return (int)ch;
+ }
+ return -1;
}
public override int ReadBlock(char[] buffer, int index, int count)
{
- throw new NotImplementedException("ReusableStringReader: This method is not implemented");
+ return Read(buffer, index, count);
}
public override string ReadLine()
{
- throw new NotImplementedException("ReusableStringReader: This method is not implemented");
+ int i;
+ for (i = upto; i < s.Length; i++)
+ {
+ char c = s[i];
+ if (c == '\r' || c == '\n')
+ {
+ string result = s.Substring(upto, i - upto);
+ upto = i + 1;
+ left = s.Length - upto;
+ if (c == '\r' && upto < s.Length && s[upto] == '\n')
+ {
+ upto++;
+ left--;
+ }
+ return result;
+ }
+ }
+ if (i > upto)
+ {
+ return ReadToEnd();
+ }
+ return null;
}
public override int Peek()
{
- throw new NotImplementedException("ReusableStringReader: This method is not implemented");
+ if (left > 0)
+ {
+ return (int)s[upto];
+ }
+ return -1;
}
public override string ReadToEnd()
{
+ string result = s.Substring(upto, left);
left = 0;
- return s;
+ upto = s.Length - 1;
+ return result;
}
}
}
\ No newline at end of file
Modified: incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/core/Support/TestOldPatches.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/core/Support/TestOldPatches.cs?rev=1132394&r1=1132393&r2=1132394&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/core/Support/TestOldPatches.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/core/Support/TestOldPatches.cs Sun Jun 5 13:08:49 2011
@@ -131,7 +131,7 @@ namespace Lucene.Net.Support
wr.Close();
}
- static string TEST_STRING = "Some Text and some more Text";
+ static string TEST_STRING = "First Line\nSecond Line";
class TestAnalyzer : Lucene.Net.Analysis.Analyzer
{
@@ -141,20 +141,23 @@ namespace Lucene.Net.Support
}
}
- class TestTokenizer : Lucene.Net.Analysis.CharTokenizer
+ class TestTokenizer : Lucene.Net.Analysis.Tokenizer
{
public TestTokenizer(System.IO.TextReader Reader)
- : base(Reader)
{
//Caution: "Reader" is actually of type "ReusableStringReader" and some
//methods (for ex. "ReadToEnd", "Peek", "ReadLine") is not implemented.
- Assert.AreEqual(TEST_STRING, Reader.ReadToEnd(), "Issue LUCENENET-150: \"ReadToEnd\" method is not implemented");
+
+ Assert.AreEqual("ReusableStringReader", Reader.GetType().Name);
+ Assert.AreEqual("First Line", Reader.ReadLine(), "\"ReadLine\" method is not implemented");
+ Assert.AreEqual("Second Line",Reader.ReadToEnd(),"\"ReadToEnd\" method is not implemented");
}
- protected override bool IsTokenChar(char c)
+ public override Token Next()
{
- return char.IsLetterOrDigit(c);
+ return null;
}
+
}
[Test]