You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by ni...@apache.org on 2016/10/23 13:02:06 UTC
[20/50] [abbrv] lucenenet git commit: Fixed parsing bug in
Core.Search.FieldCache. Also changed IFieldCache.InfoStream from StreamWriter
to TextWriter to allow more flexibility in usage (can use a StringWriter
rather than writing to a stream).
Fixed parsing bug in Core.Search.FieldCache. Also changed IFieldCache.InfoStream from StreamWriter to TextWriter to allow more flexibility in usage (can use a StringWriter rather than writing to a stream).
Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/fac1be26
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/fac1be26
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/fac1be26
Branch: refs/heads/master
Commit: fac1be26229ef2212fd1d9a5a683545a1fef64e8
Parents: 35bc499
Author: Shad Storhaug <sh...@shadstorhaug.com>
Authored: Mon Oct 17 22:33:51 2016 +0700
Committer: Shad Storhaug <sh...@shadstorhaug.com>
Committed: Thu Oct 20 18:20:56 2016 +0700
----------------------------------------------------------------------
src/Lucene.Net.Core/Search/FieldCache.cs | 8 ++++++--
src/Lucene.Net.Core/Search/FieldCacheImpl.cs | 8 ++++----
src/Lucene.Net.Tests/core/Search/TestFieldCache.cs | 15 +++++++++------
3 files changed, 19 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/fac1be26/src/Lucene.Net.Core/Search/FieldCache.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Search/FieldCache.cs b/src/Lucene.Net.Core/Search/FieldCache.cs
index 2e269c0..712de8d 100644
--- a/src/Lucene.Net.Core/Search/FieldCache.cs
+++ b/src/Lucene.Net.Core/Search/FieldCache.cs
@@ -349,7 +349,7 @@ namespace Lucene.Net.Search
/// entries are created that are not sane according to
/// <seealso cref="Lucene.Net.Util.FieldCacheSanityChecker"/>.
/// </summary>
- StreamWriter InfoStream { set; get; }
+ TextWriter InfoStream { set; get; }
}
public static class FieldCache
@@ -568,7 +568,11 @@ namespace Lucene.Net.Search
// UTF8 bytes... but really users should use
// FloatField, instead, which already decodes
// directly from byte[]
- return float.Parse(term.Utf8ToString(), NumberStyles.Float, CultureInfo.InvariantCulture);
+
+ // LUCENENET: We parse to double first and then cast to float, which allows us to parse
+ // double.MaxValue.ToString("R") (resulting in Infinity). This is how it worked in Java
+ // and the TestFieldCache.TestInfoStream() test depends on this behavior to pass.
+ return (float)double.Parse(term.Utf8ToString(), NumberStyles.Float, CultureInfo.InvariantCulture);
}
public TermsEnum TermsEnum(Terms terms)
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/fac1be26/src/Lucene.Net.Core/Search/FieldCacheImpl.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Search/FieldCacheImpl.cs b/src/Lucene.Net.Core/Search/FieldCacheImpl.cs
index 7f9e301..2eb716e 100644
--- a/src/Lucene.Net.Core/Search/FieldCacheImpl.cs
+++ b/src/Lucene.Net.Core/Search/FieldCacheImpl.cs
@@ -295,7 +295,7 @@ namespace Lucene.Net.Search
// call to FieldCache.getXXX
if (key.Custom != null && Wrapper != null)
{
- StreamWriter infoStream = Wrapper.InfoStream;
+ TextWriter infoStream = Wrapper.InfoStream;
if (infoStream != null)
{
PrintNewInsanity(infoStream, progress.Value);
@@ -308,7 +308,7 @@ namespace Lucene.Net.Search
return value;
}
- internal virtual void PrintNewInsanity(StreamWriter infoStream, object value)
+ internal virtual void PrintNewInsanity(TextWriter infoStream, object value)
{
FieldCacheSanityChecker.Insanity[] insanities = FieldCacheSanityChecker.CheckSanity(Wrapper);
for (int i = 0; i < insanities.Length; i++)
@@ -1931,9 +1931,9 @@ namespace Lucene.Net.Search
}
}
- private volatile StreamWriter infoStream;
+ private volatile TextWriter infoStream;
- public virtual StreamWriter InfoStream
+ public virtual TextWriter InfoStream
{
set
{
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/fac1be26/src/Lucene.Net.Tests/core/Search/TestFieldCache.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Search/TestFieldCache.cs b/src/Lucene.Net.Tests/core/Search/TestFieldCache.cs
index abe05f7..c7dd8bd 100644
--- a/src/Lucene.Net.Tests/core/Search/TestFieldCache.cs
+++ b/src/Lucene.Net.Tests/core/Search/TestFieldCache.cs
@@ -64,7 +64,7 @@ namespace Lucene.Net.Search
using IOUtils = Lucene.Net.Util.IOUtils;
using LuceneTestCase = Lucene.Net.Util.LuceneTestCase;
using TestUtil = Lucene.Net.Util.TestUtil;
-
+ using System.Text;
[TestFixture]
public class TestFieldCache : LuceneTestCase
@@ -158,11 +158,14 @@ namespace Lucene.Net.Search
try
{
IFieldCache cache = FieldCache.DEFAULT;
- MemoryStream bos = new MemoryStream(1024);
- cache.InfoStream = new StreamWriter(bos.ToString(), false, IOUtils.CHARSET_UTF_8);
- cache.GetDoubles(Reader, "theDouble", false);
- cache.GetFloats(Reader, "theDouble", false);
- Assert.IsTrue(bos.ToString(/*IOUtils.UTF_8*/).IndexOf("WARNING") != -1);
+ StringBuilder sb = new StringBuilder();
+ using (var bos = new StringWriter(sb))
+ {
+ cache.InfoStream = bos;
+ cache.GetDoubles(Reader, "theDouble", false);
+ cache.GetFloats(Reader, "theDouble", false);
+ }
+ Assert.IsTrue(sb.ToString(/*IOUtils.UTF_8*/).IndexOf("WARNING") != -1);
}
finally
{