lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From synhers...@apache.org
Subject [2/5] lucenenet git commit: Some files cleanup
Date Fri, 07 Nov 2014 03:59:49 GMT
Some files cleanup


Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/051b0ef0
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/051b0ef0
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/051b0ef0

Branch: refs/heads/master
Commit: 051b0ef091364b0d9d7697759eca69f07391741a
Parents: bf7317d
Author: Itamar Syn-Hershko <itamar@code972.com>
Authored: Wed Nov 5 20:13:14 2014 +0200
Committer: Itamar Syn-Hershko <itamar@code972.com>
Committed: Wed Nov 5 20:13:14 2014 +0200

----------------------------------------------------------------------
 .../Function/ValueSources/EnumFieldSource.cs    | 603 +++++++++----------
 .../Function/ValueSources/ScaleFloatFunction.cs | 284 ++++-----
 .../Function/ValueSources/TFValueSource.cs      | 346 +++++------
 3 files changed, 619 insertions(+), 614 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/051b0ef0/src/Lucene.Net.Queries/Function/ValueSources/EnumFieldSource.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/EnumFieldSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/EnumFieldSource.cs
index 1958daf..cf2c366 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/EnumFieldSource.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/EnumFieldSource.cs
@@ -11,99 +11,100 @@ using Lucene.Net.Util.Mutable;
 namespace Lucene.Net.Queries.Function.ValueSources
 {
 
-	/*
-	 * Licensed to the Apache Software Foundation (ASF) under one or more
-	 * contributor license agreements.  See the NOTICE file distributed with
-	 * this work for additional information regarding copyright ownership.
-	 * The ASF licenses this file to You under the Apache License, Version 2.0
-	 * (the "License"); you may not use this file except in compliance with
-	 * the License.  You may obtain a copy of the License at
-	 *
-	 *     http://www.apache.org/licenses/LICENSE-2.0
-	 *
-	 * Unless required by applicable law or agreed to in writing, software
-	 * distributed under the License is distributed on an "AS IS" BASIS,
-	 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-	 * See the License for the specific language governing permissions and
-	 * limitations under the License.
-	 */
+    /*
+     * Licensed to the Apache Software Foundation (ASF) under one or more
+     * contributor license agreements.  See the NOTICE file distributed with
+     * this work for additional information regarding copyright ownership.
+     * The ASF licenses this file to You under the Apache License, Version 2.0
+     * (the "License"); you may not use this file except in compliance with
+     * the License.  You may obtain a copy of the License at
+     *
+     *     http://www.apache.org/licenses/LICENSE-2.0
+     *
+     * Unless required by applicable law or agreed to in writing, software
+     * distributed under the License is distributed on an "AS IS" BASIS,
+     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     * See the License for the specific language governing permissions and
+     * limitations under the License.
+     */
     /// <summary>
-	/// Obtains int field values from <seealso cref="IFieldCache#getInts"/> and makes
-	/// those values available as other numeric types, casting as needed.
-	/// StrVal of the value is not the int value, but its str (displayed) value
-	/// </summary>
-	public class EnumFieldSource : FieldCacheSource
-	{
-	  internal const int DEFAULT_VALUE = -1;
-
-	  internal readonly FieldCache.IIntParser parser;
-	  internal readonly IDictionary<int?, string> enumIntToStringMap;
-	  internal readonly IDictionary<string, int?> enumStringToIntMap;
-
-	  public EnumFieldSource(string field, FieldCache.IIntParser parser, IDictionary<int?,
string> enumIntToStringMap, IDictionary<string, int?> enumStringToIntMap) : base(field)
-	  {
-		this.parser = parser;
-		this.enumIntToStringMap = enumIntToStringMap;
-		this.enumStringToIntMap = enumStringToIntMap;
-	  }
-
-	  private static int? TryParseInt(string valueStr)
-	  {
-		int? intValue = null;
-		try
-		{
-		  intValue = Convert.ToInt32(valueStr);
-		}
-		catch (FormatException)
-		{
-		}
-		return intValue;
-	  }
-
-	  private string IntValueToStringValue(int? intVal)
-	  {
-		if (intVal == null)
-		{
-		  return null;
-		}
-
-		string enumString = enumIntToStringMap[intVal];
-		if (enumString != null)
-		{
-		  return enumString;
-		}
-		// can't find matching enum name - return DEFAULT_VALUE.toString()
-		return DEFAULT_VALUE.ToString(CultureInfo.InvariantCulture);
-	  }
-
-	  private int? StringValueToIntValue(string stringVal)
-	  {
-		if (stringVal == null)
-		{
-		  return null;
-		}
-
-		int? intValue;
-		int? enumInt = enumStringToIntMap[stringVal];
-		if (enumInt != null) //enum int found for str
-		{
-		  return enumInt;
-		}
-
-		//enum int not found for str
-		intValue = TryParseInt(stringVal);
-		if (intValue == null) //not Integer
-		{
-		  intValue = DEFAULT_VALUE;
-		}
-		string enumString = enumIntToStringMap[intValue];
-		if (enumString != null) //has matching str
-		{
-		  return intValue;
-		}
-
-		return DEFAULT_VALUE;
-	  }
+    /// Obtains int field values from <seealso cref="IFieldCache#getInts"/> and makes
+    /// those values available as other numeric types, casting as needed.
+    /// StrVal of the value is not the int value, but its str (displayed) value
+    /// </summary>
+    public class EnumFieldSource : FieldCacheSource
+    {
+        internal const int DEFAULT_VALUE = -1;
+
+        internal readonly FieldCache.IIntParser parser;
+        internal readonly IDictionary<int?, string> enumIntToStringMap;
+        internal readonly IDictionary<string, int?> enumStringToIntMap;
+
+        public EnumFieldSource(string field, FieldCache.IIntParser parser, IDictionary<int?,
string> enumIntToStringMap, IDictionary<string, int?> enumStringToIntMap)
+            : base(field)
+        {
+            this.parser = parser;
+            this.enumIntToStringMap = enumIntToStringMap;
+            this.enumStringToIntMap = enumStringToIntMap;
+        }
+
+        private static int? TryParseInt(string valueStr)
+        {
+            int? intValue = null;
+            try
+            {
+                intValue = Convert.ToInt32(valueStr);
+            }
+            catch (FormatException)
+            {
+            }
+            return intValue;
+        }
+
+        private string IntValueToStringValue(int? intVal)
+        {
+            if (intVal == null)
+            {
+                return null;
+            }
+
+            string enumString = enumIntToStringMap[intVal];
+            if (enumString != null)
+            {
+                return enumString;
+            }
+            // can't find matching enum name - return DEFAULT_VALUE.toString()
+            return DEFAULT_VALUE.ToString(CultureInfo.InvariantCulture);
+        }
+
+        private int? StringValueToIntValue(string stringVal)
+        {
+            if (stringVal == null)
+            {
+                return null;
+            }
+
+            int? intValue;
+            int? enumInt = enumStringToIntMap[stringVal];
+            if (enumInt != null) //enum int found for str
+            {
+                return enumInt;
+            }
+
+            //enum int not found for str
+            intValue = TryParseInt(stringVal);
+            if (intValue == null) //not Integer
+            {
+                intValue = DEFAULT_VALUE;
+            }
+            string enumString = enumIntToStringMap[intValue];
+            if (enumString != null) //has matching str
+            {
+                return intValue;
+            }
+
+            return DEFAULT_VALUE;
+        }
 
         public override string Description
         {
@@ -111,217 +112,213 @@ namespace Lucene.Net.Queries.Function.ValueSources
         }
 
 
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: @Override public org.apache.lucene.queries.function.FunctionValues GetValues(java.util.Map
context, org.apache.lucene.index.AtomicReaderContext readerContext) throws java.io.IOException
-	  public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext)
-	  {
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final org.apache.lucene.search.FieldCache.Ints arr = cache.getInts(readerContext.reader(),
field, parser, true);
-		FieldCache.Ints arr = cache.GetInts(readerContext.AtomicReader, field, parser, true);
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final org.apache.lucene.util.Bits valid = cache.getDocsWithField(readerContext.reader(),
field);
-		Bits valid = cache.GetDocsWithField(readerContext.AtomicReader, field);
-
-		return new IntDocValuesAnonymousInnerClassHelper(this, this, arr, valid);
-	  }
-
-	  private class IntDocValuesAnonymousInnerClassHelper : IntDocValues
-	  {
-		  private readonly EnumFieldSource outerInstance;
-
-		  private readonly FieldCache.Ints arr;
-		  private readonly Bits valid;
-
-		  public IntDocValuesAnonymousInnerClassHelper(EnumFieldSource outerInstance, EnumFieldSource
@this, FieldCache.Ints arr, Bits valid) : base(@this)
-		  {
-			  this.outerInstance = outerInstance;
-			  this.arr = arr;
-			  this.valid = valid;
-			  val = new MutableValueInt();
-		  }
-
-	      private readonly MutableValueInt val;
-
-		  public override float FloatVal(int doc)
-		  {
-			return (float) arr.Get(doc);
-		  }
-
-		  public override int IntVal(int doc)
-		  {
-			return arr.Get(doc);
-		  }
-
-		  public override long LongVal(int doc)
-		  {
-			return (long) arr.Get(doc);
-		  }
-
-		  public override double DoubleVal(int doc)
-		  {
-			return (double) arr.Get(doc);
-		  }
-
-		  public override string StrVal(int doc)
-		  {
-			int? intValue = arr.Get(doc);
-			return outerInstance.IntValueToStringValue(intValue);
-		  }
-
-		  public override object ObjectVal(int doc)
-		  {
-			return valid.Get(doc) ? (object) arr.Get(doc) : null;
-		  }
-
-		  public override bool Exists(int doc)
-		  {
-			return valid.Get(doc);
-		  }
-
-		  public override string ToString(int doc)
-		  {
-			return outerInstance.Description + '=' + StrVal(doc);
-		  }
-
-
-		  public override ValueSourceScorer GetRangeScorer(IndexReader reader, string lowerVal,
string upperVal, bool includeLower, bool includeUpper)
-		  {
-			int? lower = outerInstance.StringValueToIntValue(lowerVal);
-			int? upper = outerInstance.StringValueToIntValue(upperVal);
-
-			// instead of using separate comparison functions, adjust the endpoints.
-
-			if (lower == null)
-			{
-			  lower = int.MinValue;
-			}
-			else
-			{
-			  if (!includeLower && lower < int.MaxValue)
-			  {
-				  lower++;
-			  }
-			}
-
-			if (upper == null)
-			{
-			  upper = int.MaxValue;
-			}
-			else
-			{
-			  if (!includeUpper && upper > int.MinValue)
-			  {
-				  upper--;
-			  }
-			}
-
-			int ll = lower.Value;
-			int uu = upper.Value;
-
-			return new ValueSourceScorerAnonymousInnerClassHelper(this, reader, this, ll, uu);
-		  }
-
-		  private class ValueSourceScorerAnonymousInnerClassHelper : ValueSourceScorer
-		  {
-			  private readonly IntDocValuesAnonymousInnerClassHelper outerInstance;
-
-			  private readonly int ll;
-			  private readonly int uu;
-
-			  public ValueSourceScorerAnonymousInnerClassHelper(IntDocValuesAnonymousInnerClassHelper
outerInstance, IndexReader reader, EnumFieldSource @this, int ll, int uu) : base(reader, @this)
-			  {
-				  this.outerInstance = outerInstance;
-				  this.ll = ll;
-				  this.uu = uu;
-			  }
-
-			  public override bool MatchesValue(int doc)
-			  {
-				int val = outerInstance.arr.Get(doc);
-				// only check for deleted if it's the default value
-				// if (val==0 && reader.isDeleted(doc)) return false;
-				return val >= ll && val <= uu;
-			  }
-		  }
-
-		  public override AbstractValueFiller ValueFiller
-		  {
-			  get
-			  {
-				return new ValueFillerAnonymousInnerClassHelper(this);
-			  }
-		  }
-
-		  private class ValueFillerAnonymousInnerClassHelper : AbstractValueFiller
-		  {
-			  private readonly IntDocValuesAnonymousInnerClassHelper outerInstance;
-
-			  public ValueFillerAnonymousInnerClassHelper(IntDocValuesAnonymousInnerClassHelper outerInstance)
-			  {
-				  this.outerInstance = outerInstance;
-				  mval = new MutableValueInt();
-			  }
-
-			  private readonly MutableValueInt mval;
-
-			  public override MutableValue Value
-			  {
-				  get
-				  {
-					return mval;
-				  }
-			  }
-
-			  public override void FillValue(int doc)
-			  {
-				mval.Value = outerInstance.arr.Get(doc);
-				mval.Exists = outerInstance.valid.Get(doc);
-			  }
-		  }
-	  }
-
-	  public override bool Equals(object o)
-	  {
-		if (this == o)
-		{
-			return true;
-		}
-		if (o == null || this.GetType() != o.GetType())
-		{
-			return false;
-		}
-		if (!base.Equals(o))
-		{
-			return false;
-		}
-
-		EnumFieldSource that = (EnumFieldSource) o;
-
-		if (!enumIntToStringMap.Equals(that.enumIntToStringMap))
-		{
-			return false;
-		}
-		if (!enumStringToIntMap.Equals(that.enumStringToIntMap))
-		{
-			return false;
-		}
-		if (!parser.Equals(that.parser))
-		{
-			return false;
-		}
-
-		return true;
-	  }
-
-	  public override int GetHashCode()
-	  {
-		int result = base.GetHashCode();
-		result = 31 * result + parser.GetHashCode();
-		result = 31 * result + enumIntToStringMap.GetHashCode();
-		result = 31 * result + enumStringToIntMap.GetHashCode();
-		return result;
-	  }
-	}
+        public override FunctionValues GetValues(IDictionary context, AtomicReaderContext
readerContext)
+        {
+            var arr = cache.GetInts(readerContext.AtomicReader, field, parser, true);
+            var valid = cache.GetDocsWithField(readerContext.AtomicReader, field);
+
+            return new IntDocValuesAnonymousInnerClassHelper(this, this, arr, valid);
+        }
+
+        private class IntDocValuesAnonymousInnerClassHelper : IntDocValues
+        {
+            private readonly EnumFieldSource outerInstance;
+
+            private readonly FieldCache.Ints arr;
+            private readonly Bits valid;
+
+            public IntDocValuesAnonymousInnerClassHelper(EnumFieldSource outerInstance, EnumFieldSource
@this, FieldCache.Ints arr, Bits valid)
+                : base(@this)
+            {
+                this.outerInstance = outerInstance;
+                this.arr = arr;
+                this.valid = valid;
+                val = new MutableValueInt();
+            }
+
+            private readonly MutableValueInt val;
+
+            public override float FloatVal(int doc)
+            {
+                return (float)arr.Get(doc);
+            }
+
+            public override int IntVal(int doc)
+            {
+                return arr.Get(doc);
+            }
+
+            public override long LongVal(int doc)
+            {
+                return (long)arr.Get(doc);
+            }
+
+            public override double DoubleVal(int doc)
+            {
+                return (double)arr.Get(doc);
+            }
+
+            public override string StrVal(int doc)
+            {
+                int? intValue = arr.Get(doc);
+                return outerInstance.IntValueToStringValue(intValue);
+            }
+
+            public override object ObjectVal(int doc)
+            {
+                return valid.Get(doc) ? (object)arr.Get(doc) : null;
+            }
+
+            public override bool Exists(int doc)
+            {
+                return valid.Get(doc);
+            }
+
+            public override string ToString(int doc)
+            {
+                return outerInstance.Description + '=' + StrVal(doc);
+            }
+
+
+            public override ValueSourceScorer GetRangeScorer(IndexReader reader, string lowerVal,
string upperVal, bool includeLower, bool includeUpper)
+            {
+                int? lower = outerInstance.StringValueToIntValue(lowerVal);
+                int? upper = outerInstance.StringValueToIntValue(upperVal);
+
+                // instead of using separate comparison functions, adjust the endpoints.
+
+                if (lower == null)
+                {
+                    lower = int.MinValue;
+                }
+                else
+                {
+                    if (!includeLower && lower < int.MaxValue)
+                    {
+                        lower++;
+                    }
+                }
+
+                if (upper == null)
+                {
+                    upper = int.MaxValue;
+                }
+                else
+                {
+                    if (!includeUpper && upper > int.MinValue)
+                    {
+                        upper--;
+                    }
+                }
+
+                int ll = lower.Value;
+                int uu = upper.Value;
+
+                return new ValueSourceScorerAnonymousInnerClassHelper(this, reader, this,
ll, uu);
+            }
+
+            private class ValueSourceScorerAnonymousInnerClassHelper : ValueSourceScorer
+            {
+                private readonly IntDocValuesAnonymousInnerClassHelper outerInstance;
+
+                private readonly int ll;
+                private readonly int uu;
+
+                public ValueSourceScorerAnonymousInnerClassHelper(IntDocValuesAnonymousInnerClassHelper
outerInstance, IndexReader reader, EnumFieldSource @this, int ll, int uu)
+                    : base(reader, @this)
+                {
+                    this.outerInstance = outerInstance;
+                    this.ll = ll;
+                    this.uu = uu;
+                }
+
+                public override bool MatchesValue(int doc)
+                {
+                    int val = outerInstance.arr.Get(doc);
+                    // only check for deleted if it's the default value
+                    // if (val==0 && reader.isDeleted(doc)) return false;
+                    return val >= ll && val <= uu;
+                }
+            }
+
+            public override AbstractValueFiller ValueFiller
+            {
+                get
+                {
+                    return new ValueFillerAnonymousInnerClassHelper(this);
+                }
+            }
+
+            private class ValueFillerAnonymousInnerClassHelper : AbstractValueFiller
+            {
+                private readonly IntDocValuesAnonymousInnerClassHelper outerInstance;
+
+                public ValueFillerAnonymousInnerClassHelper(IntDocValuesAnonymousInnerClassHelper
outerInstance)
+                {
+                    this.outerInstance = outerInstance;
+                    mval = new MutableValueInt();
+                }
+
+                private readonly MutableValueInt mval;
+
+                public override MutableValue Value
+                {
+                    get
+                    {
+                        return mval;
+                    }
+                }
+
+                public override void FillValue(int doc)
+                {
+                    mval.Value = outerInstance.arr.Get(doc);
+                    mval.Exists = outerInstance.valid.Get(doc);
+                }
+            }
+        }
+
+        public override bool Equals(object o)
+        {
+            if (this == o)
+            {
+                return true;
+            }
+            if (o == null || this.GetType() != o.GetType())
+            {
+                return false;
+            }
+            if (!base.Equals(o))
+            {
+                return false;
+            }
+
+            EnumFieldSource that = (EnumFieldSource)o;
+
+            if (!enumIntToStringMap.Equals(that.enumIntToStringMap))
+            {
+                return false;
+            }
+            if (!enumStringToIntMap.Equals(that.enumStringToIntMap))
+            {
+                return false;
+            }
+            if (!parser.Equals(that.parser))
+            {
+                return false;
+            }
+
+            return true;
+        }
+
+        public override int GetHashCode()
+        {
+            int result = base.GetHashCode();
+            result = 31 * result + parser.GetHashCode();
+            result = 31 * result + enumIntToStringMap.GetHashCode();
+            result = 31 * result + enumStringToIntMap.GetHashCode();
+            return result;
+        }
+    }
 
 
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/051b0ef0/src/Lucene.Net.Queries/Function/ValueSources/ScaleFloatFunction.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/ScaleFloatFunction.cs b/src/Lucene.Net.Queries/Function/ValueSources/ScaleFloatFunction.cs
index b3e69b9..0fc40a8 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/ScaleFloatFunction.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/ScaleFloatFunction.cs
@@ -15,6 +15,7 @@
  * limitations under the License.
  */
 using System.Collections;
+using System.Collections.Generic;
 using Lucene.Net.Index;
 using Lucene.Net.Queries.Function.DocValues;
 using Lucene.Net.Search;
@@ -23,30 +24,30 @@ using Lucene.Net.Support;
 namespace Lucene.Net.Queries.Function.ValueSources
 {
     /// <summary>
-	/// Scales values to be between min and max.
-	/// <para>This implementation currently traverses all of the source values to obtain
-	/// their min and max.
-	/// </para>
-	/// <para>This implementation currently cannot distinguish when documents have been
-	/// deleted or documents that have no value, and 0.0 values will be used for
-	/// these cases.  This means that if values are normally all greater than 0.0, one can
-	/// still end up with 0.0 as the min value to map from.  In these cases, an
-	/// appropriate map() function could be used as a workaround to change 0.0
-	/// to a value in the real range.
-	/// </para>
-	/// </summary>
-	public class ScaleFloatFunction : ValueSource
-	{
-	  protected internal readonly ValueSource source;
-	  protected internal readonly float min;
-	  protected internal readonly float max;
-
-	  public ScaleFloatFunction(ValueSource source, float min, float max)
-	  {
-		this.source = source;
-		this.min = min;
-		this.max = max;
-	  }
+    /// Scales values to be between min and max.
+    /// <para>This implementation currently traverses all of the source values to obtain
+    /// their min and max.
+    /// </para>
+    /// <para>This implementation currently cannot distinguish when documents have
been
+    /// deleted or documents that have no value, and 0.0 values will be used for
+    /// these cases.  This means that if values are normally all greater than 0.0, one can
+    /// still end up with 0.0 as the min value to map from.  In these cases, an
+    /// appropriate map() function could be used as a workaround to change 0.0
+    /// to a value in the real range.
+    /// </para>
+    /// </summary>
+    public class ScaleFloatFunction : ValueSource
+    {
+        protected internal readonly ValueSource source;
+        protected internal readonly float min;
+        protected internal readonly float max;
+
+        public ScaleFloatFunction(ValueSource source, float min, float max)
+        {
+            this.source = source;
+            this.min = min;
+            this.max = max;
+        }
 
         public override string Description
         {
@@ -54,122 +55,121 @@ namespace Lucene.Net.Queries.Function.ValueSources
         }
 
         private class ScaleInfo
-	  {
-		internal float minVal;
-		internal float maxVal;
-	  }
-
-	  private ScaleInfo CreateScaleInfo(IDictionary context, AtomicReaderContext readerContext)
-	  {
-		var leaves = ReaderUtil.GetTopLevelContext(readerContext).Leaves;
-
-		float minVal = float.PositiveInfinity;
-		float maxVal = float.NegativeInfinity;
-
-		foreach (AtomicReaderContext leaf in leaves)
-		{
-		  int maxDoc = leaf.Reader.MaxDoc;
-		  FunctionValues vals = source.GetValues(context, leaf);
-		  for (int i = 0; i < maxDoc; i++)
-		  {
-
-		  float val = vals.FloatVal(i);
-		  if ((Number.FloatToRawIntBits(val) & (0xff << 23)) == 0xff << 23)
-		  {
-			// if the exponent in the float is all ones, then this is +Inf, -Inf or NaN
-			// which don't make sense to factor into the scale function
-			continue;
-		  }
-		  if (val < minVal)
-		  {
-			minVal = val;
-		  }
-		  if (val > maxVal)
-		  {
-			maxVal = val;
-		  }
-		  }
-		}
-
-		if (minVal == float.PositiveInfinity)
-		{
-		// must have been an empty index
-		  minVal = maxVal = 0;
-		}
-
-		ScaleInfo scaleInfo = new ScaleInfo();
-		scaleInfo.minVal = minVal;
-		scaleInfo.maxVal = maxVal;
-		context[ScaleFloatFunction.this] = scaleInfo;
-		return scaleInfo;
-	  }
-
-	  public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext)
-	  {
-
-		var scaleInfo = (ScaleInfo)context[ScaleFloatFunction.this];
-		if (scaleInfo == null)
-		{
-		  scaleInfo = CreateScaleInfo(context, readerContext);
-		}
-
-		float scale = (scaleInfo.maxVal - scaleInfo.minVal == 0) ? 0 : (max - min) / (scaleInfo.maxVal
- scaleInfo.minVal);
-		float minSource = scaleInfo.minVal;
-		float maxSource = scaleInfo.maxVal;
-
-		var vals = source.GetValues(context, readerContext);
-		return new FloatDocValuesAnonymousInnerClassHelper(this, this, scale, minSource, maxSource,
vals);
-	  }
-
-	  private class FloatDocValuesAnonymousInnerClassHelper : FloatDocValues
-	  {
-		  private readonly ScaleFloatFunction outerInstance;
-
-		  private readonly float scale;
-		  private readonly float minSource;
-		  private readonly float maxSource;
-		  private readonly FunctionValues vals;
-
-		  public FloatDocValuesAnonymousInnerClassHelper(ScaleFloatFunction outerInstance, ScaleFloatFunction
@this, float scale, float minSource, float maxSource, FunctionValues vals) : base(@this)
-		  {
-			  this.outerInstance = outerInstance;
-			  this.scale = scale;
-			  this.minSource = minSource;
-			  this.maxSource = maxSource;
-			  this.vals = vals;
-		  }
-
-		  public override float FloatVal(int doc)
-		  {
-			return (vals.FloatVal(doc) - minSource) * scale + outerInstance.min;
-		  }
-		  public override string ToString(int doc)
-		  {
-			return "scale(" + vals.ToString(doc) + ",toMin=" + outerInstance.min + ",toMax=" + outerInstance.max
+ ",fromMin=" + minSource + ",fromMax=" + maxSource + ")";
-		  }
-	  }
-
-	  public override void CreateWeight(IDictionary context, IndexSearcher searcher)
-	  {
-		source.CreateWeight(context, searcher);
-	  }
-
-	  public override int GetHashCode()
-	  {
-		int h = Number.FloatToIntBits(min);
-		h = h * 29;
-		h += Number.FloatToIntBits(max);
-		h = h * 29;
-		h += source.GetHashCode();
-		return h;
-	  }
-
-	  public override bool Equals(object o)
-	  {
-		var other = o as ScaleFloatFunction;
-	      if (other == null)
-	          return false;
-		return this.min == other.min && this.max == other.max && this.source.Equals(other.source);
-	  }
-	}
+        {
+            internal float minVal;
+            internal float maxVal;
+        }
+
+        private ScaleInfo CreateScaleInfo(IDictionary context, AtomicReaderContext readerContext)
+        {
+            var leaves = ReaderUtil.GetTopLevelContext(readerContext).Leaves;
+
+            float minVal = float.PositiveInfinity;
+            float maxVal = float.NegativeInfinity;
+
+            foreach (AtomicReaderContext leaf in leaves)
+            {
+                int maxDoc = leaf.Reader.MaxDoc;
+                FunctionValues vals = source.GetValues(context, leaf);
+                for (int i = 0; i < maxDoc; i++)
+                {
+
+                    float val = vals.FloatVal(i);
+                    if ((Number.FloatToRawIntBits(val) & (0xff << 23)) == 0xff
<< 23)
+                    {
+                        // if the exponent in the float is all ones, then this is +Inf, -Inf
or NaN
+                        // which don't make sense to factor into the scale function
+                        continue;
+                    }
+                    if (val < minVal)
+                    {
+                        minVal = val;
+                    }
+                    if (val > maxVal)
+                    {
+                        maxVal = val;
+                    }
+                }
+            }
+
+            if (minVal == float.PositiveInfinity)
+            {
+                // must have been an empty index
+                minVal = maxVal = 0;
+            }
+
+            var scaleInfo = new ScaleInfo { minVal = minVal, maxVal = maxVal };
+            context[this] = scaleInfo;
+            return scaleInfo;
+        }
+
+        public override FunctionValues GetValues(IDictionary context, AtomicReaderContext
readerContext)
+        {
+
+            var scaleInfo = (ScaleInfo)context[this];
+            if (scaleInfo == null)
+            {
+                scaleInfo = CreateScaleInfo(context, readerContext);
+            }
+
+            float scale = (scaleInfo.maxVal - scaleInfo.minVal == 0) ? 0 : (max - min) /
(scaleInfo.maxVal - scaleInfo.minVal);
+            float minSource = scaleInfo.minVal;
+            float maxSource = scaleInfo.maxVal;
+
+            var vals = source.GetValues(context, readerContext);
+            return new FloatDocValuesAnonymousInnerClassHelper(this, this, scale, minSource,
maxSource, vals);
+        }
+
+        private class FloatDocValuesAnonymousInnerClassHelper : FloatDocValues
+        {
+            private readonly ScaleFloatFunction outerInstance;
+
+            private readonly float scale;
+            private readonly float minSource;
+            private readonly float maxSource;
+            private readonly FunctionValues vals;
+
+            public FloatDocValuesAnonymousInnerClassHelper(ScaleFloatFunction outerInstance,
ScaleFloatFunction @this, float scale, float minSource, float maxSource, FunctionValues vals)
+                : base(@this)
+            {
+                this.outerInstance = outerInstance;
+                this.scale = scale;
+                this.minSource = minSource;
+                this.maxSource = maxSource;
+                this.vals = vals;
+            }
+
+            public override float FloatVal(int doc)
+            {
+                return (vals.FloatVal(doc) - minSource) * scale + outerInstance.min;
+            }
+            public override string ToString(int doc)
+            {
+                return "scale(" + vals.ToString(doc) + ",toMin=" + outerInstance.min + ",toMax="
+ outerInstance.max + ",fromMin=" + minSource + ",fromMax=" + maxSource + ")";
+            }
+        }
+
+        public override void CreateWeight(IDictionary context, IndexSearcher searcher)
+        {
+            source.CreateWeight(context, searcher);
+        }
+
+        public override int GetHashCode()
+        {
+            int h = Number.FloatToIntBits(min);
+            h = h * 29;
+            h += Number.FloatToIntBits(max);
+            h = h * 29;
+            h += source.GetHashCode();
+            return h;
+        }
+
+        public override bool Equals(object o)
+        {
+            var other = o as ScaleFloatFunction;
+            if (other == null)
+                return false;
+            return this.min == other.min && this.max == other.max && this.source.Equals(other.source);
+        }
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/051b0ef0/src/Lucene.Net.Queries/Function/ValueSources/TFValueSource.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/TFValueSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/TFValueSource.cs
index a4353a8..4e8efb0 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/TFValueSource.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/TFValueSource.cs
@@ -1,5 +1,6 @@
 ´╗┐using System;
 using System.Collections;
+using System.Collections.Generic;
 using System.IO;
 using Lucene.Net.Index;
 using Lucene.Net.Queries.Function.DocValues;
@@ -10,176 +11,183 @@ using Lucene.Net.Util;
 namespace Lucene.Net.Queries.Function.ValueSources
 {
 
-	/*
-	 * Licensed to the Apache Software Foundation (ASF) under one or more
-	 * contributor license agreements.  See the NOTICE file distributed with
-	 * this work for additional information regarding copyright ownership.
-	 * The ASF licenses this file to You under the Apache License, Version 2.0
-	 * (the "License"); you may not use this file except in compliance with
-	 * the License.  You may obtain a copy of the License at
-	 *
-	 *     http://www.apache.org/licenses/LICENSE-2.0
-	 *
-	 * Unless required by applicable law or agreed to in writing, software
-	 * distributed under the License is distributed on an "AS IS" BASIS,
-	 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-	 * See the License for the specific language governing permissions and
-	 * limitations under the License.
-	 */
+    /*
+     * Licensed to the Apache Software Foundation (ASF) under one or more
+     * contributor license agreements.  See the NOTICE file distributed with
+     * this work for additional information regarding copyright ownership.
+     * The ASF licenses this file to You under the Apache License, Version 2.0
+     * (the "License"); you may not use this file except in compliance with
+     * the License.  You may obtain a copy of the License at
+     *
+     *     http://www.apache.org/licenses/LICENSE-2.0
+     *
+     * Unless required by applicable law or agreed to in writing, software
+     * distributed under the License is distributed on an "AS IS" BASIS,
+     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     * See the License for the specific language governing permissions and
+     * limitations under the License.
+     */
     /// <summary>
-	/// Function that returns <seealso cref="TFIDFSimilarity#tf(float)"/>
-	/// for every document.
-	/// <para>
-	/// Note that the configured Similarity for the field must be
-	/// a subclass of <seealso cref="TFIDFSimilarity"/>
-	/// @lucene.internal 
-	/// </para>
-	/// </summary>
-	public class TFValueSource : TermFreqValueSource
-	{
-	  public TFValueSource(string field, string val, string indexedField, BytesRef indexedBytes)
: base(field, val, indexedField, indexedBytes)
-	  {
-	  }
-
-	  public override string name()
-	  {
-		return "tf";
-	  }
+    /// Function that returns <seealso cref="TFIDFSimilarity#tf(float)"/>
+    /// for every document.
+    /// <para>
+    /// Note that the configured Similarity for the field must be
+    /// a subclass of <seealso cref="TFIDFSimilarity"/>
+    /// @lucene.internal 
+    /// </para>
+    /// </summary>
+    public class TFValueSource : TermFreqValueSource
+    {
+        public TFValueSource(string field, string val, string indexedField, BytesRef indexedBytes)
+            : base(field, val, indexedField, indexedBytes)
+        {
+        }
+
+        public override string Name
+        {
+            get
+            {
+                {
+                    return "tf";
+                }
+            }
+        }
 
         public override FunctionValues GetValues(IDictionary context, AtomicReaderContext
readerContext)
-	  {
-		Fields fields = readerContext.AtomicReader.Fields;
-		Terms terms = fields.Terms(indexedField);
-		IndexSearcher searcher = (IndexSearcher)context["searcher"];
-		TFIDFSimilarity similarity = IDFValueSource.AsTFIDF(searcher.Similarity, indexedField);
-		if (similarity == null)
-		{
-		  throw new System.NotSupportedException("requires a TFIDFSimilarity (such as DefaultSimilarity)");
-		}
-
-		return new FloatDocValuesAnonymousInnerClassHelper(this, this, terms, similarity);
-	  }
-
-	  private class FloatDocValuesAnonymousInnerClassHelper : FloatDocValues
-	  {
-		  private readonly TFValueSource outerInstance;
-
-		  private readonly Terms terms;
-		  private readonly TFIDFSimilarity similarity;
-
-		  public FloatDocValuesAnonymousInnerClassHelper(TFValueSource outerInstance, TFValueSource
@this, Terms terms, TFIDFSimilarity similarity) : base(@this)
-		  {
-			  this.outerInstance = outerInstance;
-			  this.terms = terms;
-			  this.similarity = similarity;
-			  lastDocRequested = -1;
-		  }
-
-	      private DocsEnum docs;
-	      private int atDoc;
-	      private int lastDocRequested;
-
-//JAVA TO C# CONVERTER TODO TASK: Initialization blocks declared within anonymous inner classes
are not converted:
-	//	  {
-	//		  reset();
-	//	  }
-
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: public void reset() throws java.io.IOException
-		  public virtual void Reset()
-		  {
-			// no one should call us for deleted docs?
-
-			if (terms != null)
-			{
-			  TermsEnum termsEnum = terms.Iterator(null);
-			  if (termsEnum.SeekExact(outerInstance.indexedBytes))
-			  {
-				docs = termsEnum.Docs(null, null);
-			  }
-			  else
-			  {
-				docs = null;
-			  }
-			}
-			else
-			{
-			  docs = null;
-			}
-
-			if (docs == null)
-			{
-			  docs = new DocsEnumAnonymousInnerClassHelper(this);
-			}
-			atDoc = -1;
-		  }
-
-		  private class DocsEnumAnonymousInnerClassHelper : DocsEnum
-		  {
-			  private readonly FloatDocValuesAnonymousInnerClassHelper outerInstance;
-
-			  public DocsEnumAnonymousInnerClassHelper(FloatDocValuesAnonymousInnerClassHelper outerInstance)
-			  {
-				  this.outerInstance = outerInstance;
-			  }
-
-			  public override int Freq()
-			  {
-				return 0;
-			  }
-
-			  public override int DocID()
-			  {
-				return DocIdSetIterator.NO_MORE_DOCS;
-			  }
-
-			  public override int NextDoc()
-			  {
-				return DocIdSetIterator.NO_MORE_DOCS;
-			  }
-
-			  public override int Advance(int target)
-			  {
-				return DocIdSetIterator.NO_MORE_DOCS;
-			  }
-
-			  public override long Cost()
-			  {
-				return 0;
-			  }
-		  }
-
-		  public override float FloatVal(int doc)
-		  {
-			try
-			{
-			  if (doc < lastDocRequested)
-			  {
-				// out-of-order access.... reset
-				Reset();
-			  }
-			  lastDocRequested = doc;
-
-			  if (atDoc < doc)
-			  {
-				atDoc = docs.Advance(doc);
-			  }
-
-			  if (atDoc > doc)
-			  {
-				// term doesn't match this document... either because we hit the
-				// end, or because the next doc is after this doc.
-				return similarity.Tf(0);
-			  }
-
-			  // a match!
-			  return similarity.Tf(docs.Freq());
-			}
-			catch (IOException e)
-			{
-			  throw new Exception("caught exception in function " + outerInstance.Description + "
: doc=" + doc, e);
-			}
-		  }
-	  }
-	}
+        {
+            var fields = readerContext.AtomicReader.Fields;
+            var terms = fields.Terms(indexedField);
+            var searcher = (IndexSearcher)context["searcher"];
+            var similarity = IDFValueSource.AsTFIDF(searcher.Similarity, indexedField);
+            if (similarity == null)
+            {
+                throw new System.NotSupportedException("requires a TFIDFSimilarity (such
as DefaultSimilarity)");
+            }
+
+            return new FloatDocValuesAnonymousInnerClassHelper(this, this, terms, similarity);
+        }
+
+        private class FloatDocValuesAnonymousInnerClassHelper : FloatDocValues
+        {
+            private readonly TFValueSource outerInstance;
+
+            private readonly Terms terms;
+            private readonly TFIDFSimilarity similarity;
+
+            public FloatDocValuesAnonymousInnerClassHelper(TFValueSource outerInstance, TFValueSource
@this, Terms terms, TFIDFSimilarity similarity)
+                : base(@this)
+            {
+                this.outerInstance = outerInstance;
+                this.terms = terms;
+                this.similarity = similarity;
+                lastDocRequested = -1;
+            }
+
+            private DocsEnum docs;
+            private int atDoc;
+            private int lastDocRequested;
+
+            //JAVA TO C# CONVERTER TODO TASK: Initialization blocks declared within anonymous
inner classes are not converted:
+            //	  {
+            //		  reset();
+            //	  }
+
+            //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in
.NET:
+            //ORIGINAL LINE: public void reset() throws java.io.IOException
+            public virtual void Reset()
+            {
+                // no one should call us for deleted docs?
+
+                if (terms != null)
+                {
+                    TermsEnum termsEnum = terms.Iterator(null);
+                    if (termsEnum.SeekExact(outerInstance.indexedBytes))
+                    {
+                        docs = termsEnum.Docs(null, null);
+                    }
+                    else
+                    {
+                        docs = null;
+                    }
+                }
+                else
+                {
+                    docs = null;
+                }
+
+                if (docs == null)
+                {
+                    docs = new DocsEnumAnonymousInnerClassHelper(this);
+                }
+                atDoc = -1;
+            }
+
+            private class DocsEnumAnonymousInnerClassHelper : DocsEnum
+            {
+                private readonly FloatDocValuesAnonymousInnerClassHelper outerInstance;
+
+                public DocsEnumAnonymousInnerClassHelper(FloatDocValuesAnonymousInnerClassHelper
outerInstance)
+                {
+                    this.outerInstance = outerInstance;
+                }
+
+                public override int Freq()
+                {
+                    return 0;
+                }
+
+                public override int DocID()
+                {
+                    return DocIdSetIterator.NO_MORE_DOCS;
+                }
+
+                public override int NextDoc()
+                {
+                    return DocIdSetIterator.NO_MORE_DOCS;
+                }
+
+                public override int Advance(int target)
+                {
+                    return DocIdSetIterator.NO_MORE_DOCS;
+                }
+
+                public override long Cost()
+                {
+                    return 0;
+                }
+            }
+
+            public override float FloatVal(int doc)
+            {
+                try
+                {
+                    if (doc < lastDocRequested)
+                    {
+                        // out-of-order access.... reset
+                        Reset();
+                    }
+                    lastDocRequested = doc;
+
+                    if (atDoc < doc)
+                    {
+                        atDoc = docs.Advance(doc);
+                    }
+
+                    if (atDoc > doc)
+                    {
+                        // term doesn't match this document... either because we hit the
+                        // end, or because the next doc is after this doc.
+                        return similarity.Tf(0);
+                    }
+
+                    // a match!
+                    return similarity.Tf(docs.Freq());
+                }
+                catch (IOException e)
+                {
+                    throw new Exception("caught exception in function " + outerInstance.Description
+ " : doc=" + doc, e);
+                }
+            }
+        }
+    }
 }
\ No newline at end of file


Mime
View raw message