You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by sy...@apache.org on 2014/09/22 01:56:43 UTC

[1/4] More work on Lucene.Net.Queries

Repository: lucenenet
Updated Branches:
  refs/heads/master cf1df6bec -> 5506faf0c


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Queries/Function/ValueSources/SimpleBoolFunction.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/SimpleBoolFunction.cs b/src/Lucene.Net.Queries/Function/ValueSources/SimpleBoolFunction.cs
index ea31a26..eab3ac6 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/SimpleBoolFunction.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/SimpleBoolFunction.cs
@@ -15,89 +15,82 @@
  * limitations under the License.
  */
 using System.Collections;
+using Lucene.Net.Index;
 using Lucene.Net.Queries.Function.DocValues;
-using org.apache.lucene.queries.function;
+using Lucene.Net.Search;
 
 namespace Lucene.Net.Queries.Function.ValueSources
 {
     /// <summary>
-	/// <seealso cref="BoolFunction"/> implementation which applies an extendible boolean
-	/// function to the values of a single wrapped <seealso cref="ValueSource"/>.
-	/// 
-	/// Functions this can be used for include whether a field has a value or not,
-	/// or inverting the boolean value of the wrapped ValueSource.
-	/// </summary>
-	public abstract class SimpleBoolFunction : BoolFunction
-	{
-	  protected internal readonly ValueSource source;
+    /// <seealso cref="BoolFunction"/> implementation which applies an extendible boolean
+    /// function to the values of a single wrapped <seealso cref="ValueSource"/>.
+    /// 
+    /// Functions this can be used for include whether a field has a value or not,
+    /// or inverting the boolean value of the wrapped ValueSource.
+    /// </summary>
+    public abstract class SimpleBoolFunction : BoolFunction
+    {
+        protected internal readonly ValueSource source;
 
-	  public SimpleBoolFunction(ValueSource source)
-	  {
-		this.source = source;
-	  }
+        protected SimpleBoolFunction(ValueSource source)
+        {
+            this.source = source;
+        }
 
-	  protected internal abstract string name();
+        protected abstract string Name { get; }
 
-	  protected internal abstract bool func(int doc, FunctionValues vals);
+        protected abstract bool Func(int doc, FunctionValues vals);
 
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: @Override public org.apache.lucene.queries.function.docvalues.BoolDocValues GetValues(java.util.Map context, org.apache.lucene.index.AtomicReaderContext readerContext) throws java.io.IOException
-	  public override BoolDocValues GetValues(IDictionary context, AtomicReaderContext readerContext)
-	  {
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final org.apache.lucene.queries.function.FunctionValues vals = source.GetValues(context, readerContext);
-		FunctionValues vals = source.GetValues(context, readerContext);
-		return new BoolDocValuesAnonymousInnerClassHelper(this, this, vals);
-	  }
+        public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext)
+        {
+            FunctionValues vals = source.GetValues(context, readerContext);
+            return new BoolDocValuesAnonymousInnerClassHelper(this, this, vals);
+        }
 
-	  private class BoolDocValuesAnonymousInnerClassHelper : BoolDocValues
-	  {
-		  private readonly SimpleBoolFunction outerInstance;
+        private class BoolDocValuesAnonymousInnerClassHelper : BoolDocValues
+        {
+            private readonly SimpleBoolFunction outerInstance;
 
-		  private FunctionValues vals;
+            private FunctionValues vals;
 
-		  public BoolDocValuesAnonymousInnerClassHelper(SimpleBoolFunction outerInstance, SimpleBoolFunction this, FunctionValues vals) : base(this)
-		  {
-			  this.outerInstance = outerInstance;
-			  this.vals = vals;
-		  }
+            public BoolDocValuesAnonymousInnerClassHelper(SimpleBoolFunction outerInstance, SimpleBoolFunction @this, FunctionValues vals)
+                : base(@this)
+            {
+                this.outerInstance = outerInstance;
+                this.vals = vals;
+            }
 
-		  public override bool boolVal(int doc)
-		  {
-			return outerInstance.func(doc, vals);
-		  }
-		  public override string ToString(int doc)
-		  {
-			return outerInstance.name() + '(' + vals.ToString(doc) + ')';
-		  }
-	  }
+            public override bool BoolVal(int doc)
+            {
+                return outerInstance.Func(doc, vals);
+            }
+            public override string ToString(int doc)
+            {
+                return outerInstance.Name + '(' + vals.ToString(doc) + ')';
+            }
+        }
 
-	  public override string description()
-	  {
-		return name() + '(' + source.description() + ')';
-	  }
+        public override string Description
+        {
+            get { return Name + '(' + source.Description + ')'; }
+        }
 
-	  public override int GetHashCode()
-	  {
-		return source.GetHashCode() + name().GetHashCode();
-	  }
+        public override int GetHashCode()
+        {
+            return source.GetHashCode() + Name.GetHashCode();
+        }
 
-	  public override bool Equals(object o)
-	  {
-		if (this.GetType() != o.GetType())
-		{
-			return false;
-		}
-		SimpleBoolFunction other = (SimpleBoolFunction)o;
-		return this.source.Equals(other.source);
-	  }
-
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: @Override public void CreateWeight(java.util.Map context, org.apache.lucene.search.IndexSearcher searcher) throws java.io.IOException
-	  public override void CreateWeight(IDictionary context, IndexSearcher searcher)
-	  {
-		source.CreateWeight(context, searcher);
-	  }
-	}
+        public override bool Equals(object o)
+        {
+            var other = o as SimpleBoolFunction;
+            if (other == null)
+                return false;
+            return this.source.Equals(other.source);
+        }
 
+        public override void CreateWeight(IDictionary context, IndexSearcher searcher)
+        {
+            source.CreateWeight(context, searcher);
+        }
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Queries/Function/ValueSources/SimpleFloatFunction.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/SimpleFloatFunction.cs b/src/Lucene.Net.Queries/Function/ValueSources/SimpleFloatFunction.cs
index 31cb1c2..f18a0f1 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/SimpleFloatFunction.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/SimpleFloatFunction.cs
@@ -17,48 +17,47 @@
  */
 using Lucene.Net.Index;
 using Lucene.Net.Queries.Function.DocValues;
-using org.apache.lucene.queries.function;
 
 namespace Lucene.Net.Queries.Function.ValueSources
 {
     /// <summary>
-	/// A simple float function with a single argument
-	/// </summary>
-	 public abstract class SimpleFloatFunction : SingleFunction
-	 {
-	  public SimpleFloatFunction(ValueSource source) : base(source)
-	  {
-	  }
-
-	  protected internal abstract float func(int doc, FunctionValues vals);
-
-	  public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext)
-	  {
-		FunctionValues vals = source.GetValues(context, readerContext);
-		return new FloatDocValuesAnonymousInnerClassHelper(this, this, vals);
-	  }
-
-	  private class FloatDocValuesAnonymousInnerClassHelper : FloatDocValues
-	  {
-		  private readonly SimpleFloatFunction outerInstance;
-
-		  private FunctionValues vals;
-
-		  public FloatDocValuesAnonymousInnerClassHelper(SimpleFloatFunction outerInstance, SimpleFloatFunction this, FunctionValues vals) : base(this)
-		  {
-			  this.outerInstance = outerInstance;
-			  this.vals = vals;
-		  }
-
-		  public override float FloatVal(int doc)
-		  {
-			return outerInstance.func(doc, vals);
-		  }
-		  public override string ToString(int doc)
-		  {
-			return outerInstance.name() + '(' + vals.ToString(doc) + ')';
-		  }
-	  }
-	 }
-
+    /// A simple float function with a single argument
+    /// </summary>
+    public abstract class SimpleFloatFunction : SingleFunction
+    {
+        protected SimpleFloatFunction(ValueSource source)
+            : base(source)
+        {
+        }
+
+        protected abstract float Func(int doc, FunctionValues vals);
+
+        public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext)
+        {
+            FunctionValues vals = source.GetValues(context, readerContext);
+            return new FloatDocValuesAnonymousInnerClassHelper(this, this, vals);
+        }
+
+        private class FloatDocValuesAnonymousInnerClassHelper : FloatDocValues
+        {
+            private readonly SimpleFloatFunction outerInstance;
+            private readonly FunctionValues vals;
+
+            public FloatDocValuesAnonymousInnerClassHelper(SimpleFloatFunction outerInstance, SimpleFloatFunction @this, FunctionValues vals)
+                : base(@this)
+            {
+                this.outerInstance = outerInstance;
+                this.vals = vals;
+            }
+
+            public override float FloatVal(int doc)
+            {
+                return outerInstance.Func(doc, vals);
+            }
+            public override string ToString(int doc)
+            {
+                return outerInstance.Name + '(' + vals.ToString(doc) + ')';
+            }
+        }
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Queries/Function/ValueSources/SingleFunction.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/SingleFunction.cs b/src/Lucene.Net.Queries/Function/ValueSources/SingleFunction.cs
index 51c196d..07cac33 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/SingleFunction.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/SingleFunction.cs
@@ -15,48 +15,45 @@
  * limitations under the License.
  */
 using System.Collections;
+using Lucene.Net.Search;
 
 namespace Lucene.Net.Queries.Function.ValueSources
 {
     /// <summary>
-	/// A function with a single argument
-	/// </summary>
-	 public abstract class SingleFunction : ValueSource
-	 {
-	  protected internal readonly ValueSource source;
+    /// A function with a single argument
+    /// </summary>
+    public abstract class SingleFunction : ValueSource
+    {
+        protected internal readonly ValueSource source;
 
-	  public SingleFunction(ValueSource source)
-	  {
-		this.source = source;
-	  }
+        protected SingleFunction(ValueSource source)
+        {
+            this.source = source;
+        }
 
-	  protected internal abstract string name();
+        protected internal abstract string Name { get; }
 
-	  public override string description()
-	  {
-		return name() + '(' + source.description() + ')';
-	  }
+        public override string Description
+        {
+            get { return Name + '(' + source.Description + ')'; }
+        }
 
-	  public override int GetHashCode()
-	  {
-		return source.GetHashCode() + name().GetHashCode();
-	  }
+        public override int GetHashCode()
+        {
+            return source.GetHashCode() + Name.GetHashCode();
+        }
 
-	  public override bool Equals(object o)
-	  {
-		if (this.GetType() != o.GetType())
-		{
-			return false;
-		}
-		SingleFunction other = (SingleFunction)o;
-		return this.name().Equals(other.name()) && this.source.Equals(other.source);
-	  }
+        public override bool Equals(object o)
+        {
+            var other = o as SingleFunction;
+            if (other == null)
+                return false;
+            return Name.Equals(other.Name) && source.Equals(other.source);
+        }
 
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: @Override public void CreateWeight(java.util.Map context, org.apache.lucene.search.IndexSearcher searcher) throws java.io.IOException
-	  public override void CreateWeight(IDictionary context, IndexSearcher searcher)
-	  {
-		source.CreateWeight(context, searcher);
-	  }
-	 }
+        public override void CreateWeight(IDictionary context, IndexSearcher searcher)
+        {
+            source.CreateWeight(context, searcher);
+        }
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Queries/Function/ValueSources/SumFloatFunction.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/SumFloatFunction.cs b/src/Lucene.Net.Queries/Function/ValueSources/SumFloatFunction.cs
index 35a8274..c4f9b33 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/SumFloatFunction.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/SumFloatFunction.cs
@@ -15,34 +15,29 @@
  * limitations under the License.
  */
 
-using org.apache.lucene.queries.function;
+using System.Linq;
 
 namespace Lucene.Net.Queries.Function.ValueSources
 {
 
 
-	/// <summary>
-	/// <code>SumFloatFunction</code> returns the sum of it's components.
-	/// </summary>
-	public class SumFloatFunction : MultiFloatFunction
-	{
-	  public SumFloatFunction(ValueSource[] sources) : base(sources)
-	  {
-	  }
+    /// <summary>
+    /// <code>SumFloatFunction</code> returns the sum of it's components.
+    /// </summary>
+    public class SumFloatFunction : MultiFloatFunction
+    {
+        public SumFloatFunction(ValueSource[] sources)
+            : base(sources)
+        {
+        }
+        protected override string Name
+        {
+            get { return "sum"; }
+        }
 
-	  protected internal override string name()
-	  {
-		return "sum";
-	  }
-
-	  protected internal override float func(int doc, FunctionValues[] valsArr)
-	  {
-		float val = 0.0f;
-		foreach (FunctionValues vals in valsArr)
-		{
-		  val += vals.FloatVal(doc);
-		}
-		return val;
-	  }
-	}
+        protected override float Func(int doc, FunctionValues[] valsArr)
+        {
+            return valsArr.Sum(vals => vals.FloatVal(doc));
+        }
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Queries/Function/ValueSources/SumTotalTermFreqValueSource.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/SumTotalTermFreqValueSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/SumTotalTermFreqValueSource.cs
index bb5aa41..07cb60d 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/SumTotalTermFreqValueSource.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/SumTotalTermFreqValueSource.cs
@@ -15,110 +15,103 @@
  * limitations under the License.
  */
 using System.Collections;
+using Lucene.Net.Index;
 using Lucene.Net.Queries.Function.DocValues;
-using org.apache.lucene.queries.function;
+using Lucene.Net.Search;
 
 namespace Lucene.Net.Queries.Function.ValueSources
 {
     /// <summary>
-	/// <code>SumTotalTermFreqValueSource</code> returns the number of tokens.
-	/// (sum of term freqs across all documents, across all terms).
-	/// Returns -1 if frequencies were omitted for the field, or if 
-	/// the codec doesn't support this statistic.
-	/// @lucene.internal
-	/// </summary>
-	public class SumTotalTermFreqValueSource : ValueSource
-	{
-	  protected internal readonly string indexedField;
+    /// <code>SumTotalTermFreqValueSource</code> returns the number of tokens.
+    /// (sum of term freqs across all documents, across all terms).
+    /// Returns -1 if frequencies were omitted for the field, or if 
+    /// the codec doesn't support this statistic.
+    /// @lucene.internal
+    /// </summary>
+    public class SumTotalTermFreqValueSource : ValueSource
+    {
+        protected internal readonly string indexedField;
 
-	  public SumTotalTermFreqValueSource(string indexedField)
-	  {
-		this.indexedField = indexedField;
-	  }
+        public SumTotalTermFreqValueSource(string indexedField)
+        {
+            this.indexedField = indexedField;
+        }
 
-	  public virtual string name()
-	  {
-		return "sumtotaltermfreq";
-	  }
+        public virtual string Name
+        {
+            get { return "sumtotaltermfreq"; }
+        }
 
-	  public override string description()
-	  {
-		return name() + '(' + indexedField + ')';
-	  }
+        public override string Description
+        {
+            get { return Name + '(' + indexedField + ')'; }
+        }
 
-//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)
-	  {
-		return (FunctionValues)context[this];
-	  }
+        public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext)
+        {
+            return (FunctionValues)context[this];
+        }
 
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: @Override public void CreateWeight(java.util.Map context, org.apache.lucene.search.IndexSearcher searcher) throws java.io.IOException
-	  public override void CreateWeight(IDictionary context, IndexSearcher searcher)
-	  {
-		long sumTotalTermFreq = 0;
-		foreach (AtomicReaderContext readerContext in searcher.TopReaderContext.leaves())
-		{
-		  Fields fields = readerContext.reader().fields();
-		  if (fields == null)
-		  {
-			  continue;
-		  }
-		  Terms terms = fields.terms(indexedField);
-		  if (terms == null)
-		  {
-			  continue;
-		  }
-		  long v = terms.SumTotalTermFreq;
-		  if (v == -1)
-		  {
-			sumTotalTermFreq = -1;
-			break;
-		  }
-		  else
-		  {
-			sumTotalTermFreq += v;
-		  }
-		}
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final long ttf = sumTotalTermFreq;
-		long ttf = sumTotalTermFreq;
-		context[this] = new LongDocValuesAnonymousInnerClassHelper(this, this, ttf);
-	  }
+        public override void CreateWeight(IDictionary context, IndexSearcher searcher)
+        {
+            long sumTotalTermFreq = 0;
+            foreach (AtomicReaderContext readerContext in searcher.TopReaderContext.Leaves)
+            {
+                Fields fields = readerContext.AtomicReader.Fields;
+                if (fields == null)
+                {
+                    continue;
+                }
+                Terms terms = fields.Terms(indexedField);
+                if (terms == null)
+                {
+                    continue;
+                }
+                long v = terms.SumTotalTermFreq;
+                if (v == -1)
+                {
+                    sumTotalTermFreq = -1;
+                    break;
+                }
+                else
+                {
+                    sumTotalTermFreq += v;
+                }
+            }
+            long ttf = sumTotalTermFreq;
+            context[this] = new LongDocValuesAnonymousInnerClassHelper(this, this, ttf);
+        }
 
-	  private class LongDocValuesAnonymousInnerClassHelper : LongDocValues
-	  {
-		  private readonly SumTotalTermFreqValueSource outerInstance;
+        private class LongDocValuesAnonymousInnerClassHelper : LongDocValues
+        {
+            private readonly SumTotalTermFreqValueSource outerInstance;
 
-		  private long ttf;
+            private long ttf;
 
-		  public LongDocValuesAnonymousInnerClassHelper(SumTotalTermFreqValueSource outerInstance, SumTotalTermFreqValueSource this, long ttf) : base(this)
-		  {
-			  this.outerInstance = outerInstance;
-			  this.ttf = ttf;
-		  }
+            public LongDocValuesAnonymousInnerClassHelper(SumTotalTermFreqValueSource outerInstance, SumTotalTermFreqValueSource @this, long ttf)
+                : base(@this)
+            {
+                this.outerInstance = outerInstance;
+                this.ttf = ttf;
+            }
 
-		  public override long LongVal(int doc)
-		  {
-			return ttf;
-		  }
-	  }
+            public override long LongVal(int doc)
+            {
+                return ttf;
+            }
+        }
 
-	  public override int GetHashCode()
-	  {
-		return this.GetType().GetHashCode() + indexedField.GetHashCode();
-	  }
-
-	  public override bool Equals(object o)
-	  {
-		if (this.GetType() != o.GetType())
-		{
-			return false;
-		}
-		SumTotalTermFreqValueSource other = (SumTotalTermFreqValueSource)o;
-		return this.indexedField.Equals(other.indexedField);
-	  }
-	}
+        public override int GetHashCode()
+        {
+            return this.GetType().GetHashCode() + indexedField.GetHashCode();
+        }
 
+        public override bool Equals(object o)
+        {
+            var other = o as SumTotalTermFreqValueSource;
+            if (other == null)
+                return false;
+            return this.indexedField.Equals(other.indexedField);
+        }
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/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 2240d4d..a4353a8 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/TFValueSource.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/TFValueSource.cs
@@ -6,7 +6,6 @@ using Lucene.Net.Queries.Function.DocValues;
 using Lucene.Net.Search;
 using Lucene.Net.Search.Similarities;
 using Lucene.Net.Util;
-using org.apache.lucene.queries.function;
 
 namespace Lucene.Net.Queries.Function.ValueSources
 {
@@ -65,8 +64,8 @@ namespace Lucene.Net.Queries.Function.ValueSources
 	  {
 		  private readonly TFValueSource outerInstance;
 
-		  private Terms terms;
-		  private TFIDFSimilarity similarity;
+		  private readonly Terms terms;
+		  private readonly TFIDFSimilarity similarity;
 
 		  public FloatDocValuesAnonymousInnerClassHelper(TFValueSource outerInstance, TFValueSource @this, Terms terms, TFIDFSimilarity similarity) : base(@this)
 		  {
@@ -76,9 +75,9 @@ namespace Lucene.Net.Queries.Function.ValueSources
 			  lastDocRequested = -1;
 		  }
 
-		  internal DocsEnum docs;
-		  internal int atDoc;
-		  internal int lastDocRequested;
+	      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:
 	//	  {
@@ -93,8 +92,6 @@ namespace Lucene.Net.Queries.Function.ValueSources
 
 			if (terms != null)
 			{
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final TermsEnum termsEnum = terms.iterator(null);
 			  TermsEnum termsEnum = terms.Iterator(null);
 			  if (termsEnum.SeekExact(outerInstance.indexedBytes))
 			  {
@@ -180,10 +177,9 @@ namespace Lucene.Net.Queries.Function.ValueSources
 			}
 			catch (IOException e)
 			{
-			  throw new Exception("caught exception in function " + outerInstance.description() + " : doc=" + doc, e);
+			  throw new Exception("caught exception in function " + outerInstance.Description + " : doc=" + doc, e);
 			}
 		  }
 	  }
 	}
-
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Queries/Function/ValueSources/TermFreqValueSource.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/TermFreqValueSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/TermFreqValueSource.cs
index 5634e0d..69888e0 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/TermFreqValueSource.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/TermFreqValueSource.cs
@@ -16,165 +16,159 @@
  */
 using System;
 using System.Collections;
+using System.IO;
+using Lucene.Net.Index;
 using Lucene.Net.Queries.Function.DocValues;
-using org.apache.lucene.queries.function;
+using Lucene.Net.Search;
+using Lucene.Net.Util;
 
 namespace Lucene.Net.Queries.Function.ValueSources
 {
     /// <summary>
-	/// Function that returns <seealso cref="DocsEnum#freq()"/> for the
-	/// supplied term in every document.
-	/// <para>
-	/// If the term does not exist in the document, returns 0.
-	/// If frequencies are omitted, returns 1.
-	/// </para>
-	/// </summary>
-	public class TermFreqValueSource : DocFreqValueSource
-	{
-	  public TermFreqValueSource(string field, string val, string indexedField, BytesRef indexedBytes) : base(field, val, indexedField, indexedBytes)
-	  {
-	  }
-
-	  public override string name()
-	  {
-		return "termfreq";
-	  }
-
-//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, AtomicReaderContext readerContext) throws java.io.IOException
-	  public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext)
-	  {
-		Fields fields = readerContext.reader().fields();
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final Terms terms = fields.terms(indexedField);
-		Terms terms = fields.terms(indexedField);
-
-		return new IntDocValuesAnonymousInnerClassHelper(this, this, terms);
-	  }
-
-	  private class IntDocValuesAnonymousInnerClassHelper : IntDocValues
-	  {
-		  private readonly TermFreqValueSource outerInstance;
-
-		  private Terms terms;
-
-		  public IntDocValuesAnonymousInnerClassHelper(TermFreqValueSource outerInstance, TermFreqValueSource this, Terms terms) : base(this)
-		  {
-			  this.outerInstance = outerInstance;
-			  this.terms = terms;
-			  lastDocRequested = -1;
-		  }
-
-		  internal DocsEnum docs;
-		  internal int atDoc;
-		  internal 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)
-			{
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final TermsEnum termsEnum = terms.iterator(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 IntDocValuesAnonymousInnerClassHelper outerInstance;
-
-			  public DocsEnumAnonymousInnerClassHelper(IntDocValuesAnonymousInnerClassHelper 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 int intVal(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 0;
-			  }
-
-			  // a match!
-			  return docs.freq();
-			}
-			catch (IOException e)
-			{
-			  throw new Exception("caught exception in function " + outerInstance.description() + " : doc=" + doc, e);
-			}
-		  }
-	  }
-	}
-
-
-
+    /// Function that returns <seealso cref="DocsEnum#freq()"/> for the
+    /// supplied term in every document.
+    /// <para>
+    /// If the term does not exist in the document, returns 0.
+    /// If frequencies are omitted, returns 1.
+    /// </para>
+    /// </summary>
+    public class TermFreqValueSource : DocFreqValueSource
+    {
+        public TermFreqValueSource(string field, string val, string indexedField, BytesRef indexedBytes)
+            : base(field, val, indexedField, indexedBytes)
+        {
+        }
+
+        public override string Name
+        {
+            get { return "termfreq"; }
+        }
+
+        public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext)
+        {
+            Fields fields = readerContext.AtomicReader.Fields;
+            Terms terms = fields.Terms(indexedField);
+
+            return new IntDocValuesAnonymousInnerClassHelper(this, this, terms);
+        }
+
+        private class IntDocValuesAnonymousInnerClassHelper : IntDocValues
+        {
+            private readonly TermFreqValueSource outerInstance;
+
+            private Terms terms;
+
+            public IntDocValuesAnonymousInnerClassHelper(TermFreqValueSource outerInstance, TermFreqValueSource @this, Terms terms)
+                : base(@this)
+            {
+                this.outerInstance = outerInstance;
+                this.terms = terms;
+                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();
+            //	  }
+
+            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 IntDocValuesAnonymousInnerClassHelper outerInstance;
+
+                public DocsEnumAnonymousInnerClassHelper(IntDocValuesAnonymousInnerClassHelper 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 int IntVal(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 0;
+                    }
+
+                    // a match!
+                    return docs.Freq();
+                }
+                catch (IOException e)
+                {
+                    throw new Exception("caught exception in function " + outerInstance.Description + " : doc=" + doc, e);
+                }
+            }
+        }
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Queries/Function/ValueSources/TotalTermFreqValueSource.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/TotalTermFreqValueSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/TotalTermFreqValueSource.cs
index dce8177..c37f9c7 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/TotalTermFreqValueSource.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/TotalTermFreqValueSource.cs
@@ -15,106 +15,102 @@
  * limitations under the License.
  */
 using System.Collections;
+using Lucene.Net.Index;
 using Lucene.Net.Queries.Function.DocValues;
-using org.apache.lucene.queries.function;
+using Lucene.Net.Search;
+using Lucene.Net.Util;
 
 namespace Lucene.Net.Queries.Function.ValueSources
 {
     /// <summary>
-	/// <code>TotalTermFreqValueSource</code> returns the total term freq 
-	/// (sum of term freqs across all documents).
-	/// Returns -1 if frequencies were omitted for the field, or if 
-	/// the codec doesn't support this statistic.
-	/// @lucene.internal
-	/// </summary>
-	public class TotalTermFreqValueSource : ValueSource
-	{
-	  protected internal readonly string field;
-	  protected internal readonly string indexedField;
-	  protected internal readonly string val;
-	  protected internal readonly BytesRef indexedBytes;
+    /// <code>TotalTermFreqValueSource</code> returns the total term freq 
+    /// (sum of term freqs across all documents).
+    /// Returns -1 if frequencies were omitted for the field, or if 
+    /// the codec doesn't support this statistic.
+    /// @lucene.internal
+    /// </summary>
+    public class TotalTermFreqValueSource : ValueSource
+    {
+        protected readonly string field;
+        protected readonly string indexedField;
+        protected readonly string val;
+        protected readonly BytesRef indexedBytes;
 
-	  public TotalTermFreqValueSource(string field, string val, string indexedField, BytesRef indexedBytes)
-	  {
-		this.field = field;
-		this.val = val;
-		this.indexedField = indexedField;
-		this.indexedBytes = indexedBytes;
-	  }
+        public TotalTermFreqValueSource(string field, string val, string indexedField, BytesRef indexedBytes)
+        {
+            this.field = field;
+            this.val = val;
+            this.indexedField = indexedField;
+            this.indexedBytes = indexedBytes;
+        }
 
-	  public virtual string name()
-	  {
-		return "totaltermfreq";
-	  }
+        public virtual string Name
+        {
+            get { return "totaltermfreq"; }
+        }
 
-	  public override string description()
-	  {
-		return name() + '(' + field + ',' + val + ')';
-	  }
+        public override string Description
+        {
+            get { return Name + '(' + field + ',' + val + ')'; }
+        }
 
-//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)
-	  {
-		return (FunctionValues)context[this];
-	  }
+        public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext)
+        {
+            return (FunctionValues)context[this];
+        }
 
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: @Override public void CreateWeight(java.util.Map context, org.apache.lucene.search.IndexSearcher searcher) throws java.io.IOException
-	  public override void CreateWeight(IDictionary context, IndexSearcher searcher)
-	  {
-		long totalTermFreq = 0;
-		foreach (AtomicReaderContext readerContext in searcher.TopReaderContext.leaves())
-		{
-		  long val = readerContext.reader().totalTermFreq(new Term(indexedField, indexedBytes));
-		  if (val == -1)
-		  {
-			totalTermFreq = -1;
-			break;
-		  }
-		  else
-		  {
-			totalTermFreq += val;
-		  }
-		}
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final long ttf = totalTermFreq;
-		long ttf = totalTermFreq;
-		context[this] = new LongDocValuesAnonymousInnerClassHelper(this, this, ttf);
-	  }
+        public override void CreateWeight(IDictionary context, IndexSearcher searcher)
+        {
+            long totalTermFreq = 0;
+            foreach (var readerContext in searcher.TopReaderContext.Leaves)
+            {
+                long val = readerContext.Reader.TotalTermFreq(new Term(indexedField, indexedBytes));
+                if (val == -1)
+                {
+                    totalTermFreq = -1;
+                    break;
+                }
+                else
+                {
+                    totalTermFreq += val;
+                }
+            }
+            var ttf = totalTermFreq;
+            context[this] = new LongDocValuesAnonymousInnerClassHelper(this, this, ttf);
+        }
 
-	  private class LongDocValuesAnonymousInnerClassHelper : LongDocValues
-	  {
-		  private readonly TotalTermFreqValueSource outerInstance;
+        private class LongDocValuesAnonymousInnerClassHelper : LongDocValues
+        {
+            private readonly TotalTermFreqValueSource outerInstance;
 
-		  private long ttf;
+            private readonly long ttf;
 
-		  public LongDocValuesAnonymousInnerClassHelper(TotalTermFreqValueSource outerInstance, TotalTermFreqValueSource this, long ttf) : base(this)
-		  {
-			  this.outerInstance = outerInstance;
-			  this.ttf = ttf;
-		  }
+            public LongDocValuesAnonymousInnerClassHelper(TotalTermFreqValueSource outerInstance, TotalTermFreqValueSource @this, long ttf)
+                : base(@this)
+            {
+                this.outerInstance = outerInstance;
+                this.ttf = ttf;
+            }
 
-		  public override long LongVal(int doc)
-		  {
-			return ttf;
-		  }
-	  }
+            public override long LongVal(int doc)
+            {
+                return ttf;
+            }
+        }
 
-	  public override int GetHashCode()
-	  {
-		return this.GetType().GetHashCode() + indexedField.GetHashCode() * 29 + indexedBytes.GetHashCode();
-	  }
-
-	  public override bool Equals(object o)
-	  {
-		if (this.GetType() != o.GetType())
-		{
-			return false;
-		}
-		TotalTermFreqValueSource other = (TotalTermFreqValueSource)o;
-		return this.indexedField.Equals(other.indexedField) && this.indexedBytes.Equals(other.indexedBytes);
-	  }
-	}
+        public override int GetHashCode()
+        {
+            return this.GetType().GetHashCode() + indexedField.GetHashCode() * 29 + indexedBytes.GetHashCode();
+        }
 
+        public override bool Equals(object o)
+        {
+            if (this.GetType() != o.GetType())
+            {
+                return false;
+            }
+            var other = (TotalTermFreqValueSource)o;
+            return this.indexedField.Equals(other.indexedField) && this.indexedBytes.Equals(other.indexedBytes);
+        }
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Queries/Function/ValueSources/VectorValueSource.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/VectorValueSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/VectorValueSource.cs
index e859263..fa53603 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/VectorValueSource.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/VectorValueSource.cs
@@ -3,234 +3,223 @@ using System.Collections.Generic;
 using System.Text;
 using Lucene.Net.Index;
 using Lucene.Net.Search;
-using org.apache.lucene.queries.function;
 
 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>
-	/// Converts individual ValueSource instances to leverage the FunctionValues *Val functions that work with multiple values,
-	/// i.e. <seealso cref="FunctionValues#DoubleVal(int, double[])"/>
-	/// </summary>
-	//Not crazy about the name, but...
-	public class VectorValueSource : MultiValueSource
-	{
-	  protected internal readonly IList<ValueSource> sources;
+    /// Converts individual ValueSource instances to leverage the FunctionValues *Val functions that work with multiple values,
+    /// i.e. <seealso cref="FunctionValues#DoubleVal(int, double[])"/>
+    /// </summary>
+    //Not crazy about the name, but...
+    public class VectorValueSource : MultiValueSource
+    {
+        protected internal readonly IList<ValueSource> sources;
 
 
-	  public VectorValueSource(IList<ValueSource> sources)
-	  {
-		this.sources = sources;
-	  }
-
-	  public virtual IList<ValueSource> Sources
-	  {
-		  get
-		  {
-			return sources;
-		  }
-	  }
-
-	  public override int dimension()
-	  {
-		return sources.Count;
-	  }
+        public VectorValueSource(IList<ValueSource> sources)
+        {
+            this.sources = sources;
+        }
 
-	  public virtual string name()
-	  {
-		return "vector";
-	  }
+        public virtual IList<ValueSource> Sources
+        {
+            get
+            {
+                return sources;
+            }
+        }
 
-//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)
-	  {
-		int size = sources.Count;
+        public override int Dimension
+        {
+            get { return sources.Count; }
+        }
 
-		// special-case x,y and lat,lon since it's so common
-		if (size == 2)
-		{
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final org.apache.lucene.queries.function.FunctionValues x = sources.get(0).GetValues(context, readerContext);
-		  FunctionValues x = sources[0].GetValues(context, readerContext);
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final org.apache.lucene.queries.function.FunctionValues y = sources.get(1).GetValues(context, readerContext);
-		  FunctionValues y = sources[1].GetValues(context, readerContext);
-		  return new FunctionValuesAnonymousInnerClassHelper(this, x, y);
-		}
+        public virtual string Name
+        {
+            get { return "vector"; }
+        }
 
+        public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext)
+        {
+            var size = sources.Count;
 
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final org.apache.lucene.queries.function.FunctionValues[] valsArr = new org.apache.lucene.queries.function.FunctionValues[size];
-		FunctionValues[] valsArr = new FunctionValues[size];
-		for (int i = 0; i < size; i++)
-		{
-		  valsArr[i] = sources[i].GetValues(context, readerContext);
-		}
+            // special-case x,y and lat,lon since it's so common
+            if (size == 2)
+            {
+                var x = sources[0].GetValues(context, readerContext);
+                var y = sources[1].GetValues(context, readerContext);
+                return new FunctionValuesAnonymousInnerClassHelper(this, x, y);
+            }
 
-		return new FunctionValuesAnonymousInnerClassHelper2(this, valsArr);
-	  }
+            var valsArr = new FunctionValues[size];
+            for (int i = 0; i < size; i++)
+            {
+                valsArr[i] = sources[i].GetValues(context, readerContext);
+            }
 
-	  private class FunctionValuesAnonymousInnerClassHelper : FunctionValues
-	  {
-		  private readonly VectorValueSource outerInstance;
+            return new FunctionValuesAnonymousInnerClassHelper2(this, valsArr);
+        }
 
-		  private FunctionValues x;
-		  private FunctionValues y;
+        private class FunctionValuesAnonymousInnerClassHelper : FunctionValues
+        {
+            private readonly VectorValueSource outerInstance;
 
-		  public FunctionValuesAnonymousInnerClassHelper(VectorValueSource outerInstance, FunctionValues x, FunctionValues y)
-		  {
-			  this.outerInstance = outerInstance;
-			  this.x = x;
-			  this.y = y;
-		  }
+            private readonly FunctionValues x;
+            private readonly FunctionValues y;
 
-		  public override void ByteVal(int doc, sbyte[] vals)
-		  {
-			vals[0] = x.ByteVal(doc);
-			vals[1] = y.ByteVal(doc);
-		  }
+            public FunctionValuesAnonymousInnerClassHelper(VectorValueSource outerInstance, FunctionValues x, FunctionValues y)
+            {
+                this.outerInstance = outerInstance;
+                this.x = x;
+                this.y = y;
+            }
 
-		  public override void ShortVal(int doc, short[] vals)
-		  {
-			vals[0] = x.ShortVal(doc);
-			vals[1] = y.ShortVal(doc);
-		  }
-		  public override void IntVal(int doc, int[] vals)
-		  {
-			vals[0] = x.IntVal(doc);
-			vals[1] = y.IntVal(doc);
-		  }
-		  public override void LongVal(int doc, long[] vals)
-		  {
-			vals[0] = x.LongVal(doc);
-			vals[1] = y.LongVal(doc);
-		  }
-		  public override void FloatVal(int doc, float[] vals)
-		  {
-			vals[0] = x.FloatVal(doc);
-			vals[1] = y.FloatVal(doc);
-		  }
-		  public override void DoubleVal(int doc, double[] vals)
-		  {
-			vals[0] = x.DoubleVal(doc);
-			vals[1] = y.DoubleVal(doc);
-		  }
-		  public override void StrVal(int doc, string[] vals)
-		  {
-			vals[0] = x.StrVal(doc);
-			vals[1] = y.StrVal(doc);
-		  }
-		  public override string ToString(int doc)
-		  {
-			return outerInstance.name() + "(" + x.ToString(doc) + "," + y.ToString(doc) + ")";
-		  }
-	  }
+            public override void ByteVal(int doc, sbyte[] vals)
+            {
+                vals[0] = x.ByteVal(doc);
+                vals[1] = y.ByteVal(doc);
+            }
 
-	  private class FunctionValuesAnonymousInnerClassHelper2 : FunctionValues
-	  {
-		  private readonly VectorValueSource outerInstance;
+            public override void ShortVal(int doc, short[] vals)
+            {
+                vals[0] = x.ShortVal(doc);
+                vals[1] = y.ShortVal(doc);
+            }
+            public override void IntVal(int doc, int[] vals)
+            {
+                vals[0] = x.IntVal(doc);
+                vals[1] = y.IntVal(doc);
+            }
+            public override void LongVal(int doc, long[] vals)
+            {
+                vals[0] = x.LongVal(doc);
+                vals[1] = y.LongVal(doc);
+            }
+            public override void FloatVal(int doc, float[] vals)
+            {
+                vals[0] = x.FloatVal(doc);
+                vals[1] = y.FloatVal(doc);
+            }
+            public override void DoubleVal(int doc, double[] vals)
+            {
+                vals[0] = x.DoubleVal(doc);
+                vals[1] = y.DoubleVal(doc);
+            }
+            public override void StrVal(int doc, string[] vals)
+            {
+                vals[0] = x.StrVal(doc);
+                vals[1] = y.StrVal(doc);
+            }
+            public override string ToString(int doc)
+            {
+                return outerInstance.Name + "(" + x.ToString(doc) + "," + y.ToString(doc) + ")";
+            }
+        }
 
-		  private FunctionValues[] valsArr;
+        private class FunctionValuesAnonymousInnerClassHelper2 : FunctionValues
+        {
+            private readonly VectorValueSource outerInstance;
+            private readonly FunctionValues[] valsArr;
 
-		  public FunctionValuesAnonymousInnerClassHelper2(VectorValueSource outerInstance, FunctionValues[] valsArr)
-		  {
-			  this.outerInstance = outerInstance;
-			  this.valsArr = valsArr;
-		  }
+            public FunctionValuesAnonymousInnerClassHelper2(VectorValueSource outerInstance, FunctionValues[] valsArr)
+            {
+                this.outerInstance = outerInstance;
+                this.valsArr = valsArr;
+            }
 
-		  public override void ByteVal(int doc, sbyte[] vals)
-		  {
-			for (int i = 0; i < valsArr.Length; i++)
-			{
-			  vals[i] = valsArr[i].ByteVal(doc);
-			}
-		  }
+            public override void ByteVal(int doc, sbyte[] vals)
+            {
+                for (int i = 0; i < valsArr.Length; i++)
+                {
+                    vals[i] = valsArr[i].ByteVal(doc);
+                }
+            }
 
-		  public override void ShortVal(int doc, short[] vals)
-		  {
-			for (int i = 0; i < valsArr.Length; i++)
-			{
-			  vals[i] = valsArr[i].ShortVal(doc);
-			}
-		  }
+            public override void ShortVal(int doc, short[] vals)
+            {
+                for (int i = 0; i < valsArr.Length; i++)
+                {
+                    vals[i] = valsArr[i].ShortVal(doc);
+                }
+            }
 
-		  public override void FloatVal(int doc, float[] vals)
-		  {
-			for (int i = 0; i < valsArr.Length; i++)
-			{
-			  vals[i] = valsArr[i].FloatVal(doc);
-			}
-		  }
+            public override void FloatVal(int doc, float[] vals)
+            {
+                for (int i = 0; i < valsArr.Length; i++)
+                {
+                    vals[i] = valsArr[i].FloatVal(doc);
+                }
+            }
 
-		  public override void IntVal(int doc, int[] vals)
-		  {
-			for (int i = 0; i < valsArr.Length; i++)
-			{
-			  vals[i] = valsArr[i].IntVal(doc);
-			}
-		  }
+            public override void IntVal(int doc, int[] vals)
+            {
+                for (int i = 0; i < valsArr.Length; i++)
+                {
+                    vals[i] = valsArr[i].IntVal(doc);
+                }
+            }
 
-		  public override void LongVal(int doc, long[] vals)
-		  {
-			for (int i = 0; i < valsArr.Length; i++)
-			{
-			  vals[i] = valsArr[i].LongVal(doc);
-			}
-		  }
+            public override void LongVal(int doc, long[] vals)
+            {
+                for (int i = 0; i < valsArr.Length; i++)
+                {
+                    vals[i] = valsArr[i].LongVal(doc);
+                }
+            }
 
-		  public override void DoubleVal(int doc, double[] vals)
-		  {
-			for (int i = 0; i < valsArr.Length; i++)
-			{
-			  vals[i] = valsArr[i].DoubleVal(doc);
-			}
-		  }
+            public override void DoubleVal(int doc, double[] vals)
+            {
+                for (var i = 0; i < valsArr.Length; i++)
+                {
+                    vals[i] = valsArr[i].DoubleVal(doc);
+                }
+            }
 
-		  public override void StrVal(int doc, string[] vals)
-		  {
-			for (int i = 0; i < valsArr.Length; i++)
-			{
-			  vals[i] = valsArr[i].StrVal(doc);
-			}
-		  }
+            public override void StrVal(int doc, string[] vals)
+            {
+                for (var i = 0; i < valsArr.Length; i++)
+                {
+                    vals[i] = valsArr[i].StrVal(doc);
+                }
+            }
 
-		  public override string ToString(int doc)
-		  {
-			StringBuilder sb = new StringBuilder();
-			sb.Append(outerInstance.name()).Append('(');
-			bool firstTime = true;
-			foreach (FunctionValues vals in valsArr)
-			{
-			  if (firstTime)
-			  {
-				firstTime = false;
-			  }
-			  else
-			  {
-				sb.Append(',');
-			  }
-			  sb.Append(vals.ToString(doc));
-			}
-			sb.Append(')');
-			return sb.ToString();
-		  }
-	  }
+            public override string ToString(int doc)
+            {
+                var sb = new StringBuilder();
+                sb.Append(outerInstance.Name).Append('(');
+                bool firstTime = true;
+                foreach (var vals in valsArr)
+                {
+                    if (firstTime)
+                    {
+                        firstTime = false;
+                    }
+                    else
+                    {
+                        sb.Append(',');
+                    }
+                    sb.Append(vals.ToString(doc));
+                }
+                sb.Append(')');
+                return sb.ToString();
+            }
+        }
 
         public override void CreateWeight(IDictionary context, IndexSearcher searcher)
         {
@@ -241,48 +230,48 @@ namespace Lucene.Net.Queries.Function.ValueSources
         }
 
 
-        public override string description()
-	  {
-		StringBuilder sb = new StringBuilder();
-		sb.Append(name()).Append('(');
-		bool firstTime = true;
-		foreach (ValueSource source in sources)
-		{
-		  if (firstTime)
-		  {
-			firstTime = false;
-		  }
-		  else
-		  {
-			sb.Append(',');
-		  }
-		  sb.Append(source);
-		}
-		sb.Append(")");
-		return sb.ToString();
-	  }
-
-	  public override bool Equals(object o)
-	  {
-		if (this == o)
-		{
-			return true;
-		}
-		if (!(o is VectorValueSource))
-		{
-			return false;
-		}
-
-		VectorValueSource that = (VectorValueSource) o;
-
-		return sources.Equals(that.sources);
+        public override string Description
+        {
+            get
+            {
+                var sb = new StringBuilder();
+                sb.Append(Name).Append('(');
+                bool firstTime = true;
+                foreach (ValueSource source in sources)
+                {
+                    if (firstTime)
+                    {
+                        firstTime = false;
+                    }
+                    else
+                    {
+                        sb.Append(',');
+                    }
+                    sb.Append(source);
+                }
+                sb.Append(")");
+                return sb.ToString();
+            }
+        }
 
-	  }
+        public override bool Equals(object o)
+        {
+            if (this == o)
+            {
+                return true;
+            }
+            if (!(o is VectorValueSource))
+            {
+                return false;
+            }
 
-	  public override int GetHashCode()
-	  {
-		return sources.GetHashCode();
-	  }
-	}
+            var that = (VectorValueSource)o;
+            return sources.Equals(that.sources);
+        }
 
+        public override int GetHashCode()
+        {
+            return sources.GetHashCode();
+        }
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Queries/TermsFilter.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/TermsFilter.cs b/src/Lucene.Net.Queries/TermsFilter.cs
index 667cd55..421b056 100644
--- a/src/Lucene.Net.Queries/TermsFilter.cs
+++ b/src/Lucene.Net.Queries/TermsFilter.cs
@@ -70,7 +70,7 @@ namespace Lucene.Net.Queries
 		  {
 			  this.outerInstance = outerInstance;
 			  this.terms = terms;
-			  iter = sort(terms).GetEnumerator();
+			  iter = Sort(terms).GetEnumerator();
 		  }
 
 			// we need to sort for deduplication and to have a common cache key
@@ -163,7 +163,7 @@ namespace Lucene.Net.Queries
 		string currentField;
 		while ((currentTerm = iter.Next()) != null)
 		{
-		  currentField = iter.field();
+		  currentField = iter.Field();
 		  if (currentField == null)
 		  {
 			throw new System.ArgumentException("Field must not be null");


[4/4] git commit: More work on Lucene.Net.Queries

Posted by sy...@apache.org.
More work on Lucene.Net.Queries


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

Branch: refs/heads/master
Commit: 5506faf0c1397018c8f7e24ffcfe4d99823d86b7
Parents: cf1df6b
Author: Itamar Syn-Hershko <it...@code972.com>
Authored: Mon Sep 22 02:55:29 2014 +0300
Committer: Itamar Syn-Hershko <it...@code972.com>
Committed: Mon Sep 22 02:55:29 2014 +0300

----------------------------------------------------------------------
 src/Lucene.Net.Core/Search/Query.cs             |   4 +-
 src/Lucene.Net.Queries/BooleanFilter.cs         |   2 +-
 src/Lucene.Net.Queries/BoostingQuery.cs         | 344 ++++----
 src/Lucene.Net.Queries/CommonTermsQuery.cs      |  21 +-
 src/Lucene.Net.Queries/CustomScoreQuery.cs      | 821 ++++++++++---------
 src/Lucene.Net.Queries/Function/BoostedQuery.cs |  41 +-
 .../Function/FunctionQuery.cs                   |  51 +-
 .../Function/FunctionValues.cs                  |  18 +-
 src/Lucene.Net.Queries/Function/ValueSource.cs  |   7 +-
 .../Function/ValueSources/ByteFieldSource.cs    |   6 +-
 .../ValueSources/BytesRefFieldSource.cs         |   2 +-
 .../ValueSources/DoubleConstValueSource.cs      | 257 +++---
 .../Function/ValueSources/EnumFieldSource.cs    |   8 +-
 .../Function/ValueSources/FloatFieldSource.cs   | 213 +++--
 .../Function/ValueSources/IDFValueSource.cs     |  97 ++-
 .../Function/ValueSources/IfFunction.cs         | 299 ++++---
 .../Function/ValueSources/IntFieldSource.cs     | 294 ++++---
 .../ValueSources/JoinDocFreqValueSource.cs      | 166 ++--
 .../ValueSources/LinearFloatFunction.cs         | 145 ++--
 .../Function/ValueSources/LiteralValueSource.cs | 205 +++--
 .../Function/ValueSources/LongFieldSource.cs    | 301 ++++---
 .../Function/ValueSources/MaxDocValueSource.cs  |  85 +-
 .../Function/ValueSources/MaxFloatFunction.cs   |  57 +-
 .../Function/ValueSources/MinFloatFunction.cs   |  57 +-
 .../Function/ValueSources/MultiBoolFunction.cs  | 236 +++---
 .../Function/ValueSources/MultiFloatFunction.cs | 241 +++---
 .../Function/ValueSources/MultiFunction.cs      |   6 +-
 .../Function/ValueSources/MultiValueSource.cs   |   4 +-
 .../Function/ValueSources/NormValueSource.cs    | 183 ++---
 .../Function/ValueSources/NumDocsValueSource.cs |  60 +-
 .../Function/ValueSources/OrdFieldSource.cs     | 270 +++---
 .../Function/ValueSources/PowFloatFunction.cs   |  49 +-
 .../ValueSources/ProductFloatFunction.cs        |  45 +-
 .../Function/ValueSources/QueryValueSource.cs   | 590 ++++++-------
 .../ValueSources/RangeMapFloatFunction.cs       | 193 +++--
 .../ValueSources/ReciprocalFloatFunction.cs     | 181 ++--
 .../ValueSources/ReverseOrdFieldSource.cs       | 168 ++--
 .../Function/ValueSources/ScaleFloatFunction.cs |  54 +-
 .../Function/ValueSources/ShortFieldSource.cs   | 243 +++---
 .../Function/ValueSources/SimpleBoolFunction.cs | 129 ++-
 .../ValueSources/SimpleFloatFunction.cs         |  79 +-
 .../Function/ValueSources/SingleFunction.cs     |  65 +-
 .../Function/ValueSources/SumFloatFunction.cs   |  43 +-
 .../ValueSources/SumTotalTermFreqValueSource.cs | 173 ++--
 .../Function/ValueSources/TFValueSource.cs      |  16 +-
 .../ValueSources/TermFreqValueSource.cs         | 306 ++++---
 .../ValueSources/TotalTermFreqValueSource.cs    | 168 ++--
 .../Function/ValueSources/VectorValueSource.cs  | 471 ++++++-----
 src/Lucene.Net.Queries/TermsFilter.cs           |   4 +-
 49 files changed, 3633 insertions(+), 3845 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Core/Search/Query.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Search/Query.cs b/src/Lucene.Net.Core/Search/Query.cs
index 8e084ff..6111cba 100644
--- a/src/Lucene.Net.Core/Search/Query.cs
+++ b/src/Lucene.Net.Core/Search/Query.cs
@@ -105,7 +105,7 @@ namespace Lucene.Net.Search
         /// Expert: adds all terms occurring in this query to the terms set. Only
         /// works if this query is in its <seealso cref="#rewrite rewritten"/> form.
         /// </summary>
-        /// <exception cref="UnsupportedOperationException"> if this query is not yet rewritten </exception>
+        /// <exception cref="InvalidOperationException"> if this query is not yet rewritten </exception>
         public virtual void ExtractTerms(ISet<Term> terms)
         {
             // needs to be implemented by query subclasses
@@ -148,7 +148,7 @@ namespace Lucene.Net.Search
             {
                 return false;
             }
-            Query other = (Query)obj;
+            var other = (Query)obj;
             if (Number.FloatToIntBits(boost) != Number.FloatToIntBits(other.boost))
             {
                 return false;

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Queries/BooleanFilter.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/BooleanFilter.cs b/src/Lucene.Net.Queries/BooleanFilter.cs
index 65b6d4e..7136fe1 100644
--- a/src/Lucene.Net.Queries/BooleanFilter.cs
+++ b/src/Lucene.Net.Queries/BooleanFilter.cs
@@ -164,7 +164,7 @@ namespace Lucene.Net.Queries
                 return false;
             }
 
-            BooleanFilter other = (BooleanFilter)obj;
+            var other = (BooleanFilter)obj;
             return clauses.Equals(other.clauses);
         }
 

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Queries/BoostingQuery.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/BoostingQuery.cs b/src/Lucene.Net.Queries/BoostingQuery.cs
index 8212f98..7a73eb5 100644
--- a/src/Lucene.Net.Queries/BoostingQuery.cs
+++ b/src/Lucene.Net.Queries/BoostingQuery.cs
@@ -1,178 +1,172 @@
-namespace org.apache.lucene.queries
-{
+using Lucene.Net.Index;
+using Lucene.Net.Search;
+using Lucene.Net.Support;
 
-	/*
-	 * 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.
-	 */
-
-	using IndexReader = org.apache.lucene.index.IndexReader;
-	using org.apache.lucene.search;
-
-	/// <summary>
-	/// The BoostingQuery class can be used to effectively demote results that match a given query. 
-	/// Unlike the "NOT" clause, this still selects documents that contain undesirable terms, 
-	/// but reduces their overall score:
-	/// 
-	///     Query balancedQuery = new BoostingQuery(positiveQuery, negativeQuery, 0.01f);
-	/// In this scenario the positiveQuery contains the mandatory, desirable criteria which is used to 
-	/// select all matching documents, and the negativeQuery contains the undesirable elements which 
-	/// are simply used to lessen the scores. Documents that match the negativeQuery have their score 
-	/// multiplied by the supplied "boost" parameter, so this should be less than 1 to achieve a 
-	/// demoting effect
-	/// 
-	/// This code was originally made available here: [WWW] http://marc.theaimsgroup.com/?l=lucene-user&m=108058407130459&w=2
-	/// and is documented here: http://wiki.apache.org/lucene-java/CommunityContributions
-	/// </summary>
-	public class BoostingQuery : Query
-	{
-		private readonly float boost; // the amount to boost by
-		private readonly Query match; // query to match
-		private readonly Query context; // boost when matches too
-
-		public BoostingQuery(Query match, Query context, float boost)
-		{
-		  this.match = match;
-		  this.context = context.clone(); // clone before boost
-		  this.boost = boost;
-		  this.context.Boost = 0.0f; // ignore context-only matches
-		}
-
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: @Override public Query rewrite(org.apache.lucene.index.IndexReader reader) throws java.io.IOException
-		public override Query rewrite(IndexReader reader)
-		{
-		  BooleanQuery result = new BooleanQueryAnonymousInnerClassHelper(this);
-
-		  result.add(match, BooleanClause.Occur.MUST);
-		  result.add(context, BooleanClause.Occur.SHOULD);
-
-		  return result;
-		}
-
-		private class BooleanQueryAnonymousInnerClassHelper : BooleanQuery
-		{
-			private readonly BoostingQuery outerInstance;
-
-			public BooleanQueryAnonymousInnerClassHelper(BoostingQuery outerInstance)
-			{
-				this.outerInstance = outerInstance;
-			}
-
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: @Override public Weight CreateWeight(IndexSearcher searcher) throws java.io.IOException
-			public override Weight CreateWeight(IndexSearcher searcher)
-			{
-			  return new BooleanWeightAnonymousInnerClassHelper(this, searcher);
-			}
-
-			private class BooleanWeightAnonymousInnerClassHelper : BooleanWeight
-			{
-				private readonly BooleanQueryAnonymousInnerClassHelper outerInstance;
-
-				public BooleanWeightAnonymousInnerClassHelper(BooleanQueryAnonymousInnerClassHelper outerInstance, IndexSearcher searcher) : base(searcher, false)
-				{
-					this.outerInstance = outerInstance;
-				}
-
-
-				public override float coord(int overlap, int max)
-				{
-				  switch (overlap)
-				  {
-
-				  case 1: // matched only one clause
-					return 1.0f; // use the score as-is
-
-				  case 2: // matched both clauses
-					return outerInstance.outerInstance.boost; // multiply by boost
-
-				  default:
-					return 0.0f;
-
-				  }
-				}
-			}
-		}
-
-		public override int GetHashCode()
-		{
-		  const int prime = 31;
-		  int result = base.GetHashCode();
-		  result = prime * result + Number.FloatToIntBits(boost);
-		  result = prime * result + ((context == null) ? 0 : context.GetHashCode());
-		  result = prime * result + ((match == null) ? 0 : match.GetHashCode());
-		  return result;
-		}
-
-		public override bool Equals(object obj)
-		{
-		  if (this == obj)
-		  {
-			return true;
-		  }
-		  if (obj == null)
-		  {
-			return false;
-		  }
-		  if (this.GetType() != obj.GetType())
-		  {
-			return false;
-		  }
-
-		  if (!base.Equals(obj))
-		  {
-			return false;
-		  }
-
-		  BoostingQuery other = (BoostingQuery) obj;
-		  if (Number.FloatToIntBits(boost) != Number.FloatToIntBits(other.boost))
-		  {
-			return false;
-		  }
-
-		  if (context == null)
-		  {
-			if (other.context != null)
-			{
-			  return false;
-			}
-		  }
-		  else if (!context.Equals(other.context))
-		  {
-			return false;
-		  }
-
-		  if (match == null)
-		  {
-			if (other.match != null)
-			{
-			  return false;
-			}
-		  }
-		  else if (!match.Equals(other.match))
-		  {
-			return false;
-		  }
-		  return true;
-		}
-
-		public override string ToString(string field)
-		{
-		  return match.ToString(field) + "/" + context.ToString(field);
-		}
-	}
+namespace Lucene.Net.Queries
+{
 
+    /*
+     * 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>
+    /// The BoostingQuery class can be used to effectively demote results that match a given query. 
+    /// Unlike the "NOT" clause, this still selects documents that contain undesirable terms, 
+    /// but reduces their overall score:
+    /// 
+    ///     Query balancedQuery = new BoostingQuery(positiveQuery, negativeQuery, 0.01f);
+    /// In this scenario the positiveQuery contains the mandatory, desirable criteria which is used to 
+    /// select all matching documents, and the negativeQuery contains the undesirable elements which 
+    /// are simply used to lessen the scores. Documents that match the negativeQuery have their score 
+    /// multiplied by the supplied "boost" parameter, so this should be less than 1 to achieve a 
+    /// demoting effect
+    /// 
+    /// This code was originally made available here: [WWW] http://marc.theaimsgroup.com/?l=lucene-user&m=108058407130459&w=2
+    /// and is documented here: http://wiki.apache.org/lucene-java/CommunityContributions
+    /// </summary>
+    public class BoostingQuery : Query
+    {
+        private readonly float boost; // the amount to boost by
+        private readonly Query match; // query to match
+        private readonly Query context; // boost when matches too
+
+        public BoostingQuery(Query match, Query context, float boost)
+        {
+            this.match = match;
+            this.context = context.Clone(); // clone before boost
+            this.boost = boost;
+            this.context.Boost = 0.0f; // ignore context-only matches
+        }
+
+        public override Query Rewrite(IndexReader reader)
+        {
+            BooleanQuery result = new BooleanQueryAnonymousInnerClassHelper(this);
+            result.Add(match, BooleanClause.Occur.MUST);
+            result.Add(context, BooleanClause.Occur.SHOULD);
+            return result;
+        }
+
+        private class BooleanQueryAnonymousInnerClassHelper : BooleanQuery
+        {
+            private readonly BoostingQuery outerInstance;
+
+            public BooleanQueryAnonymousInnerClassHelper(BoostingQuery outerInstance)
+            {
+                this.outerInstance = outerInstance;
+            }
+
+            public override Weight CreateWeight(IndexSearcher searcher)
+            {
+                return new BooleanWeightAnonymousInnerClassHelper(this, searcher);
+            }
+
+            private class BooleanWeightAnonymousInnerClassHelper : BooleanWeight
+            {
+                private readonly BooleanQueryAnonymousInnerClassHelper outerInstance;
+
+                public BooleanWeightAnonymousInnerClassHelper(BooleanQueryAnonymousInnerClassHelper outerInstance, IndexSearcher searcher)
+                    : base(searcher, false)
+                {
+                    this.outerInstance = outerInstance;
+                }
+
+                public override float Coord(int overlap, int max)
+                {
+                    switch (overlap)
+                    {
+
+                        case 1: // matched only one clause
+                            return 1.0f; // use the score as-is
+
+                        case 2: // matched both clauses
+                            return outerInstance.outerInstance.boost; // multiply by boost
+
+                        default:
+                            return 0.0f;
+
+                    }
+                }
+            }
+        }
+
+        public override int GetHashCode()
+        {
+            const int prime = 31;
+            int result = base.GetHashCode();
+            result = prime * result + Number.FloatToIntBits(boost);
+            result = prime * result + ((context == null) ? 0 : context.GetHashCode());
+            result = prime * result + ((match == null) ? 0 : match.GetHashCode());
+            return result;
+        }
+
+        public override bool Equals(object obj)
+        {
+            if (this == obj)
+            {
+                return true;
+            }
+            if (obj == null)
+            {
+                return false;
+            }
+            if (this.GetType() != obj.GetType())
+            {
+                return false;
+            }
+
+            if (!base.Equals(obj))
+            {
+                return false;
+            }
+
+            var other = (BoostingQuery)obj;
+            if (Number.FloatToIntBits(boost) != Number.FloatToIntBits(other.boost))
+            {
+                return false;
+            }
+
+            if (context == null)
+            {
+                if (other.context != null)
+                {
+                    return false;
+                }
+            }
+            else if (!context.Equals(other.context))
+            {
+                return false;
+            }
+
+            if (match == null)
+            {
+                if (other.match != null)
+                {
+                    return false;
+                }
+            }
+            else if (!match.Equals(other.match))
+            {
+                return false;
+            }
+            return true;
+        }
+
+        public override string ToString(string field)
+        {
+            return match.ToString(field) + "/" + context.ToString(field);
+        }
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Queries/CommonTermsQuery.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/CommonTermsQuery.cs b/src/Lucene.Net.Queries/CommonTermsQuery.cs
index 70f093d..a31f248 100644
--- a/src/Lucene.Net.Queries/CommonTermsQuery.cs
+++ b/src/Lucene.Net.Queries/CommonTermsQuery.cs
@@ -67,7 +67,7 @@ namespace Lucene.Net.Queries
         protected internal readonly BooleanClause.Occur highFreqOccur;
         protected internal float lowFreqBoost = 1.0f;
         protected internal float highFreqBoost = 1.0f;
-       
+
 
         /// <summary>
         /// Creates a new <seealso cref="CommonTermsQuery"/>
@@ -174,16 +174,15 @@ namespace Lucene.Net.Queries
             {
                 return (int)minNrShouldMatch;
             }
-            return Math.Round(minNrShouldMatch * numOptional);
+            return (int)Math.Round(minNrShouldMatch * numOptional);
         }
 
-         protected internal virtual Query BuildQuery(int maxDoc, TermContext[] contextArray, Term[] queryTerms)
+        protected internal virtual Query BuildQuery(int maxDoc, TermContext[] contextArray, Term[] queryTerms)
         {
-            BooleanQuery lowFreq = new BooleanQuery(disableCoord);
-            BooleanQuery highFreq = new BooleanQuery(disableCoord);
-            highFreq.Boost = highFreqBoost;
+            var lowFreq = new BooleanQuery(disableCoord);
+            var highFreq = new BooleanQuery(disableCoord) { Boost = highFreqBoost };
             lowFreq.Boost = lowFreqBoost;
-            BooleanQuery query = new BooleanQuery(true);
+            var query = new BooleanQuery(true);
             for (int i = 0; i < queryTerms.Length; i++)
             {
                 TermContext termContext = contextArray[i];
@@ -230,7 +229,7 @@ namespace Lucene.Net.Queries
                 {
                     foreach (BooleanClause booleanClause in highFreq)
                     {
-                        booleanClause.Occur = BooleanClause.Occur.MUST;
+                        booleanClause.Occur_ = BooleanClause.Occur.MUST;
                     }
                 }
                 highFreq.Boost = Boost;
@@ -347,14 +346,14 @@ namespace Lucene.Net.Queries
         public float HighFreqMinimumNumberShouldMatch { get; set; }
 
 
-        public override void ExtractTerms(HashSet<Term> terms)
+        public override void ExtractTerms(ISet<Term> terms)
         {
             terms.AddAll(this.terms);
         }
 
         public override string ToString(string field)
         {
-            StringBuilder buffer = new StringBuilder();
+            var buffer = new StringBuilder();
             bool needParens = (Boost != 1.0) || (LowFreqMinimumNumberShouldMatch > 0);
             if (needParens)
             {
@@ -419,7 +418,7 @@ namespace Lucene.Net.Queries
             {
                 return false;
             }
-            CommonTermsQuery other = (CommonTermsQuery)obj;
+            var other = (CommonTermsQuery)obj;
             if (disableCoord != other.disableCoord)
             {
                 return false;

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Queries/CustomScoreQuery.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/CustomScoreQuery.cs b/src/Lucene.Net.Queries/CustomScoreQuery.cs
index 016b87c..770422b 100644
--- a/src/Lucene.Net.Queries/CustomScoreQuery.cs
+++ b/src/Lucene.Net.Queries/CustomScoreQuery.cs
@@ -25,415 +25,416 @@ namespace Lucene.Net.Queries
 	 * See the License for the specific language governing permissions and
 	 * limitations under the License.
 	 */
-    /// <summary>
-	/// Query that sets document score as a programmatic function of several (sub) scores:
-	/// <ol>
-	///    <li>the score of its subQuery (any query)</li>
-	///    <li>(optional) the score of its <seealso cref="FunctionQuery"/> (or queries).</li>
-	/// </ol>
-	/// Subclasses can modify the computation by overriding <seealso cref="#getCustomScoreProvider"/>.
-	/// 
-	/// @lucene.experimental
-	/// </summary>
-	public class CustomScoreQuery : Query
-	{
-
-	  private Query subQuery;
-	  private Query[] scoringQueries; // never null (empty array if there are no valSrcQueries).
-	  private bool strict = false; // if true, valueSource part of query does not take part in weights normalization.
-
-	  /// <summary>
-	  /// Create a CustomScoreQuery over input subQuery. </summary>
-	  /// <param name="subQuery"> the sub query whose scored is being customized. Must not be null.  </param>
-	  public CustomScoreQuery(Query subQuery) : this(subQuery, new FunctionQuery[0])
-	  {
-	  }
-
-	  /// <summary>
-	  /// Create a CustomScoreQuery over input subQuery and a <seealso cref="FunctionQuery"/>. </summary>
-	  /// <param name="subQuery"> the sub query whose score is being customized. Must not be null. </param>
-	  /// <param name="scoringQuery"> a value source query whose scores are used in the custom score
-	  /// computation.  This parameter is optional - it can be null. </param>
-	  public CustomScoreQuery(Query subQuery, FunctionQuery scoringQuery) : this(subQuery, scoringQuery != null ? new FunctionQuery[] {scoringQuery} : new FunctionQuery[0]) // don't want an array that contains a single null..
-	  {
-	  }
-
-	  /// <summary>
-	  /// Create a CustomScoreQuery over input subQuery and a <seealso cref="FunctionQuery"/>. </summary>
-	  /// <param name="subQuery"> the sub query whose score is being customized. Must not be null. </param>
-	  /// <param name="scoringQueries"> value source queries whose scores are used in the custom score
-	  /// computation.  This parameter is optional - it can be null or even an empty array. </param>
-	  public CustomScoreQuery(Query subQuery, params FunctionQuery[] scoringQueries)
-	  {
-		this.subQuery = subQuery;
-		this.scoringQueries = scoringQueries != null? scoringQueries : new Query[0];
-		if (subQuery == null)
-		{
-			throw new System.ArgumentException("<subquery> must not be null!");
-		}
-	  }
-
-	  /*(non-Javadoc) @see org.apache.lucene.search.Query#rewrite(org.apache.lucene.index.IndexReader) */
-	  public override Query Rewrite(IndexReader reader)
-	  {
-		CustomScoreQuery clone = null;
-
-		Query sq = subQuery.Rewrite(reader);
-		if (sq != subQuery)
-		{
-		  clone = Clone();
-		  clone.subQuery = sq;
-		}
-
-		for (int i = 0; i < scoringQueries.Length; i++)
-		{
-		  Query v = scoringQueries[i].Rewrite(reader);
-		  if (v != scoringQueries[i])
-		  {
-			if (clone == null)
-			{
-				clone = Clone();
-			}
-			clone.scoringQueries[i] = v;
-		  }
-		}
-
-		return clone ?? this;
-	  }
-
-	  /*(non-Javadoc) @see org.apache.lucene.search.Query#extractTerms(java.util.Set) */
-	  public override void ExtractTerms(HashSet<Term> terms)
-	  {
-		subQuery.ExtractTerms(terms);
-		foreach (Query scoringQuery in scoringQueries)
-		{
-		  scoringQuery.ExtractTerms(terms);
-		}
-	  }
-
-	  /*(non-Javadoc) @see org.apache.lucene.search.Query#clone() */
-	  public override CustomScoreQuery Clone()
-	  {
-		CustomScoreQuery clone = (CustomScoreQuery)base.Clone();
-		clone.subQuery = subQuery.Clone();
-		clone.scoringQueries = new Query[scoringQueries.Length];
-		for (int i = 0; i < scoringQueries.Length; i++)
-		{
-		  clone.scoringQueries[i] = scoringQueries[i].Clone();
-		}
-		return clone;
-	  }
-
-	  /* (non-Javadoc) @see org.apache.lucene.search.Query#toString(java.lang.String) */
-	  public override string ToString(string field)
-	  {
-		StringBuilder sb = (new StringBuilder(name())).Append("(");
-		sb.Append(subQuery.ToString(field));
-		foreach (Query scoringQuery in scoringQueries)
-		{
-		  sb.Append(", ").Append(scoringQuery.ToString(field));
-		}
-		sb.Append(")");
-		sb.Append(strict?" STRICT" : "");
-		return sb.ToString() + ToStringUtils.Boost(Boost);
-	  }
-
-	  /// <summary>
-	  /// Returns true if <code>o</code> is equal to this. </summary>
-	  public override bool Equals(object o)
-	  {
-		if (this == o)
-		{
-		  return true;
-		}
-		if (!base.Equals(o))
-		{
-		  return false;
-		}
-		if (this.GetType() != o.GetType())
-		{
-		  return false;
-		}
-		CustomScoreQuery other = (CustomScoreQuery)o;
-		if (this.Boost != other.Boost || !this.subQuery.Equals(other.subQuery) || this.strict != other.strict || this.scoringQueries.Length != other.scoringQueries.Length)
-		{
-		  return false;
-		}
-		return Arrays.Equals(scoringQueries, other.scoringQueries);
-	  }
-
-	  /// <summary>
-	  /// Returns a hash code value for this object. </summary>
-	  public override int GetHashCode()
-	  {
-		return (this.GetType().GetHashCode() + subQuery.GetHashCode() + Arrays.GetHashCode(scoringQueries)) ^ Number.FloatToIntBits(Boost) ^ (strict ? 1234 : 4321);
-	  }
-
-	  /// <summary>
-	  /// Returns a <seealso cref="CustomScoreProvider"/> that calculates the custom scores
-	  /// for the given <seealso cref="IndexReader"/>. The default implementation returns a default
-	  /// implementation as specified in the docs of <seealso cref="CustomScoreProvider"/>.
-	  /// @since 2.9.2
-	  /// </summary>
-	  protected internal virtual CustomScoreProvider GetCustomScoreProvider(AtomicReaderContext context)
-	  {
-		return new CustomScoreProvider(context);
-	  }
-
-	  //=========================== W E I G H T ============================
-
-	  private class CustomWeight : Weight
-	  {
-		  private readonly CustomScoreQuery outerInstance;
-
-		internal Weight subQueryWeight;
-		internal Weight[] valSrcWeights;
-		internal bool qStrict;
-		internal float queryWeight;
-
-		public CustomWeight(CustomScoreQuery outerInstance, IndexSearcher searcher)
-		{
-			this.outerInstance = outerInstance;
-		  this.subQueryWeight = outerInstance.subQuery.CreateWeight(searcher);
-		  this.valSrcWeights = new Weight[outerInstance.scoringQueries.Length];
-		  for (int i = 0; i < outerInstance.scoringQueries.Length; i++)
-		  {
-			this.valSrcWeights[i] = outerInstance.scoringQueries[i].CreateWeight(searcher);
-		  }
-		  this.qStrict = outerInstance.strict;
-		}
-
-		/*(non-Javadoc) @see org.apache.lucene.search.Weight#getQuery() */
-		public override Query Query
-		{
-			get
-			{
-			  return outerInstance;
-			}
-		}
-
-		public override float ValueForNormalization
-		{
-			get
-			{
-			  float sum = subQueryWeight.ValueForNormalization;
-			  foreach (Weight valSrcWeight in valSrcWeights)
-			  {
-				if (qStrict)
-				{
-				  valSrcWeight.ValueForNormalization; // do not include ValueSource part in the query normalization
-				}
-				else
-				{
-				  sum += valSrcWeight.ValueForNormalization;
-				}
-			  }
-			  return sum;
-			}
-		}
-
-		/*(non-Javadoc) @see org.apache.lucene.search.Weight#normalize(float) */
-		public override void Normalize(float norm, float topLevelBoost)
-		{
-		  // note we DONT incorporate our boost, nor pass down any topLevelBoost 
-		  // (e.g. from outer BQ), as there is no guarantee that the CustomScoreProvider's 
-		  // function obeys the distributive law... it might call sqrt() on the subQuery score
-		  // or some other arbitrary function other than multiplication.
-		  // so, instead boosts are applied directly in score()
-		  subQueryWeight.Normalize(norm, 1f);
-		  foreach (Weight valSrcWeight in valSrcWeights)
-		  {
-			if (qStrict)
-			{
-			  valSrcWeight.Normalize(1, 1); // do not normalize the ValueSource part
-			}
-			else
-			{
-			  valSrcWeight.Normalize(norm, 1f);
-			}
-		  }
-		  queryWeight = topLevelBoost * Boost;
-		}
-
-		public override Scorer Scorer(AtomicReaderContext context, Bits acceptDocs)
-		{
-		  Scorer subQueryScorer = subQueryWeight.Scorer(context, acceptDocs);
-		  if (subQueryScorer == null)
-		  {
-			return null;
-		  }
-		  Scorer[] valSrcScorers = new Scorer[valSrcWeights.Length];
-		  for (int i = 0; i < valSrcScorers.Length; i++)
-		  {
-			 valSrcScorers[i] = valSrcWeights[i].Scorer(context, acceptDocs);
-		  }
-		  return new CustomScorer(outerInstance, outerInstance.GetCustomScoreProvider(context), this, queryWeight, subQueryScorer, valSrcScorers);
-		}
-
-	      public override Explanation Explain(AtomicReaderContext context, int doc)
-	      {
-	          Explanation explain = DoExplain(context, doc);
-	          return explain ?? new Explanation(0.0f, "no matching docs");
-	      }
-
-		internal virtual Explanation DoExplain(AtomicReaderContext info, int doc)
-		{
-		  Explanation subQueryExpl = subQueryWeight.Explain(info, doc);
-		  if (!subQueryExpl.Match)
-		  {
-			return subQueryExpl;
-		  }
-		  // match
-		  Explanation[] valSrcExpls = new Explanation[valSrcWeights.Length];
-		  for (int i = 0; i < valSrcWeights.Length; i++)
-		  {
-			valSrcExpls[i] = valSrcWeights[i].Explain(info, doc);
-		  }
-		  Explanation customExp = outerInstance.GetCustomScoreProvider(info).CustomExplain(doc,subQueryExpl,valSrcExpls);
-		  float sc = Boost * customExp.Value;
-		  Explanation res = new ComplexExplanation(true, sc, outerInstance.ToString() + ", product of:");
-		  res.AddDetail(customExp);
-		  res.AddDetail(new Explanation(Boost, "queryBoost")); // actually using the q boost as q weight (== weight value)
-		  return res;
-		}
-
-		public override bool ScoresDocsOutOfOrder()
-		{
-		  return false;
-		}
-	  
-
-
-	  //=========================== S C O R E R ============================
-
-	  /// <summary>
-	  /// A scorer that applies a (callback) function on scores of the subQuery.
-	  /// </summary>
-	  private class CustomScorer : Scorer
-	  {
-		  private readonly CustomScoreQuery outerInstance;
-
-		internal readonly float qWeight;
-		internal readonly Scorer subQueryScorer;
-		internal readonly Scorer[] valSrcScorers;
-		internal readonly CustomScoreProvider provider;
-		internal readonly float[] vScores; // reused in score() to avoid allocating this array for each doc
-
-		// constructor
-		internal CustomScorer(CustomScoreQuery outerInstance, CustomScoreProvider provider, CustomWeight w, float qWeight, Scorer subQueryScorer, Scorer[] valSrcScorers) : base(w)
-		{
-			this.outerInstance = outerInstance;
-		  this.qWeight = qWeight;
-		  this.subQueryScorer = subQueryScorer;
-		  this.valSrcScorers = valSrcScorers;
-		  this.vScores = new float[valSrcScorers.Length];
-		  this.provider = provider;
-		}
-
-		public override int NextDoc()
-		{
-		  int doc = subQueryScorer.NextDoc();
-		  if (doc != NO_MORE_DOCS)
-		  {
-			foreach (Scorer valSrcScorer in valSrcScorers)
-			{
-			  valSrcScorer.Advance(doc);
-			}
-		  }
-		  return doc;
-		}
-
-		public override int DocID()
-		{
-		  return subQueryScorer.DocID();
-		}
-
-		/*(non-Javadoc) @see org.apache.lucene.search.Scorer#score() */
-		public override float Score()
-		{
-		  for (int i = 0; i < valSrcScorers.Length; i++)
-		  {
-			vScores[i] = valSrcScorers[i].Score();
-		  }
-		  return qWeight * provider.customScore(subQueryScorer.docID(), subQueryScorer.score(), vScores);
-		}
-
-		public override int Freq()
-		{
-		  return subQueryScorer.Freq();
-		}
-
-		public override ICollection<ChildScorer> Children
-		{
-			get
-			{
-			  return Collections.Singleton(new ChildScorer(subQueryScorer, "CUSTOM"));
-			}
-		}
-
-		public override int Advance(int target)
-		{
-		  int doc = subQueryScorer.Advance(target);
-		  if (doc != NO_MORE_DOCS)
-		  {
-			foreach (Scorer valSrcScorer in valSrcScorers)
-			{
-			  valSrcScorer.Advance(doc);
-			}
-		  }
-		  return doc;
-		}
-
-		public override long Cost()
-		{
-		  return subQueryScorer.Cost();
-		}
-	  }
-
-	  public override Weight CreateWeight(IndexSearcher searcher)
-	  {
-		return new CustomWeight(this, searcher);
-	  }
-
-	  /// <summary>
-	  /// Checks if this is strict custom scoring.
-	  /// In strict custom scoring, the <seealso cref="ValueSource"/> part does not participate in weight normalization.
-	  /// This may be useful when one wants full control over how scores are modified, and does 
-	  /// not care about normalizing by the <seealso cref="ValueSource"/> part.
-	  /// One particular case where this is useful if for testing this query.   
-	  /// <P>
-	  /// Note: only has effect when the <seealso cref="ValueSource"/> part is not null.
-	  /// </summary>
-	  public virtual bool Strict { get; set; }
-
-
-	  /// <summary>
-	  /// The sub-query that CustomScoreQuery wraps, affecting both the score and which documents match. </summary>
-	  public virtual Query SubQuery
-	  {
-		  get
-		  {
-			return subQuery;
-		  }
-	  }
-
-	  /// <summary>
-	  /// The scoring queries that only affect the score of CustomScoreQuery. </summary>
-	  public virtual Query[] ScoringQueries
-	  {
-		  get
-		  {
-			return scoringQueries;
-		  }
-	  }
-
-	      /// <summary>
-	      /// A short name of this query, used in <seealso cref="#toString(String)"/>.
-	      /// </summary>
-	      public virtual string Name
-	      {
-	          get { return "custom"; }
-	      }
-	  }
 
+    /// <summary>
+    /// Query that sets document score as a programmatic function of several (sub) scores:
+    /// <ol>
+    ///    <li>the score of its subQuery (any query)</li>
+    ///    <li>(optional) the score of its <seealso cref="FunctionQuery"/> (or queries).</li>
+    /// </ol>
+    /// Subclasses can modify the computation by overriding <seealso cref="#getCustomScoreProvider"/>.
+    /// 
+    /// @lucene.experimental
+    /// </summary>
+    public class CustomScoreQuery : Query
+    {
+
+        private Query subQuery;
+        private Query[] scoringQueries; // never null (empty array if there are no valSrcQueries).
+        private bool strict = false; // if true, valueSource part of query does not take part in weights normalization.
+
+        /// <summary>
+        /// Create a CustomScoreQuery over input subQuery. </summary>
+        /// <param name="subQuery"> the sub query whose scored is being customized. Must not be null.  </param>
+        public CustomScoreQuery(Query subQuery) : this(subQuery, new FunctionQuery[0])
+        {
+        }
+
+        /// <summary>
+        /// Create a CustomScoreQuery over input subQuery and a <seealso cref="FunctionQuery"/>. </summary>
+        /// <param name="subQuery"> the sub query whose score is being customized. Must not be null. </param>
+        /// <param name="scoringQuery"> a value source query whose scores are used in the custom score
+        /// computation.  This parameter is optional - it can be null. </param>
+        public CustomScoreQuery(Query subQuery, FunctionQuery scoringQuery)
+            : this(subQuery, scoringQuery != null ? new FunctionQuery[] {scoringQuery} : new FunctionQuery[0])
+            // don't want an array that contains a single null..
+        {
+        }
+
+        /// <summary>
+        /// Create a CustomScoreQuery over input subQuery and a <seealso cref="FunctionQuery"/>. </summary>
+        /// <param name="subQuery"> the sub query whose score is being customized. Must not be null. </param>
+        /// <param name="scoringQueries"> value source queries whose scores are used in the custom score
+        /// computation.  This parameter is optional - it can be null or even an empty array. </param>
+        public CustomScoreQuery(Query subQuery, params FunctionQuery[] scoringQueries)
+        {
+            this.subQuery = subQuery;
+            this.scoringQueries = scoringQueries != null ? scoringQueries : new Query[0];
+            if (subQuery == null)
+            {
+                throw new System.ArgumentException("<subquery> must not be null!");
+            }
+        }
+
+        public override Query Rewrite(IndexReader reader)
+        {
+            CustomScoreQuery clone = null;
+
+            Query sq = subQuery.Rewrite(reader);
+            if (sq != subQuery)
+            {
+                clone = Clone();
+                clone.subQuery = sq;
+            }
+
+            for (int i = 0; i < scoringQueries.Length; i++)
+            {
+                Query v = scoringQueries[i].Rewrite(reader);
+                if (v != scoringQueries[i])
+                {
+                    if (clone == null)
+                    {
+                        clone = Clone();
+                    }
+                    clone.scoringQueries[i] = v;
+                }
+            }
+
+            return clone ?? this;
+        }
+
+        public override void ExtractTerms(ISet<Term> terms)
+        {
+            subQuery.ExtractTerms(terms);
+            foreach (Query scoringQuery in scoringQueries)
+            {
+                scoringQuery.ExtractTerms(terms);
+            }
+        }
+
+        /*(non-Javadoc) @see org.apache.lucene.search.Query#clone() */
+
+        public override CustomScoreQuery Clone()
+        {
+            CustomScoreQuery clone = (CustomScoreQuery) base.Clone();
+            clone.subQuery = subQuery.Clone();
+            clone.scoringQueries = new Query[scoringQueries.Length];
+            for (int i = 0; i < scoringQueries.Length; i++)
+            {
+                clone.scoringQueries[i] = scoringQueries[i].Clone();
+            }
+            return clone;
+        }
+
+        /* (non-Javadoc) @see org.apache.lucene.search.Query#toString(java.lang.String) */
+
+        public override string ToString(string field)
+        {
+            StringBuilder sb = (new StringBuilder(Name)).Append("(");
+            sb.Append(subQuery.ToString(field));
+            foreach (Query scoringQuery in scoringQueries)
+            {
+                sb.Append(", ").Append(scoringQuery.ToString(field));
+            }
+            sb.Append(")");
+            sb.Append(strict ? " STRICT" : "");
+            return sb.ToString() + ToStringUtils.Boost(Boost);
+        }
+
+        /// <summary>
+        /// Returns true if <code>o</code> is equal to this. </summary>
+        public override bool Equals(object o)
+        {
+            if (this == o)
+            {
+                return true;
+            }
+            if (!base.Equals(o))
+            {
+                return false;
+            }
+            if (this.GetType() != o.GetType())
+            {
+                return false;
+            }
+            var other = (CustomScoreQuery) o;
+            if (this.Boost != other.Boost || !this.subQuery.Equals(other.subQuery) || this.strict != other.strict ||
+                this.scoringQueries.Length != other.scoringQueries.Length)
+            {
+                return false;
+            }
+            return Arrays.Equals(scoringQueries, other.scoringQueries);
+        }
+
+        /// <summary>
+        /// Returns a hash code value for this object. </summary>
+        public override int GetHashCode()
+        {
+            return (this.GetType().GetHashCode() + subQuery.GetHashCode() + Arrays.GetHashCode(scoringQueries)) ^
+                   Number.FloatToIntBits(Boost) ^ (strict ? 1234 : 4321);
+        }
+
+        /// <summary>
+        /// Returns a <seealso cref="CustomScoreProvider"/> that calculates the custom scores
+        /// for the given <seealso cref="IndexReader"/>. The default implementation returns a default
+        /// implementation as specified in the docs of <seealso cref="CustomScoreProvider"/>.
+        /// @since 2.9.2
+        /// </summary>
+        protected internal virtual CustomScoreProvider GetCustomScoreProvider(AtomicReaderContext context)
+        {
+            return new CustomScoreProvider(context);
+        }
+
+        //=========================== W E I G H T ============================
+
+        private class CustomWeight : Weight
+        {
+            private readonly CustomScoreQuery outerInstance;
+
+            private readonly Weight subQueryWeight;
+            private readonly Weight[] valSrcWeights;
+            private readonly bool qStrict;
+            private float queryWeight;
+
+            public CustomWeight(CustomScoreQuery outerInstance, IndexSearcher searcher)
+            {
+                this.outerInstance = outerInstance;
+                this.subQueryWeight = outerInstance.subQuery.CreateWeight(searcher);
+                this.valSrcWeights = new Weight[outerInstance.scoringQueries.Length];
+                for (int i = 0; i < outerInstance.scoringQueries.Length; i++)
+                {
+                    this.valSrcWeights[i] = outerInstance.scoringQueries[i].CreateWeight(searcher);
+                }
+                this.qStrict = outerInstance.strict;
+            }
+
+            /*(non-Javadoc) @see org.apache.lucene.search.Weight#getQuery() */
+
+            public override Query Query
+            {
+                get { return outerInstance; }
+            }
+
+            public override float ValueForNormalization
+            {
+                get
+                {
+                    float sum = subQueryWeight.ValueForNormalization;
+                    foreach (Weight valSrcWeight in valSrcWeights)
+                    {
+                        if (qStrict)
+                        {
+                            valSrcWeight.ValueForNormalization;
+                                // do not include ValueSource part in the query normalization
+                        }
+                        else
+                        {
+                            sum += valSrcWeight.ValueForNormalization;
+                        }
+                    }
+                    return sum;
+                }
+            }
+
+            /*(non-Javadoc) @see org.apache.lucene.search.Weight#normalize(float) */
+
+            public override void Normalize(float norm, float topLevelBoost)
+            {
+                // note we DONT incorporate our boost, nor pass down any topLevelBoost 
+                // (e.g. from outer BQ), as there is no guarantee that the CustomScoreProvider's 
+                // function obeys the distributive law... it might call sqrt() on the subQuery score
+                // or some other arbitrary function other than multiplication.
+                // so, instead boosts are applied directly in score()
+                subQueryWeight.Normalize(norm, 1f);
+                foreach (Weight valSrcWeight in valSrcWeights)
+                {
+                    if (qStrict)
+                    {
+                        valSrcWeight.Normalize(1, 1); // do not normalize the ValueSource part
+                    }
+                    else
+                    {
+                        valSrcWeight.Normalize(norm, 1f);
+                    }
+                }
+                queryWeight = topLevelBoost*Boost;
+            }
+
+            public override Scorer Scorer(AtomicReaderContext context, Bits acceptDocs)
+            {
+                Scorer subQueryScorer = subQueryWeight.Scorer(context, acceptDocs);
+                if (subQueryScorer == null)
+                {
+                    return null;
+                }
+                var valSrcScorers = new Scorer[valSrcWeights.Length];
+                for (int i = 0; i < valSrcScorers.Length; i++)
+                {
+                    valSrcScorers[i] = valSrcWeights[i].Scorer(context, acceptDocs);
+                }
+                return new CustomScorer(outerInstance, outerInstance.GetCustomScoreProvider(context), this, queryWeight,
+                    subQueryScorer, valSrcScorers);
+            }
+
+            public override Explanation Explain(AtomicReaderContext context, int doc)
+            {
+                Explanation explain = DoExplain(context, doc);
+                return explain ?? new Explanation(0.0f, "no matching docs");
+            }
+
+            internal virtual Explanation DoExplain(AtomicReaderContext info, int doc)
+            {
+                Explanation subQueryExpl = subQueryWeight.Explain(info, doc);
+                if (!subQueryExpl.IsMatch)
+                {
+                    return subQueryExpl;
+                }
+                // match
+                Explanation[] valSrcExpls = new Explanation[valSrcWeights.Length];
+                for (int i = 0; i < valSrcWeights.Length; i++)
+                {
+                    valSrcExpls[i] = valSrcWeights[i].Explain(info, doc);
+                }
+                Explanation customExp = outerInstance.GetCustomScoreProvider(info)
+                    .CustomExplain(doc, subQueryExpl, valSrcExpls);
+                float sc = Boost*customExp.Value;
+                Explanation res = new ComplexExplanation(true, sc, outerInstance.ToString() + ", product of:");
+                res.AddDetail(customExp);
+                res.AddDetail(new Explanation(Boost, "queryBoost"));
+                    // actually using the q boost as q weight (== weight value)
+                return res;
+            }
+
+            public override bool ScoresDocsOutOfOrder()
+            {
+                return false;
+            }
+
+
+
+            //=========================== S C O R E R ============================
+
+            /// <summary>
+            /// A scorer that applies a (callback) function on scores of the subQuery.
+            /// </summary>
+            private class CustomScorer : Scorer
+            {
+                private readonly CustomScoreQuery outerInstance;
+
+                private readonly float qWeight;
+                private readonly Scorer subQueryScorer;
+                private readonly Scorer[] valSrcScorers;
+                private readonly CustomScoreProvider provider;
+                private readonly float[] vScores; // reused in score() to avoid allocating this array for each doc
+
+                // constructor
+                internal CustomScorer(CustomScoreQuery outerInstance, CustomScoreProvider provider, CustomWeight w,
+                    float qWeight, Scorer subQueryScorer, Scorer[] valSrcScorers) : base(w)
+                {
+                    this.outerInstance = outerInstance;
+                    this.qWeight = qWeight;
+                    this.subQueryScorer = subQueryScorer;
+                    this.valSrcScorers = valSrcScorers;
+                    this.vScores = new float[valSrcScorers.Length];
+                    this.provider = provider;
+                }
+
+                public override int NextDoc()
+                {
+                    int doc = subQueryScorer.NextDoc();
+                    if (doc != NO_MORE_DOCS)
+                    {
+                        foreach (Scorer valSrcScorer in valSrcScorers)
+                        {
+                            valSrcScorer.Advance(doc);
+                        }
+                    }
+                    return doc;
+                }
+
+                public override int DocID()
+                {
+                    return subQueryScorer.DocID();
+                }
+
+                /*(non-Javadoc) @see org.apache.lucene.search.Scorer#score() */
+
+                public override float Score()
+                {
+                    for (int i = 0; i < valSrcScorers.Length; i++)
+                    {
+                        vScores[i] = valSrcScorers[i].Score();
+                    }
+                    return qWeight*provider.CustomScore(subQueryScorer.DocID, subQueryScorer.Score, vScores);
+                }
+
+                public override int Freq()
+                {
+                    return subQueryScorer.Freq();
+                }
+
+                public override ICollection<ChildScorer> Children
+                {
+                    get { return Collections.Singleton(new ChildScorer(subQueryScorer, "CUSTOM")); }
+                }
+
+                public override int Advance(int target)
+                {
+                    int doc = subQueryScorer.Advance(target);
+                    if (doc != NO_MORE_DOCS)
+                    {
+                        foreach (Scorer valSrcScorer in valSrcScorers)
+                        {
+                            valSrcScorer.Advance(doc);
+                        }
+                    }
+                    return doc;
+                }
+
+                public override long Cost()
+                {
+                    return subQueryScorer.Cost();
+                }
+            }
+
+            public override Weight CreateWeight(IndexSearcher searcher)
+            {
+                return new CustomWeight(this, searcher);
+            }
+
+            /// <summary>
+            /// Checks if this is strict custom scoring.
+            /// In strict custom scoring, the <seealso cref="ValueSource"/> part does not participate in weight normalization.
+            /// This may be useful when one wants full control over how scores are modified, and does 
+            /// not care about normalizing by the <seealso cref="ValueSource"/> part.
+            /// One particular case where this is useful if for testing this query.   
+            /// <P>
+            /// Note: only has effect when the <seealso cref="ValueSource"/> part is not null.
+            /// </summary>
+            public virtual bool Strict { get; set; }
+
+
+            /// <summary>
+            /// The sub-query that CustomScoreQuery wraps, affecting both the score and which documents match. </summary>
+            public virtual Query SubQuery
+            {
+                get { return subQuery; }
+            }
+
+            /// <summary>
+            /// The scoring queries that only affect the score of CustomScoreQuery. </summary>
+            public virtual Query[] ScoringQueries
+            {
+                get { return scoringQueries; }
+            }
+
+            /// <summary>
+            /// A short name of this query, used in <seealso cref="#toString(String)"/>.
+            /// </summary>
+            public virtual string Name
+            {
+                get { return "custom"; }
+            }
+        }
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Queries/Function/BoostedQuery.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/BoostedQuery.cs b/src/Lucene.Net.Queries/Function/BoostedQuery.cs
index 369617c..157d238 100644
--- a/src/Lucene.Net.Queries/Function/BoostedQuery.cs
+++ b/src/Lucene.Net.Queries/Function/BoostedQuery.cs
@@ -5,7 +5,6 @@ using Lucene.Net.Index;
 using Lucene.Net.Search;
 using Lucene.Net.Support;
 using Lucene.Net.Util;
-using org.apache.lucene.queries.function;
 
 namespace Lucene.Net.Queries.Function
 {
@@ -83,9 +82,9 @@ namespace Lucene.Net.Queries.Function
         {
             private readonly BoostedQuery outerInstance;
 
-            internal readonly IndexSearcher searcher;
-            internal Weight qWeight;
-            internal IDictionary fcontext;
+            private readonly IndexSearcher searcher;
+            private readonly Weight qWeight;
+            private readonly IDictionary fcontext;
 
             //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
             //ORIGINAL LINE: public BoostedWeight(IndexSearcher searcher) throws java.io.IOException
@@ -94,7 +93,7 @@ namespace Lucene.Net.Queries.Function
                 this.outerInstance = outerInstance;
                 this.searcher = searcher;
                 this.qWeight = outerInstance.q.CreateWeight(searcher);
-                this.fcontext = ValueSource.newContext(searcher);
+                this.fcontext = ValueSource.NewContext(searcher);
                 outerInstance.boostVal.CreateWeight(fcontext, searcher);
             }
 
@@ -106,8 +105,6 @@ namespace Lucene.Net.Queries.Function
                 }
             }
 
-            //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-            //ORIGINAL LINE: @Override public float getValueForNormalization() throws java.io.IOException
             public override float ValueForNormalization
             {
                 get
@@ -118,7 +115,7 @@ namespace Lucene.Net.Queries.Function
                 }
             }
 
-            public override void normalize(float norm, float topLevelBoost)
+            public override void Normalize(float norm, float topLevelBoost)
             {
                 topLevelBoost *= Boost;
                 qWeight.Normalize(norm, topLevelBoost);
@@ -145,7 +142,7 @@ namespace Lucene.Net.Queries.Function
                 float sc = subQueryExpl.Value * vals.FloatVal(doc);
                 Explanation res = new ComplexExplanation(true, sc, outerInstance.ToString() + ", product of:");
                 res.AddDetail(subQueryExpl);
-                res.AddDetail(vals.explain(doc));
+                res.AddDetail(vals.Explain(doc));
                 return res;
             }
         }
@@ -155,15 +152,13 @@ namespace Lucene.Net.Queries.Function
         {
             private readonly BoostedQuery outerInstance;
 
-            internal readonly BoostedQuery.BoostedWeight weight;
-            internal readonly float qWeight;
-            internal readonly Scorer scorer;
-            internal readonly FunctionValues vals;
-            internal readonly AtomicReaderContext readerContext;
+            private readonly BoostedQuery.BoostedWeight weight;
+            private readonly float qWeight;
+            private readonly Scorer scorer;
+            private readonly FunctionValues vals;
+            private readonly AtomicReaderContext readerContext;
 
-            //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-            //ORIGINAL LINE: private CustomScorer(org.apache.lucene.index.AtomicReaderContext readerContext, BoostedQuery.BoostedWeight w, float qWeight, Scorer scorer, ValueSource vs) throws java.io.IOException
-            internal CustomScorer(BoostedQuery outerInstance, AtomicReaderContext readerContext, BoostedQuery.BoostedWeight w, float qWeight, Scorer scorer, ValueSource vs)
+            private CustomScorer(BoostedQuery outerInstance, AtomicReaderContext readerContext, BoostedQuery.BoostedWeight w, float qWeight, Scorer scorer, ValueSource vs)
                 : base(w)
             {
                 this.outerInstance = outerInstance;
@@ -179,22 +174,16 @@ namespace Lucene.Net.Queries.Function
                 return scorer.DocID();
             }
 
-            //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-            //ORIGINAL LINE: @Override public int advance(int target) throws java.io.IOException
             public override int Advance(int target)
             {
                 return scorer.Advance(target);
             }
 
-            //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-            //ORIGINAL LINE: @Override public int nextDoc() throws java.io.IOException
             public override int NextDoc()
             {
                 return scorer.NextDoc();
             }
 
-            //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-            //ORIGINAL LINE: @Override public float score() throws java.io.IOException
             public override float Score()
             {
                 float score = qWeight * scorer.Score() * vals.FloatVal(scorer.DocID());
@@ -230,7 +219,7 @@ namespace Lucene.Net.Queries.Function
                 float sc = subQueryExpl.Value * vals.FloatVal(doc);
                 Explanation res = new ComplexExplanation(true, sc, outerInstance.ToString() + ", product of:");
                 res.AddDetail(subQueryExpl);
-                res.AddDetail(vals.explain(doc));
+                res.AddDetail(vals.Explain(doc));
                 return res;
             }
 
@@ -243,7 +232,7 @@ namespace Lucene.Net.Queries.Function
 
         public override string ToString(string field)
         {
-            StringBuilder sb = new StringBuilder();
+            var sb = new StringBuilder();
             sb.Append("boost(").Append(q.ToString(field)).Append(',').Append(boostVal).Append(')');
             sb.Append(ToStringUtils.Boost(Boost));
             return sb.ToString();
@@ -255,7 +244,7 @@ namespace Lucene.Net.Queries.Function
             {
                 return false;
             }
-            BoostedQuery other = (BoostedQuery)o;
+            var other = (BoostedQuery)o;
             return this.q.Equals(other.q) && this.boostVal.Equals(other.boostVal);
         }
 

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Queries/Function/FunctionQuery.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/FunctionQuery.cs b/src/Lucene.Net.Queries/Function/FunctionQuery.cs
index 13044b3..b7b8735 100644
--- a/src/Lucene.Net.Queries/Function/FunctionQuery.cs
+++ b/src/Lucene.Net.Queries/Function/FunctionQuery.cs
@@ -2,8 +2,8 @@
 using System.Collections.Generic;
 using Lucene.Net.Index;
 using Lucene.Net.Search;
+using Lucene.Net.Support;
 using Lucene.Net.Util;
-using org.apache.lucene.queries.function;
 
 namespace Lucene.Net.Queries.Function
 {
@@ -56,7 +56,7 @@ namespace Lucene.Net.Queries.Function
             return this;
         }
 
-        public override void ExtractTerms(HashSet<Term> terms)
+        public override void ExtractTerms(ISet<Term> terms)
         {
         }
 
@@ -64,18 +64,16 @@ namespace Lucene.Net.Queries.Function
         {
             private readonly FunctionQuery outerInstance;
 
-            protected internal readonly IndexSearcher searcher;
+            protected readonly IndexSearcher searcher;
             protected internal float queryNorm;
-            protected internal float queryWeight;
+            protected float queryWeight;
             protected internal readonly IDictionary context;
 
-            //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-            //ORIGINAL LINE: public FunctionWeight(IndexSearcher searcher) throws java.io.IOException
             public FunctionWeight(FunctionQuery outerInstance, IndexSearcher searcher)
             {
                 this.outerInstance = outerInstance;
                 this.searcher = searcher;
-                this.context = ValueSource.newContext(searcher);
+                this.context = ValueSource.NewContext(searcher);
                 outerInstance.func.CreateWeight(context, searcher);
             }
 
@@ -102,14 +100,14 @@ namespace Lucene.Net.Queries.Function
                 queryWeight *= this.queryNorm;
             }
 
-            public override Scorer Scorer(AtomicReaderContext context, Bits acceptDocs)
+            public override Scorer Scorer(AtomicReaderContext ctx, Bits acceptDocs)
             {
-                return new AllScorer(outerInstance, context, acceptDocs, this, queryWeight);
+                return new AllScorer(outerInstance, ctx, acceptDocs, this, queryWeight);
             }
 
-            public override Explanation Explain(AtomicReaderContext context, int doc)
+            public override Explanation Explain(AtomicReaderContext ctx, int doc)
             {
-                return ((AllScorer)Scorer(context, context.reader().LiveDocs)).Explain(doc);
+                return ((AllScorer)Scorer(ctx, ctx.AtomicReader.LiveDocs)).Explain(doc);
             }
         }
 
@@ -165,8 +163,6 @@ namespace Lucene.Net.Queries.Function
                 }
             }
 
-            //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-            //ORIGINAL LINE: @Override public int advance(int target) throws java.io.IOException
             public override int Advance(int target)
             {
                 // this will work even if target==NO_MORE_DOCS
@@ -174,8 +170,6 @@ namespace Lucene.Net.Queries.Function
                 return NextDoc();
             }
 
-            //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-            //ORIGINAL LINE: @Override public float score() throws java.io.IOException
             public override float Score()
             {
                 float score = qWeight * vals.FloatVal(doc);
@@ -191,43 +185,36 @@ namespace Lucene.Net.Queries.Function
                 return maxDoc;
             }
 
-            //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-            //ORIGINAL LINE: @Override public int freq() throws java.io.IOException
             public override int Freq()
             {
                 return 1;
             }
 
-            //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-            //ORIGINAL LINE: public Explanation explain(int doc) throws java.io.IOException
-            public virtual Explanation Explain(int doc)
+            public virtual Explanation Explain(int d)
             {
-                float sc = qWeight * vals.FloatVal(doc);
+                float sc = qWeight * vals.FloatVal(d);
 
                 Explanation result = new ComplexExplanation(true, sc, "FunctionQuery(" + outerInstance.func + "), product of:");
 
-                result.AddDetail(vals.Explain(doc));
+                result.AddDetail(vals.Explain(d));
                 result.AddDetail(new Explanation(Boost, "boost"));
                 result.AddDetail(new Explanation(weight.queryNorm, "queryNorm"));
                 return result;
             }
         }
 
-
-        //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-        //ORIGINAL LINE: @Override public Weight CreateWeight(IndexSearcher searcher) throws java.io.IOException
         public override Weight CreateWeight(IndexSearcher searcher)
         {
             return new FunctionQuery.FunctionWeight(this, searcher);
         }
 
-
         /// <summary>
-        /// Prints a user-readable version of this query. </summary>
+        /// Prints a user-readable version of this query.
+        /// </summary>
         public override string ToString(string field)
         {
             float boost = Boost;
-            return (boost != 1.0 ? "(" : "") + func.ToString() + (boost == 1.0 ? "" : ")^" + boost);
+            return (boost != 1.0 ? "(" : "") + func + (boost == 1.0 ? "" : ")^" + boost);
         }
 
 
@@ -235,12 +222,12 @@ namespace Lucene.Net.Queries.Function
         /// Returns true if <code>o</code> is equal to this. </summary>
         public override bool Equals(object o)
         {
-            if (!typeof(FunctionQuery).IsInstanceOfType(o))
+            var other = o as FunctionQuery;
+            if (other == null)
             {
                 return false;
             }
-            FunctionQuery other = (FunctionQuery)o;
-            return this.Boost == other.Boost && this.func.Equals(other.func);
+            return Boost == other.Boost && func.Equals(other.func);
         }
 
         /// <summary>
@@ -249,7 +236,5 @@ namespace Lucene.Net.Queries.Function
         {
             return func.GetHashCode() * 31 + Number.FloatToIntBits(Boost);
         }
-
     }
-
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Queries/Function/FunctionValues.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/FunctionValues.cs b/src/Lucene.Net.Queries/Function/FunctionValues.cs
index b9443dd..3cc23c3 100644
--- a/src/Lucene.Net.Queries/Function/FunctionValues.cs
+++ b/src/Lucene.Net.Queries/Function/FunctionValues.cs
@@ -82,7 +82,7 @@ namespace Lucene.Net.Queries.Function
         }
 
         /// <summary>
-        /// returns the bytes representation of the string val - TODO: should this return the indexed raw bytes not? </summary>
+        /// returns the bytes representation of the str val - TODO: should this return the indexed raw bytes not? </summary>
         public virtual bool BytesVal(int doc, BytesRef target)
         {
             string s = StrVal(doc);
@@ -274,8 +274,8 @@ namespace Lucene.Net.Queries.Function
         {
             private readonly FunctionValues outerInstance;
 
-            private float l;
-            private float u;
+            private readonly float l;
+            private readonly float u;
 
             public ValueSourceScorerAnonymousInnerClassHelper(FunctionValues outerInstance, IndexReader reader,
                 FunctionValues @this, float l, float u)
@@ -297,8 +297,8 @@ namespace Lucene.Net.Queries.Function
         {
             private readonly FunctionValues outerInstance;
 
-            private float l;
-            private float u;
+            private readonly float l;
+            private readonly float u;
 
             public ValueSourceScorerAnonymousInnerClassHelper2(FunctionValues outerInstance, IndexReader reader,
                 FunctionValues @this, float l, float u)
@@ -320,8 +320,8 @@ namespace Lucene.Net.Queries.Function
         {
             private readonly FunctionValues outerInstance;
 
-            private float l;
-            private float u;
+            private readonly float l;
+            private readonly float u;
 
             public ValueSourceScorerAnonymousInnerClassHelper3(FunctionValues outerInstance, IndexReader reader,
                 FunctionValues @this, float l, float u)
@@ -343,8 +343,8 @@ namespace Lucene.Net.Queries.Function
         {
             private readonly FunctionValues outerInstance;
 
-            private float l;
-            private float u;
+            private readonly float l;
+            private readonly float u;
 
             public ValueSourceScorerAnonymousInnerClassHelper4(FunctionValues outerInstance, IndexReader reader,
                 FunctionValues @this, float l, float u)

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Queries/Function/ValueSource.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSource.cs b/src/Lucene.Net.Queries/Function/ValueSource.cs
index 2e29a02..0f8ed03 100644
--- a/src/Lucene.Net.Queries/Function/ValueSource.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSource.cs
@@ -1,4 +1,5 @@
 using System.Collections;
+using System.Collections.Generic;
 using Lucene.Net.Index;
 using Lucene.Net.Search;
 using Lucene.Net.Support;
@@ -65,9 +66,9 @@ namespace Lucene.Net.Queries.Function
         /// <summary>
         /// Returns a new non-threadsafe context map.
         /// </summary>
-        public static IDictionary NewContext(IndexSearcher searcher)
+        public static IDictionary<string, IndexSearcher> NewContext(IndexSearcher searcher)
         {
-            IDictionary context = new IdentityHashMap<,>();
+            var context = new IdentityHashMap<string, IndexSearcher>();
             context["searcher"] = searcher;
             return context;
         }
@@ -104,7 +105,7 @@ namespace Lucene.Net.Queries.Function
 
             public override SortField Rewrite(IndexSearcher searcher)
             {
-                IDictionary context = NewContext(searcher);
+                var context = NewContext(searcher);
                 outerInstance.CreateWeight(context, searcher);
                 return new SortField(Field, new ValueSourceComparatorSource(outerInstance, context), Reverse);
             }

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Queries/Function/ValueSources/ByteFieldSource.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/ByteFieldSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/ByteFieldSource.cs
index 88c5559..33d2554 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/ByteFieldSource.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/ByteFieldSource.cs
@@ -117,11 +117,9 @@ namespace Lucene.Net.Queries.Function.ValueSources
 
         public override bool Equals(object o)
         {
-            if (o.GetType() != typeof(ByteFieldSource))
-            {
+            var other = o as ByteFieldSource;
+            if (other == null)
                 return false;
-            }
-            ByteFieldSource other = (ByteFieldSource)o;
             return base.Equals(other) && (this.parser == null ? other.parser == null : this.parser.GetType() == other.parser.GetType());
         }
 

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Queries/Function/ValueSources/BytesRefFieldSource.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/BytesRefFieldSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/BytesRefFieldSource.cs
index a277bb2..99af053 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/BytesRefFieldSource.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/BytesRefFieldSource.cs
@@ -24,7 +24,7 @@ namespace Lucene.Net.Queries.Function.ValueSources
      * limitations under the License.
      */
     /// <summary>
-    /// An implementation for retrieving <seealso cref="FunctionValues"/> instances for string based fields.
+    /// An implementation for retrieving <seealso cref="FunctionValues"/> instances for str based fields.
     /// </summary>
     public class BytesRefFieldSource : FieldCacheSource
     {

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Queries/Function/ValueSources/DoubleConstValueSource.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/DoubleConstValueSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/DoubleConstValueSource.cs
index fc2131a..6e468ec 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/DoubleConstValueSource.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/DoubleConstValueSource.cs
@@ -22,138 +22,139 @@ using Lucene.Net.Queries.Function.DocValues;
 namespace Lucene.Net.Queries.Function.ValueSources
 {
     /// <summary>
-	/// Function that returns a constant double value for every document.
-	/// </summary>
-	public class DoubleConstValueSource : ConstNumberSource
-	{
-	  internal readonly double constant;
-	  private readonly float fv;
-	  private readonly long lv;
-
-	  public DoubleConstValueSource(double constant)
-	  {
-		this.constant = constant;
-		this.fv = (float)constant;
-		this.lv = (long)constant;
-	  }
+    /// Function that returns a constant double value for every document.
+    /// </summary>
+    public class DoubleConstValueSource : ConstNumberSource
+    {
+        internal readonly double constant;
+        private readonly float fv;
+        private readonly long lv;
+
+        public DoubleConstValueSource(double constant)
+        {
+            this.constant = constant;
+            this.fv = (float)constant;
+            this.lv = (long)constant;
+        }
 
         public override string Description
         {
             get { return "const(" + constant + ")"; }
         }
 
-	  public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext)
-	  {
-		return new DoubleDocValuesAnonymousInnerClassHelper(this, this);
-	  }
-
-	  private class DoubleDocValuesAnonymousInnerClassHelper : DoubleDocValues
-	  {
-		  private readonly DoubleConstValueSource outerInstance;
-
-		  public DoubleDocValuesAnonymousInnerClassHelper(DoubleConstValueSource outerInstance, DoubleConstValueSource @this) : base(@this)
-		  {
-			  this.outerInstance = outerInstance;
-		  }
-
-		  public override float FloatVal(int doc)
-		  {
-			return outerInstance.fv;
-		  }
-
-		  public override int IntVal(int doc)
-		  {
-			return (int) outerInstance.lv;
-		  }
-
-		  public override long LongVal(int doc)
-		  {
-			return outerInstance.lv;
-		  }
-
-		  public override double DoubleVal(int doc)
-		  {
-			return outerInstance.constant;
-		  }
-
-		  public override string StrVal(int doc)
-		  {
-			return Convert.ToString(outerInstance.constant);
-		  }
-
-		  public override object ObjectVal(int doc)
-		  {
-			return outerInstance.constant;
-		  }
-
-		  public override string ToString(int doc)
-		  {
-			return outerInstance.Description;
-		  }
-	  }
-
-	  public override int GetHashCode()
-	  {
-		long bits = Number.DoubleToRawLongBits(constant);
-		return (int)(bits ^ ((long)((ulong)bits >> 32)));
-	  }
-
-	  public override bool Equals(object o)
-	  {
-	      var other = o as DoubleConstValueSource;
-		if (other == null)
-		{
-			return false;
-		}
-		return this.constant == other.constant;
-	  }
-
-	  public override int Int
-	  {
-		  get
-		  {
-			return (int)lv;
-		  }
-	  }
-
-	  public override long Long
-	  {
-		  get
-		  {
-			return lv;
-		  }
-	  }
-
-	  public override float Float
-	  {
-		  get
-		  {
-			return fv;
-		  }
-	  }
-
-	  public override double Double
-	  {
-		  get
-		  {
-			return constant;
-		  }
-	  }
-
-	  public override Number Number
-	  {
-		  get
-		  {
-			return constant;
-		  }
-	  }
-
-	  public override bool Bool
-	  {
-		  get
-		  {
-			return constant != 0;
-		  }
-	  }
-	}
+        public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext)
+        {
+            return new DoubleDocValuesAnonymousInnerClassHelper(this, this);
+        }
+
+        private class DoubleDocValuesAnonymousInnerClassHelper : DoubleDocValues
+        {
+            private readonly DoubleConstValueSource outerInstance;
+
+            public DoubleDocValuesAnonymousInnerClassHelper(DoubleConstValueSource outerInstance, DoubleConstValueSource @this)
+                : base(@this)
+            {
+                this.outerInstance = outerInstance;
+            }
+
+            public override float FloatVal(int doc)
+            {
+                return outerInstance.fv;
+            }
+
+            public override int IntVal(int doc)
+            {
+                return (int)outerInstance.lv;
+            }
+
+            public override long LongVal(int doc)
+            {
+                return outerInstance.lv;
+            }
+
+            public override double DoubleVal(int doc)
+            {
+                return outerInstance.constant;
+            }
+
+            public override string StrVal(int doc)
+            {
+                return Convert.ToString(outerInstance.constant);
+            }
+
+            public override object ObjectVal(int doc)
+            {
+                return outerInstance.constant;
+            }
+
+            public override string ToString(int doc)
+            {
+                return outerInstance.Description;
+            }
+        }
+
+        public override int GetHashCode()
+        {
+            long bits = Number.DoubleToRawLongBits(constant);
+            return (int)(bits ^ ((long)((ulong)bits >> 32)));
+        }
+
+        public override bool Equals(object o)
+        {
+            var other = o as DoubleConstValueSource;
+            if (other == null)
+            {
+                return false;
+            }
+            return this.constant == other.constant;
+        }
+
+        public override int Int
+        {
+            get
+            {
+                return (int)lv;
+            }
+        }
+
+        public override long Long
+        {
+            get
+            {
+                return lv;
+            }
+        }
+
+        public override float Float
+        {
+            get
+            {
+                return fv;
+            }
+        }
+
+        public override double Double
+        {
+            get
+            {
+                return constant;
+            }
+        }
+
+        public override Number Number
+        {
+            get
+            {
+                return constant;
+            }
+        }
+
+        public override bool Bool
+        {
+            get
+            {
+                return constant != 0;
+            }
+        }
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/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 7aa50d9..1958daf 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/EnumFieldSource.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/EnumFieldSource.cs
@@ -30,7 +30,7 @@ namespace Lucene.Net.Queries.Function.ValueSources
     /// <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 string (displayed) value
+	/// StrVal of the value is not the int value, but its str (displayed) value
 	/// </summary>
 	public class EnumFieldSource : FieldCacheSource
 	{
@@ -85,19 +85,19 @@ namespace Lucene.Net.Queries.Function.ValueSources
 
 		int? intValue;
 		int? enumInt = enumStringToIntMap[stringVal];
-		if (enumInt != null) //enum int found for string
+		if (enumInt != null) //enum int found for str
 		{
 		  return enumInt;
 		}
 
-		//enum int not found for string
+		//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 string
+		if (enumString != null) //has matching str
 		{
 		  return intValue;
 		}

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Queries/Function/ValueSources/FloatFieldSource.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/FloatFieldSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/FloatFieldSource.cs
index 67c5c3d..b3ba445 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/FloatFieldSource.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/FloatFieldSource.cs
@@ -19,128 +19,121 @@ using Lucene.Net.Index;
 using Lucene.Net.Queries.Function.DocValues;
 using Lucene.Net.Search;
 using Lucene.Net.Util;
+using Lucene.Net.Util.Mutable;
 
 namespace Lucene.Net.Queries.Function.ValueSources
 {
     /// <summary>
-	/// Obtains float field values from <seealso cref="IFieldCache#getFloats"/> and makes those
-	/// values available as other numeric types, casting as needed.
-	/// </summary>
-	public class FloatFieldSource : FieldCacheSource
-	{
+    /// Obtains float field values from <seealso cref="IFieldCache#getFloats"/> and makes those
+    /// values available as other numeric types, casting as needed.
+    /// </summary>
+    public class FloatFieldSource : FieldCacheSource
+    {
 
-	  protected internal readonly FieldCache.FloatParser parser;
+        protected internal readonly FieldCache.IFloatParser parser;
 
-	  public FloatFieldSource(string field) : this(field, null)
-	  {
-	  }
+        public FloatFieldSource(string field)
+            : this(field, null)
+        {
+        }
 
-	  public FloatFieldSource(string field, IFieldCache.FloatParser parser) : base(field)
-	  {
-		this.parser = parser;
-	  }
+        public FloatFieldSource(string field, FieldCache.IFloatParser parser)
+            : base(field)
+        {
+            this.parser = parser;
+        }
 
         public override string Description
         {
             get { return "float(" + field + ')'; }
         }
 
-//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.Floats arr = cache.getFloats(readerContext.reader(), field, parser, true);
-		FieldCache.Floats arr = cache.GetFloats(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 FloatDocValuesAnonymousInnerClassHelper(this, this, arr, valid);
-	  }
-
-	  private class FloatDocValuesAnonymousInnerClassHelper : FloatDocValues
-	  {
-		  private readonly FloatFieldSource outerInstance;
-
-		  private readonly FieldCache.Floats arr;
-		  private readonly Bits valid;
-
-		  public FloatDocValuesAnonymousInnerClassHelper(FloatFieldSource outerInstance, FloatFieldSource this, FieldCache.Floats arr, Bits valid) : base(this)
-		  {
-			  this.outerInstance = outerInstance;
-			  this.arr = arr;
-			  this.valid = valid;
-		  }
-
-		  public override float FloatVal(int doc)
-		  {
-			return arr.get(doc);
-		  }
-
-		  public override object objectVal(int doc)
-		  {
-			return valid.get(doc) ? arr.get(doc) : null;
-		  }
-
-		  public override bool exists(int doc)
-		  {
-			return arr.get(doc) != 0 || valid.get(doc);
-		  }
-
-		  public override ValueFiller ValueFiller
-		  {
-			  get
-			  {
-				return new ValueFillerAnonymousInnerClassHelper(this);
-			  }
-		  }
-
-		  private class ValueFillerAnonymousInnerClassHelper : ValueFiller
-		  {
-			  private readonly FloatDocValuesAnonymousInnerClassHelper outerInstance;
-
-			  public ValueFillerAnonymousInnerClassHelper(FloatDocValuesAnonymousInnerClassHelper outerInstance)
-			  {
-				  this.outerInstance = outerInstance;
-				  mval = new MutableValueFloat();
-			  }
-
-			  private readonly MutableValueFloat mval;
-
-			  public override MutableValue Value
-			  {
-				  get
-				  {
-					return mval;
-				  }
-			  }
-
-			  public override void fillValue(int doc)
-			  {
-				mval.value = outerInstance.arr.get(doc);
-				mval.exists = mval.value != 0 || outerInstance.valid.get(doc);
-			  }
-		  }
-
-	  }
-
-	  public override bool Equals(object o)
-	  {
-		if (o.GetType() != typeof(FloatFieldSource))
-		{
-			return false;
-		}
-		FloatFieldSource other = (FloatFieldSource)o;
-		return base.Equals(other) && (this.parser == null ? other.parser == null : this.parser.GetType() == other.parser.GetType());
-	  }
-
-	  public override int GetHashCode()
-	  {
-		int h = parser == null ? typeof(float?).GetHashCode() : parser.GetType().GetHashCode();
-		h += base.GetHashCode();
-		return h;
-	  }
-	}
+        public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext)
+        {
+            var arr = cache.GetFloats(readerContext.AtomicReader, field, parser, true);
+            var valid = cache.GetDocsWithField(readerContext.AtomicReader, field);
+            return new FloatDocValuesAnonymousInnerClassHelper(this, this, arr, valid);
+        }
+
+        private class FloatDocValuesAnonymousInnerClassHelper : FloatDocValues
+        {
+            private readonly FloatFieldSource outerInstance;
+
+            private readonly FieldCache.Floats arr;
+            private readonly Bits valid;
+
+            public FloatDocValuesAnonymousInnerClassHelper(FloatFieldSource outerInstance, FloatFieldSource @this, FieldCache.Floats arr, Bits valid)
+                : base(@this)
+            {
+                this.outerInstance = outerInstance;
+                this.arr = arr;
+                this.valid = valid;
+            }
+
+            public override float FloatVal(int doc)
+            {
+                return arr.Get(doc);
+            }
+
+            public override object ObjectVal(int doc)
+            {
+                return valid.Get(doc) ? arr.Get(doc) : (float?)null;
+            }
+
+            public override bool Exists(int doc)
+            {
+                return arr.Get(doc) != 0 || valid.Get(doc);
+            }
+
+            public override AbstractValueFiller ValueFiller
+            {
+                get
+                {
+                    return new ValueFillerAnonymousInnerClassHelper(this);
+                }
+            }
+
+            private class ValueFillerAnonymousInnerClassHelper : AbstractValueFiller
+            {
+                private readonly FloatDocValuesAnonymousInnerClassHelper outerInstance;
+
+                public ValueFillerAnonymousInnerClassHelper(FloatDocValuesAnonymousInnerClassHelper outerInstance)
+                {
+                    this.outerInstance = outerInstance;
+                    mval = new MutableValueFloat();
+                }
+
+                private readonly MutableValueFloat mval;
+
+                public override MutableValue Value
+                {
+                    get
+                    {
+                        return mval;
+                    }
+                }
+
+                public override void FillValue(int doc)
+                {
+                    mval.Value = outerInstance.arr.Get(doc);
+                    mval.Exists = mval.Value != 0 || outerInstance.valid.Get(doc);
+                }
+            }
+        }
 
+        public override bool Equals(object o)
+        {
+            var other = o as FloatFieldSource;
+            if (other == null)
+                return false;
+            return base.Equals(other) && (this.parser == null ? other.parser == null : this.parser.GetType() == other.parser.GetType());
+        }
+
+        public override int GetHashCode()
+        {
+            int h = parser == null ? typeof(float?).GetHashCode() : parser.GetType().GetHashCode();
+            h += base.GetHashCode();
+            return h;
+        }
+    }
 }
\ No newline at end of file


[3/4] More work on Lucene.Net.Queries

Posted by sy...@apache.org.
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Queries/Function/ValueSources/IDFValueSource.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/IDFValueSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/IDFValueSource.cs
index 363cb60..1b487a8 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/IDFValueSource.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/IDFValueSource.cs
@@ -23,57 +23,54 @@ using Lucene.Net.Util;
 namespace Lucene.Net.Queries.Function.ValueSources
 {
     /// <summary>
-	/// Function that returns <seealso cref="TFIDFSimilarity #idf(long, long)"/>
-	/// 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 IDFValueSource : DocFreqValueSource
-	{
-	  public IDFValueSource(string field, string val, string indexedField, BytesRef indexedBytes) : base(field, val, indexedField, indexedBytes)
-	  {
-	  }
+    /// Function that returns <seealso cref="TFIDFSimilarity #idf(long, long)"/>
+    /// 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 IDFValueSource : DocFreqValueSource
+    {
+        public IDFValueSource(string field, string val, string indexedField, BytesRef indexedBytes)
+            : base(field, val, indexedField, indexedBytes)
+        {
+        }
 
-	  public override string name()
-	  {
-		return "idf";
-	  }
-
-//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, AtomicReaderContext readerContext) throws java.io.IOException
-	  public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext)
-	  {
-		IndexSearcher searcher = (IndexSearcher)context["searcher"];
-		TFIDFSimilarity sim = asTFIDF(searcher.Similarity, field);
-		if (sim == null)
-		{
-		  throw new System.NotSupportedException("requires a TFIDFSimilarity (such as DefaultSimilarity)");
-		}
-		int docfreq = searcher.IndexReader.docFreq(new Term(indexedField, indexedBytes));
-		float idf = sim.idf(docfreq, searcher.IndexReader.maxDoc());
-		return new ConstDoubleDocValues(idf, this);
-	  }
-
-	  // tries extra hard to cast the sim to TFIDFSimilarity
-	  internal static TFIDFSimilarity AsTFIDF(Similarity sim, string field)
-	  {
-		while (sim is PerFieldSimilarityWrapper)
-		{
-		  sim = ((PerFieldSimilarityWrapper)sim).get(field);
-		}
-		if (sim is TFIDFSimilarity)
-		{
-		  return (TFIDFSimilarity)sim;
-		}
-		else
-		{
-		  return null;
-		}
-	  }
-	}
+        public override string Name
+        {
+            get { return "idf"; }
+        }
 
+        public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext)
+        {
+            var searcher = (IndexSearcher)context["searcher"];
+            TFIDFSimilarity sim = AsTFIDF(searcher.Similarity, field);
+            if (sim == null)
+            {
+                throw new System.NotSupportedException("requires a TFIDFSimilarity (such as DefaultSimilarity)");
+            }
+            int docfreq = searcher.IndexReader.DocFreq(new Term(indexedField, indexedBytes));
+            float idf = sim.Idf(docfreq, searcher.IndexReader.MaxDoc);
+            return new ConstDoubleDocValues(idf, this);
+        }
 
+        // tries extra hard to cast the sim to TFIDFSimilarity
+        internal static TFIDFSimilarity AsTFIDF(Similarity sim, string field)
+        {
+            while (sim is PerFieldSimilarityWrapper)
+            {
+                sim = ((PerFieldSimilarityWrapper)sim).Get(field);
+            }
+            if (sim is TFIDFSimilarity)
+            {
+                return (TFIDFSimilarity)sim;
+            }
+            else
+            {
+                return null;
+            }
+        }
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Queries/Function/ValueSources/IfFunction.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/IfFunction.cs b/src/Lucene.Net.Queries/Function/ValueSources/IfFunction.cs
index 692dae1..0eb8cad 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/IfFunction.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/IfFunction.cs
@@ -15,163 +15,152 @@
  * limitations under the License.
  */
 using System.Collections;
-using org.apache.lucene.queries.function;
+using Lucene.Net.Index;
+using Lucene.Net.Search;
+using Lucene.Net.Util;
 
 namespace Lucene.Net.Queries.Function.ValueSources
 {
     /// <summary>
-	/// Depending on the boolean value of the <code>ifSource</code> function,
-	/// returns the value of the <code>trueSource</code> or <code>falseSource</code> function.
-	/// </summary>
-	public class IfFunction : BoolFunction
-	{
-	  private readonly ValueSource ifSource;
-	  private readonly ValueSource trueSource;
-	  private readonly ValueSource falseSource;
-
-
-	  public IfFunction(ValueSource ifSource, ValueSource trueSource, ValueSource falseSource)
-	  {
-		this.ifSource = ifSource;
-		this.trueSource = trueSource;
-		this.falseSource = falseSource;
-	  }
-
-//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.queries.function.FunctionValues ifVals = ifSource.GetValues(context, readerContext);
-		FunctionValues ifVals = ifSource.GetValues(context, readerContext);
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final org.apache.lucene.queries.function.FunctionValues trueVals = trueSource.GetValues(context, readerContext);
-		FunctionValues trueVals = trueSource.GetValues(context, readerContext);
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final org.apache.lucene.queries.function.FunctionValues falseVals = falseSource.GetValues(context, readerContext);
-		FunctionValues falseVals = falseSource.GetValues(context, readerContext);
-
-		return new FunctionValuesAnonymousInnerClassHelper(this, ifVals, trueVals, falseVals);
-
-	  }
-
-	  private class FunctionValuesAnonymousInnerClassHelper : FunctionValues
-	  {
-		  private readonly IfFunction outerInstance;
-
-		  private FunctionValues ifVals;
-		  private FunctionValues trueVals;
-		  private FunctionValues falseVals;
-
-		  public FunctionValuesAnonymousInnerClassHelper(IfFunction outerInstance, FunctionValues ifVals, FunctionValues trueVals, FunctionValues falseVals)
-		  {
-			  this.outerInstance = outerInstance;
-			  this.ifVals = ifVals;
-			  this.trueVals = trueVals;
-			  this.falseVals = falseVals;
-		  }
-
-		  public override sbyte ByteVal(int doc)
-		  {
-			return ifVals.boolVal(doc) ? trueVals.ByteVal(doc) : falseVals.ByteVal(doc);
-		  }
-
-		  public override short ShortVal(int doc)
-		  {
-			return ifVals.boolVal(doc) ? trueVals.ShortVal(doc) : falseVals.ShortVal(doc);
-		  }
-
-		  public override float FloatVal(int doc)
-		  {
-			return ifVals.boolVal(doc) ? trueVals.FloatVal(doc) : falseVals.FloatVal(doc);
-		  }
-
-		  public override int intVal(int doc)
-		  {
-			return ifVals.boolVal(doc) ? trueVals.intVal(doc) : falseVals.intVal(doc);
-		  }
-
-		  public override long LongVal(int doc)
-		  {
-			return ifVals.boolVal(doc) ? trueVals.LongVal(doc) : falseVals.LongVal(doc);
-		  }
-
-		  public override double DoubleVal(int doc)
-		  {
-			return ifVals.boolVal(doc) ? trueVals.DoubleVal(doc) : falseVals.DoubleVal(doc);
-		  }
-
-		  public override string StrVal(int doc)
-		  {
-			return ifVals.boolVal(doc) ? trueVals.StrVal(doc) : falseVals.StrVal(doc);
-		  }
-
-		  public override bool boolVal(int doc)
-		  {
-			return ifVals.boolVal(doc) ? trueVals.boolVal(doc) : falseVals.boolVal(doc);
-		  }
-
-		  public override bool bytesVal(int doc, BytesRef target)
-		  {
-			return ifVals.boolVal(doc) ? trueVals.bytesVal(doc, target) : falseVals.bytesVal(doc, target);
-		  }
-
-		  public override object objectVal(int doc)
-		  {
-			return ifVals.boolVal(doc) ? trueVals.objectVal(doc) : falseVals.objectVal(doc);
-		  }
-
-		  public override bool exists(int doc)
-		  {
-			return true; // TODO: flow through to any sub-sources?
-		  }
-
-		  public override ValueFiller ValueFiller
-		  {
-			  get
-			  {
-				// TODO: we need types of trueSource / falseSource to handle this
-				// for now, use float.
-				return base.ValueFiller;
-			  }
-		  }
-
-		  public override string ToString(int doc)
-		  {
-			return "if(" + ifVals.ToString(doc) + ',' + trueVals.ToString(doc) + ',' + falseVals.ToString(doc) + ')';
-		  }
-	  }
-
-	  public override string description()
-	  {
-		return "if(" + ifSource.description() + ',' + trueSource.description() + ',' + falseSource + ')';
-	  }
-
-	  public override int GetHashCode()
-	  {
-		int h = ifSource.GetHashCode();
-		h = h * 31 + trueSource.GetHashCode();
-		h = h * 31 + falseSource.GetHashCode();
-		return h;
-	  }
-
-	  public override bool Equals(object o)
-	  {
-		if (!(o is IfFunction))
-		{
-			return false;
-		}
-		IfFunction other = (IfFunction)o;
-		return ifSource.Equals(other.ifSource) && trueSource.Equals(other.trueSource) && falseSource.Equals(other.falseSource);
-	  }
-
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: @Override public void CreateWeight(java.util.Map context, org.apache.lucene.search.IndexSearcher searcher) throws java.io.IOException
-	  public override void CreateWeight(IDictionary context, IndexSearcher searcher)
-	  {
-		ifSource.CreateWeight(context, searcher);
-		trueSource.CreateWeight(context, searcher);
-		falseSource.CreateWeight(context, searcher);
-	  }
-	}
+    /// Depending on the boolean value of the <code>ifSource</code> function,
+    /// returns the value of the <code>trueSource</code> or <code>falseSource</code> function.
+    /// </summary>
+    public class IfFunction : BoolFunction
+    {
+        private readonly ValueSource ifSource;
+        private readonly ValueSource trueSource;
+        private readonly ValueSource falseSource;
+
+
+        public IfFunction(ValueSource ifSource, ValueSource trueSource, ValueSource falseSource)
+        {
+            this.ifSource = ifSource;
+            this.trueSource = trueSource;
+            this.falseSource = falseSource;
+        }
+
+        public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext)
+        {
+            FunctionValues ifVals = ifSource.GetValues(context, readerContext);
+            FunctionValues trueVals = trueSource.GetValues(context, readerContext);
+            FunctionValues falseVals = falseSource.GetValues(context, readerContext);
+
+            return new FunctionValuesAnonymousInnerClassHelper(this, ifVals, trueVals, falseVals);
+        }
+
+        private class FunctionValuesAnonymousInnerClassHelper : FunctionValues
+        {
+            private readonly IfFunction outerInstance;
+
+            private readonly FunctionValues ifVals;
+            private readonly FunctionValues trueVals;
+            private readonly FunctionValues falseVals;
+
+            public FunctionValuesAnonymousInnerClassHelper(IfFunction outerInstance, FunctionValues ifVals, FunctionValues trueVals, FunctionValues falseVals)
+            {
+                this.outerInstance = outerInstance;
+                this.ifVals = ifVals;
+                this.trueVals = trueVals;
+                this.falseVals = falseVals;
+            }
+
+            public override sbyte ByteVal(int doc)
+            {
+                return ifVals.BoolVal(doc) ? trueVals.ByteVal(doc) : falseVals.ByteVal(doc);
+            }
+
+            public override short ShortVal(int doc)
+            {
+                return ifVals.BoolVal(doc) ? trueVals.ShortVal(doc) : falseVals.ShortVal(doc);
+            }
+
+            public override float FloatVal(int doc)
+            {
+                return ifVals.BoolVal(doc) ? trueVals.FloatVal(doc) : falseVals.FloatVal(doc);
+            }
+
+            public override int IntVal(int doc)
+            {
+                return ifVals.BoolVal(doc) ? trueVals.IntVal(doc) : falseVals.IntVal(doc);
+            }
+
+            public override long LongVal(int doc)
+            {
+                return ifVals.BoolVal(doc) ? trueVals.LongVal(doc) : falseVals.LongVal(doc);
+            }
+
+            public override double DoubleVal(int doc)
+            {
+                return ifVals.BoolVal(doc) ? trueVals.DoubleVal(doc) : falseVals.DoubleVal(doc);
+            }
+
+            public override string StrVal(int doc)
+            {
+                return ifVals.BoolVal(doc) ? trueVals.StrVal(doc) : falseVals.StrVal(doc);
+            }
+
+            public override bool BoolVal(int doc)
+            {
+                return ifVals.BoolVal(doc) ? trueVals.BoolVal(doc) : falseVals.BoolVal(doc);
+            }
+
+            public override bool BytesVal(int doc, BytesRef target)
+            {
+                return ifVals.BoolVal(doc) ? trueVals.BytesVal(doc, target) : falseVals.BytesVal(doc, target);
+            }
+
+            public override object ObjectVal(int doc)
+            {
+                return ifVals.BoolVal(doc) ? trueVals.ObjectVal(doc) : falseVals.ObjectVal(doc);
+            }
+
+            public override bool Exists(int doc)
+            {
+                return true; // TODO: flow through to any sub-sources?
+            }
+
+            public override AbstractValueFiller ValueFiller
+            {
+                get
+                {
+                    // TODO: we need types of trueSource / falseSource to handle this
+                    // for now, use float.
+                    return base.ValueFiller;
+                }
+            }
+
+            public override string ToString(int doc)
+            {
+                return "if(" + ifVals.ToString(doc) + ',' + trueVals.ToString(doc) + ',' + falseVals.ToString(doc) + ')';
+            }
+        }
+
+        public override string Description
+        {
+            get { return "if(" + ifSource.Description + ',' + trueSource.Description + ',' + falseSource + ')'; }
+        }
+
+        public override int GetHashCode()
+        {
+            int h = ifSource.GetHashCode();
+            h = h * 31 + trueSource.GetHashCode();
+            h = h * 31 + falseSource.GetHashCode();
+            return h;
+        }
+
+        public override bool Equals(object o)
+        {
+            var other = o as IfFunction;
+            if (other == null)
+                return false;
+            return ifSource.Equals(other.ifSource) && trueSource.Equals(other.trueSource) && falseSource.Equals(other.falseSource);
+        }
+
+        public override void CreateWeight(IDictionary context, IndexSearcher searcher)
+        {
+            ifSource.CreateWeight(context, searcher);
+            trueSource.CreateWeight(context, searcher);
+            falseSource.CreateWeight(context, searcher);
+        }
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Queries/Function/ValueSources/IntFieldSource.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/IntFieldSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/IntFieldSource.cs
index 63a8e31..2fc6636 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/IntFieldSource.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/IntFieldSource.cs
@@ -16,159 +16,153 @@
  */
 using System;
 using System.Collections;
+using Lucene.Net.Index;
 using Lucene.Net.Queries.Function.DocValues;
-using org.apache.lucene.queries.function;
+using Lucene.Net.Search;
+using Lucene.Net.Util;
+using Lucene.Net.Util.Mutable;
 
 namespace Lucene.Net.Queries.Function.ValueSources
 {
     /// <summary>
-	/// Obtains int field values from <seealso cref="FieldCache#getInts"/> and makes those
-	/// values available as other numeric types, casting as needed.
-	/// </summary>
-	public class IntFieldSource : FieldCacheSource
-	{
-	  internal readonly FieldCache.IntParser parser;
-
-	  public IntFieldSource(string field) : this(field, null)
-	  {
-	  }
-
-	  public IntFieldSource(string field, FieldCache.IntParser parser) : base(field)
-	  {
-		this.parser = parser;
-	  }
-
-	  public override string description()
-	  {
-		return "int(" + field + ')';
-	  }
-
-
-//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.reader(), 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.reader(), field);
-
-		return new IntDocValuesAnonymousInnerClassHelper(this, this, arr, valid);
-	  }
-
-	  private class IntDocValuesAnonymousInnerClassHelper : IntDocValues
-	  {
-		  private readonly IntFieldSource outerInstance;
-
-		  private FieldCache.Ints arr;
-		  private Bits valid;
-
-		  public IntDocValuesAnonymousInnerClassHelper(IntFieldSource outerInstance, IntFieldSource this, FieldCache.Ints arr, Bits valid) : base(this)
-		  {
-			  this.outerInstance = outerInstance;
-			  this.arr = arr;
-			  this.valid = valid;
-			  val = new MutableValueInt();
-		  }
-
-		  internal 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)
-		  {
-			return Convert.ToString(arr.get(doc));
-		  }
-
-		  public override object objectVal(int doc)
-		  {
-			return valid.get(doc) ? arr.get(doc) : null;
-		  }
-
-		  public override bool exists(int doc)
-		  {
-			return arr.get(doc) != 0 || valid.get(doc);
-		  }
-
-		  public override string ToString(int doc)
-		  {
-			return outerInstance.description() + '=' + intVal(doc);
-		  }
-
-		  public override ValueFiller ValueFiller
-		  {
-			  get
-			  {
-				return new ValueFillerAnonymousInnerClassHelper(this);
-			  }
-		  }
-
-		  private class ValueFillerAnonymousInnerClassHelper : ValueFiller
-		  {
-			  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 = mval.value != 0 || outerInstance.valid.get(doc);
-			  }
-		  }
-
-
-	  }
-
-	  public override bool Equals(object o)
-	  {
-		if (o.GetType() != typeof(IntFieldSource))
-		{
-			return false;
-		}
-		IntFieldSource other = (IntFieldSource)o;
-		return base.Equals(other) && (this.parser == null ? other.parser == null : this.parser.GetType() == other.parser.GetType());
-	  }
-
-	  public override int GetHashCode()
-	  {
-		int h = parser == null ? typeof(int?).GetHashCode() : parser.GetType().GetHashCode();
-		h += base.GetHashCode();
-		return h;
-	  }
-	}
-
+    /// Obtains int field values from <seealso cref="FieldCache#getInts"/> and makes those
+    /// values available as other numeric types, casting as needed.
+    /// </summary>
+    public class IntFieldSource : FieldCacheSource
+    {
+        internal readonly FieldCache.IIntParser parser;
+
+        public IntFieldSource(string field)
+            : this(field, null)
+        {
+        }
+
+        public IntFieldSource(string field, FieldCache.IIntParser parser)
+            : base(field)
+        {
+            this.parser = parser;
+        }
+
+        public override string Description
+        {
+            get { return "int(" + field + ')'; }
+        }
+
+        public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext)
+        {
+            FieldCache.Ints arr = cache.GetInts(readerContext.AtomicReader, field, parser, true);
+            Bits valid = cache.GetDocsWithField(readerContext.AtomicReader, field);
+
+            return new IntDocValuesAnonymousInnerClassHelper(this, this, arr, valid);
+        }
+
+        private class IntDocValuesAnonymousInnerClassHelper : IntDocValues
+        {
+            private readonly IntFieldSource outerInstance;
+
+            private readonly FieldCache.Ints arr;
+            private readonly Bits valid;
+
+            public IntDocValuesAnonymousInnerClassHelper(IntFieldSource outerInstance, IntFieldSource @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)
+            {
+                return Convert.ToString(arr.Get(doc));
+            }
+
+            public override object ObjectVal(int doc)
+            {
+                return valid.Get(doc) ? arr.Get(doc) : (int?)null;
+            }
+
+            public override bool Exists(int doc)
+            {
+                return arr.Get(doc) != 0 || valid.Get(doc);
+            }
+
+            public override string ToString(int doc)
+            {
+                return outerInstance.Description + '=' + IntVal(doc);
+            }
+
+            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 = mval.Value != 0 || outerInstance.valid.Get(doc);
+                }
+            }
+        }
+
+        public override bool Equals(object o)
+        {
+            var other = o as IntFieldSource;
+            if (other == null)
+                return false;
+            return base.Equals(other) && (this.parser == null ? other.parser == null : this.parser.GetType() == other.parser.GetType());
+        }
+
+        public override int GetHashCode()
+        {
+            int h = parser == null ? typeof(int?).GetHashCode() : parser.GetType().GetHashCode();
+            h += base.GetHashCode();
+            return h;
+        }
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Queries/Function/ValueSources/JoinDocFreqValueSource.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/JoinDocFreqValueSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/JoinDocFreqValueSource.cs
index ba9572f..4b6db96 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/JoinDocFreqValueSource.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/JoinDocFreqValueSource.cs
@@ -16,107 +16,103 @@
  */
 using System;
 using System.Collections;
+using System.IO;
+using Lucene.Net.Index;
 using Lucene.Net.Queries.Function.DocValues;
-using org.apache.lucene.queries.function;
+using Lucene.Net.Util;
+using Lucene.Net.Util.Packed;
 
 namespace Lucene.Net.Queries.Function.ValueSources
 {
     /// <summary>
-	/// Use a field value and find the Document Frequency within another field.
-	/// 
-	/// @since solr 4.0
-	/// </summary>
-	public class JoinDocFreqValueSource : FieldCacheSource
-	{
+    /// Use a field value and find the Document Frequency within another field.
+    /// 
+    /// @since solr 4.0
+    /// </summary>
+    public class JoinDocFreqValueSource : FieldCacheSource
+    {
 
-	  public const string NAME = "joindf";
+        public const string NAME = "joindf";
 
-	  protected internal readonly string qfield;
+        protected internal readonly string qfield;
 
-	  public JoinDocFreqValueSource(string field, string qfield) : base(field)
-	  {
-		this.qfield = qfield;
-	  }
+        public JoinDocFreqValueSource(string field, string qfield)
+            : base(field)
+        {
+            this.qfield = qfield;
+        }
 
-	  public override string description()
-	  {
-		return NAME + "(" + field + ":(" + qfield + "))";
-	  }
+        public override string Description
+        {
+            get { return NAME + "(" + field + ":(" + qfield + "))"; }
+        }
 
-//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.index.BinaryDocValues terms = cache.getTerms(readerContext.reader(), field, false, org.apache.lucene.util.packed.PackedInts.FAST);
-		BinaryDocValues terms = cache.getTerms(readerContext.reader(), field, false, PackedInts.FAST);
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final org.apache.lucene.index.IndexReader top = org.apache.lucene.index.ReaderUtil.getTopLevelContext(readerContext).reader();
-		IndexReader top = ReaderUtil.getTopLevelContext(readerContext).reader();
-		Terms t = MultiFields.getTerms(top, qfield);
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final org.apache.lucene.index.TermsEnum termsEnum = t == null ? org.apache.lucene.index.TermsEnum.EMPTY : t.iterator(null);
-		TermsEnum termsEnum = t == null ? TermsEnum.EMPTY : t.iterator(null);
+        public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext)
+        {
+            BinaryDocValues terms = cache.GetTerms(readerContext.AtomicReader, field, false, PackedInts.FAST);
+            IndexReader top = ReaderUtil.GetTopLevelContext(readerContext).Reader;
+            Terms t = MultiFields.GetTerms(top, qfield);
+            TermsEnum termsEnum = t == null ? TermsEnum.EMPTY : t.Iterator(null);
 
-		return new IntDocValuesAnonymousInnerClassHelper(this, this, terms, termsEnum);
-	  }
+            return new IntDocValuesAnonymousInnerClassHelper(this, this, terms, termsEnum);
+        }
 
-	  private class IntDocValuesAnonymousInnerClassHelper : IntDocValues
-	  {
-		  private readonly JoinDocFreqValueSource outerInstance;
+        private class IntDocValuesAnonymousInnerClassHelper : IntDocValues
+        {
+            private readonly JoinDocFreqValueSource outerInstance;
 
-		  private BinaryDocValues terms;
-		  private TermsEnum termsEnum;
+            private readonly BinaryDocValues terms;
+            private readonly TermsEnum termsEnum;
 
-		  public IntDocValuesAnonymousInnerClassHelper(JoinDocFreqValueSource outerInstance, JoinDocFreqValueSource this, BinaryDocValues terms, TermsEnum termsEnum) : base(this)
-		  {
-			  this.outerInstance = outerInstance;
-			  this.terms = terms;
-			  this.termsEnum = termsEnum;
-			  @ref = new BytesRef();
-		  }
+            public IntDocValuesAnonymousInnerClassHelper(JoinDocFreqValueSource outerInstance, JoinDocFreqValueSource @this, BinaryDocValues terms, TermsEnum termsEnum)
+                : base(@this)
+            {
+                this.outerInstance = outerInstance;
+                this.terms = terms;
+                this.termsEnum = termsEnum;
+                @ref = new BytesRef();
+            }
 
-		  internal readonly BytesRef @ref;
+            private readonly BytesRef @ref;
 
-		  public override int intVal(int doc)
-		  {
-			try
-			{
-			  terms.get(doc, @ref);
-			  if (termsEnum.seekExact(@ref))
-			  {
-				return termsEnum.docFreq();
-			  }
-			  else
-			  {
-				return 0;
-			  }
-			}
-			catch (IOException e)
-			{
-			  throw new Exception("caught exception in function " + outerInstance.description() + " : doc=" + doc, e);
-			}
-		  }
-	  }
+            public override int IntVal(int doc)
+            {
+                try
+                {
+                    terms.Get(doc, @ref);
+                    if (termsEnum.SeekExact(@ref))
+                    {
+                        return termsEnum.DocFreq();
+                    }
+                    else
+                    {
+                        return 0;
+                    }
+                }
+                catch (IOException e)
+                {
+                    throw new Exception("caught exception in function " + outerInstance.Description + " : doc=" + doc, e);
+                }
+            }
+        }
 
-	  public override bool Equals(object o)
-	  {
-		if (o.GetType() != typeof(JoinDocFreqValueSource))
-		{
-			return false;
-		}
-		JoinDocFreqValueSource other = (JoinDocFreqValueSource)o;
-		if (!qfield.Equals(other.qfield))
-		{
-			return false;
-		}
-		return base.Equals(other);
-	  }
-
-	  public override int GetHashCode()
-	  {
-		return qfield.GetHashCode() + base.GetHashCode();
-	  }
-	}
+        public override bool Equals(object o)
+        {
+            if (o.GetType() != typeof(JoinDocFreqValueSource))
+            {
+                return false;
+            }
+            var other = (JoinDocFreqValueSource)o;
+            if (!qfield.Equals(other.qfield))
+            {
+                return false;
+            }
+            return base.Equals(other);
+        }
 
+        public override int GetHashCode()
+        {
+            return qfield.GetHashCode() + base.GetHashCode();
+        }
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Queries/Function/ValueSources/LinearFloatFunction.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/LinearFloatFunction.cs b/src/Lucene.Net.Queries/Function/ValueSources/LinearFloatFunction.cs
index bf92522..6759de7 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/LinearFloatFunction.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/LinearFloatFunction.cs
@@ -15,94 +15,87 @@
  * limitations under the License.
  */
 using System.Collections;
+using Lucene.Net.Index;
 using Lucene.Net.Queries.Function.DocValues;
-using org.apache.lucene.queries.function;
+using Lucene.Net.Search;
+using Lucene.Net.Support;
 
 namespace Lucene.Net.Queries.Function.ValueSources
 {
     /// <summary>
-	/// <code>LinearFloatFunction</code> implements a linear function over
-	/// another <seealso cref="ValueSource"/>.
-	/// <br>
-	/// Normally Used as an argument to a <seealso cref="FunctionQuery"/>
-	/// 
-	/// 
-	/// </summary>
-	public class LinearFloatFunction : ValueSource
-	{
-	  protected internal readonly ValueSource source;
-	  protected internal readonly float slope;
-	  protected internal readonly float intercept;
+    /// <code>LinearFloatFunction</code> implements a linear function over
+    /// another <seealso cref="ValueSource"/>.
+    /// <br>
+    /// Normally Used as an argument to a <seealso cref="FunctionQuery"/>
+    /// 
+    /// 
+    /// </summary>
+    public class LinearFloatFunction : ValueSource
+    {
+        protected internal readonly ValueSource source;
+        protected internal readonly float slope;
+        protected internal readonly float intercept;
 
-	  public LinearFloatFunction(ValueSource source, float slope, float intercept)
-	  {
-		this.source = source;
-		this.slope = slope;
-		this.intercept = intercept;
-	  }
+        public LinearFloatFunction(ValueSource source, float slope, float intercept)
+        {
+            this.source = source;
+            this.slope = slope;
+            this.intercept = intercept;
+        }
 
-	  public override string description()
-	  {
-		return slope + "*float(" + source.description() + ")+" + intercept;
-	  }
+        public override string Description
+        {
+            get { return slope + "*float(" + source.Description + ")+" + intercept; }
+        }
 
-//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.queries.function.FunctionValues vals = source.GetValues(context, readerContext);
-		FunctionValues vals = source.GetValues(context, readerContext);
-		return new FloatDocValuesAnonymousInnerClassHelper(this, this, vals);
-	  }
+        public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext)
+        {
+            FunctionValues vals = source.GetValues(context, readerContext);
+            return new FloatDocValuesAnonymousInnerClassHelper(this, this, vals);
+        }
 
-	  private class FloatDocValuesAnonymousInnerClassHelper : FloatDocValues
-	  {
-		  private readonly LinearFloatFunction outerInstance;
+        private class FloatDocValuesAnonymousInnerClassHelper : FloatDocValues
+        {
+            private readonly LinearFloatFunction outerInstance;
+            private readonly FunctionValues vals;
 
-		  private FunctionValues vals;
+            public FloatDocValuesAnonymousInnerClassHelper(LinearFloatFunction outerInstance, LinearFloatFunction @this, FunctionValues vals)
+                : base(@this)
+            {
+                this.outerInstance = outerInstance;
+                this.vals = vals;
+            }
 
-		  public FloatDocValuesAnonymousInnerClassHelper(LinearFloatFunction outerInstance, LinearFloatFunction this, FunctionValues vals) : base(this)
-		  {
-			  this.outerInstance = outerInstance;
-			  this.vals = vals;
-		  }
+            public override float FloatVal(int doc)
+            {
+                return vals.FloatVal(doc) * outerInstance.slope + outerInstance.intercept;
+            }
+            public override string ToString(int doc)
+            {
+                return outerInstance.slope + "*float(" + vals.ToString(doc) + ")+" + outerInstance.intercept;
+            }
+        }
 
-		  public override float FloatVal(int doc)
-		  {
-			return vals.FloatVal(doc) * outerInstance.slope + outerInstance.intercept;
-		  }
-		  public override string ToString(int doc)
-		  {
-			return outerInstance.slope + "*float(" + vals.ToString(doc) + ")+" + outerInstance.intercept;
-		  }
-	  }
+        public override void CreateWeight(IDictionary context, IndexSearcher searcher)
+        {
+            source.CreateWeight(context, searcher);
+        }
 
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: @Override public void CreateWeight(java.util.Map context, org.apache.lucene.search.IndexSearcher searcher) throws java.io.IOException
-	  public override void CreateWeight(IDictionary context, IndexSearcher searcher)
-	  {
-		source.CreateWeight(context, searcher);
-	  }
-
-	  public override int GetHashCode()
-	  {
-		int h = Number.FloatToIntBits(slope);
-		h = ((int)((uint)h >> 2)) | (h << 30);
-		h += Number.FloatToIntBits(intercept);
-		h ^= (h << 14) | ((int)((uint)h >> 19));
-		return h + source.GetHashCode();
-	  }
-
-	  public override bool Equals(object o)
-	  {
-		if (typeof(LinearFloatFunction) != o.GetType())
-		{
-			return false;
-		}
-		LinearFloatFunction other = (LinearFloatFunction)o;
-		return this.slope == other.slope && this.intercept == other.intercept && this.source.Equals(other.source);
-	  }
-	}
+        public override int GetHashCode()
+        {
+            int h = Number.FloatToIntBits(slope);
+            h = ((int)((uint)h >> 2)) | (h << 30);
+            h += Number.FloatToIntBits(intercept);
+            h ^= (h << 14) | ((int)((uint)h >> 19));
+            return h + source.GetHashCode();
+        }
 
+        public override bool Equals(object o)
+        {
+            var other = o as LinearFloatFunction;
+            if (other == null)
+                return false;
+            return this.slope == other.slope && this.intercept == other.intercept && this.source.Equals(other.source);
+        }
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Queries/Function/ValueSources/LiteralValueSource.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/LiteralValueSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/LiteralValueSource.cs
index 0b7bcea..451c613 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/LiteralValueSource.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/LiteralValueSource.cs
@@ -1,112 +1,107 @@
 using System.Collections;
+using Lucene.Net.Index;
 using Lucene.Net.Queries.Function.DocValues;
-using org.apache.lucene.queries.function;
+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>
-	/// Pass a the field value through as a String, no matter the type // Q: doesn't this mean it's a "string"?
-	/// 
-	/// 
-	/// </summary>
-	public class LiteralValueSource : ValueSource
-	{
-	  protected internal readonly string @string;
-	  protected internal readonly BytesRef bytesRef;
-
-	  public LiteralValueSource(string @string)
-	  {
-		this.@string = @string;
-		this.bytesRef = new BytesRef(@string);
-	  }
-
-	  /// <summary>
-	  /// returns the literal value </summary>
-	  public virtual string Value
-	  {
-		  get
-		  {
-			return @string;
-		  }
-	  }
-
-//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)
-	  {
-
-		return new StrDocValuesAnonymousInnerClassHelper(this, this);
-	  }
-
-	  private class StrDocValuesAnonymousInnerClassHelper : StrDocValues
-	  {
-		  private readonly LiteralValueSource outerInstance;
-
-		  public StrDocValuesAnonymousInnerClassHelper(LiteralValueSource outerInstance, LiteralValueSource this) : base(this)
-		  {
-			  this.outerInstance = outerInstance;
-		  }
-
-		  public override string StrVal(int doc)
-		  {
-			return outerInstance.@string;
-		  }
-
-		  public override bool bytesVal(int doc, BytesRef target)
-		  {
-			target.copyBytes(outerInstance.bytesRef);
-			return true;
-		  }
-
-		  public override string ToString(int doc)
-		  {
-			return outerInstance.@string;
-		  }
-	  }
-
-	  public override string description()
-	  {
-		return "literal(" + @string + ")";
-	  }
-
-	  public override bool Equals(object o)
-	  {
-		if (this == o)
-		{
-			return true;
-		}
-		if (!(o is LiteralValueSource))
-		{
-			return false;
-		}
-
-		LiteralValueSource that = (LiteralValueSource) o;
-
-		return @string.Equals(that.@string);
-
-	  }
-
-	  public static readonly int hash = typeof(LiteralValueSource).GetHashCode();
-	  public override int GetHashCode()
-	  {
-		return hash + @string.GetHashCode();
-	  }
-	}
-
+    /// Pass a the field value through as a String, no matter the type // Q: doesn't this mean it's a "str"?
+    /// 
+    /// 
+    /// </summary>
+    public class LiteralValueSource : ValueSource
+    {
+        protected readonly string str;
+        protected readonly BytesRef bytesRef;
+
+        public LiteralValueSource(string str)
+        {
+            this.str = str;
+            this.bytesRef = new BytesRef(str);
+        }
+
+        /// <summary>
+        /// returns the literal value </summary>
+        public virtual string Value
+        {
+            get
+            {
+                return str;
+            }
+        }
+
+        public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext)
+        {
+
+            return new StrDocValuesAnonymousInnerClassHelper(this, this);
+        }
+
+        private class StrDocValuesAnonymousInnerClassHelper : StrDocValues
+        {
+            private readonly LiteralValueSource outerInstance;
+
+            public StrDocValuesAnonymousInnerClassHelper(LiteralValueSource outerInstance, LiteralValueSource @this)
+                : base(@this)
+            {
+                this.outerInstance = outerInstance;
+            }
+
+            public override string StrVal(int doc)
+            {
+                return outerInstance.str;
+            }
+
+            public override bool BytesVal(int doc, BytesRef target)
+            {
+                target.CopyBytes(outerInstance.bytesRef);
+                return true;
+            }
+
+            public override string ToString(int doc)
+            {
+                return outerInstance.str;
+            }
+        }
+
+        public override string Description
+        {
+            get { return "literal(" + str + ")"; }
+        }
+
+        public override bool Equals(object o)
+        {
+            if (this == o)
+            {
+                return true;
+            }
+            var that = o as LiteralValueSource;
+            if (that == null)
+                return false;
+            return str.Equals(that.str);
+
+        }
+
+        public static readonly int hash = typeof(LiteralValueSource).GetHashCode();
+        public override int GetHashCode()
+        {
+            return hash + str.GetHashCode();
+        }
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Queries/Function/ValueSources/LongFieldSource.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/LongFieldSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/LongFieldSource.cs
index 9216c48..9e79096 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/LongFieldSource.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/LongFieldSource.cs
@@ -16,160 +16,159 @@
  */
 using System;
 using System.Collections;
+using Lucene.Net.Index;
 using Lucene.Net.Queries.Function.DocValues;
-using org.apache.lucene.queries.function;
+using Lucene.Net.Search;
+using Lucene.Net.Util;
+using Lucene.Net.Util.Mutable;
 
 namespace Lucene.Net.Queries.Function.ValueSources
 {
     /// <summary>
-	/// Obtains long field values from <seealso cref="FieldCache#getLongs"/> and makes those
-	/// values available as other numeric types, casting as needed.
-	/// </summary>
-	public class LongFieldSource : FieldCacheSource
-	{
-
-	  protected internal readonly FieldCache.LongParser parser;
-
-	  public LongFieldSource(string field) : this(field, null)
-	  {
-	  }
-
-	  public LongFieldSource(string field, FieldCache.LongParser parser) : base(field)
-	  {
-		this.parser = parser;
-	  }
-
-	  public override string description()
-	  {
-		return "long(" + field + ')';
-	  }
-
-	  public virtual long externalToLong(string extVal)
-	  {
-		return Convert.ToInt64(extVal);
-	  }
-
-	  public virtual object longToObject(long val)
-	  {
-		return val;
-	  }
-
-	  public virtual string longToString(long val)
-	  {
-		return longToObject(val).ToString();
-	  }
-
-//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.Longs arr = cache.getLongs(readerContext.reader(), field, parser, true);
-		FieldCache.Longs arr = cache.getLongs(readerContext.reader(), 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.reader(), field);
-
-		return new LongDocValuesAnonymousInnerClassHelper(this, this, arr, valid);
-	  }
-
-	  private class LongDocValuesAnonymousInnerClassHelper : LongDocValues
-	  {
-		  private readonly LongFieldSource outerInstance;
-
-		  private FieldCache.Longs arr;
-		  private Bits valid;
-
-		  public LongDocValuesAnonymousInnerClassHelper(LongFieldSource outerInstance, LongFieldSource this, FieldCache.Longs arr, Bits valid) : base(this)
-		  {
-			  this.outerInstance = outerInstance;
-			  this.arr = arr;
-			  this.valid = valid;
-		  }
-
-		  public override long LongVal(int doc)
-		  {
-			return arr.get(doc);
-		  }
-
-		  public override bool exists(int doc)
-		  {
-			return arr.get(doc) != 0 || valid.get(doc);
-		  }
-
-		  public override object objectVal(int doc)
-		  {
-			return valid.get(doc) ? outerInstance.longToObject(arr.get(doc)) : null;
-		  }
-
-		  public override string StrVal(int doc)
-		  {
-			return valid.get(doc) ? outerInstance.longToString(arr.get(doc)) : null;
-		  }
-
-		  protected internal override long externalToLong(string extVal)
-		  {
-			return outerInstance.externalToLong(extVal);
-		  }
-
-		  public override ValueFiller ValueFiller
-		  {
-			  get
-			  {
-				return new ValueFillerAnonymousInnerClassHelper(this);
-			  }
-		  }
-
-		  private class ValueFillerAnonymousInnerClassHelper : ValueFiller
-		  {
-			  private readonly LongDocValuesAnonymousInnerClassHelper outerInstance;
-
-			  public ValueFillerAnonymousInnerClassHelper(LongDocValuesAnonymousInnerClassHelper outerInstance)
-			  {
-				  this.outerInstance = outerInstance;
-				  mval = outerInstance.outerInstance.newMutableValueLong();
-			  }
-
-			  private readonly MutableValueLong mval;
-
-			  public override MutableValue Value
-			  {
-				  get
-				  {
-					return mval;
-				  }
-			  }
-
-			  public override void fillValue(int doc)
-			  {
-				mval.value = outerInstance.arr.get(doc);
-				mval.exists = mval.value != 0 || outerInstance.valid.get(doc);
-			  }
-		  }
-
-	  }
-
-	  protected internal virtual MutableValueLong newMutableValueLong()
-	  {
-		return new MutableValueLong();
-	  }
-
-	  public override bool Equals(object o)
-	  {
-		if (o.GetType() != this.GetType())
-		{
-			return false;
-		}
-		LongFieldSource other = (LongFieldSource) o;
-		return base.Equals(other) && (this.parser == null ? other.parser == null : this.parser.GetType() == other.parser.GetType());
-	  }
-
-	  public override int GetHashCode()
-	  {
-		int h = parser == null ? this.GetType().GetHashCode() : parser.GetType().GetHashCode();
-		h += base.GetHashCode();
-		return h;
-	  }
-	}
-
+    /// Obtains long field values from <seealso cref="FieldCache#getLongs"/> and makes those
+    /// values available as other numeric types, casting as needed.
+    /// </summary>
+    public class LongFieldSource : FieldCacheSource
+    {
+
+        protected readonly FieldCache.ILongParser parser;
+
+        public LongFieldSource(string field)
+            : this(field, null)
+        {
+        }
+
+        public LongFieldSource(string field, FieldCache.ILongParser parser)
+            : base(field)
+        {
+            this.parser = parser;
+        }
+
+        public override string Description
+        {
+            get { return "long(" + field + ')'; }
+        }
+
+        public virtual long ExternalToLong(string extVal)
+        {
+            return Convert.ToInt64(extVal);
+        }
+
+        public virtual object LongToObject(long val)
+        {
+            return val;
+        }
+
+        public virtual string LongToString(long val)
+        {
+            return LongToObject(val).ToString();
+        }
+
+        public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext)
+        {
+            var arr = cache.GetLongs(readerContext.AtomicReader, field, parser, true);
+            var valid = cache.GetDocsWithField(readerContext.AtomicReader, field);
+            return new LongDocValuesAnonymousInnerClassHelper(this, this, arr, valid);
+        }
+
+        private class LongDocValuesAnonymousInnerClassHelper : LongDocValues
+        {
+            private readonly LongFieldSource outerInstance;
+
+            private readonly FieldCache.Longs arr;
+            private readonly Bits valid;
+
+            public LongDocValuesAnonymousInnerClassHelper(LongFieldSource outerInstance, LongFieldSource @this, FieldCache.Longs arr, Bits valid)
+                : base(@this)
+            {
+                this.outerInstance = outerInstance;
+                this.arr = arr;
+                this.valid = valid;
+            }
+
+            public override long LongVal(int doc)
+            {
+                return arr.Get(doc);
+            }
+
+            public override bool Exists(int doc)
+            {
+                return arr.Get(doc) != 0 || valid.Get(doc);
+            }
+
+            public override object ObjectVal(int doc)
+            {
+                return valid.Get(doc) ? outerInstance.LongToObject(arr.Get(doc)) : null;
+            }
+
+            public override string StrVal(int doc)
+            {
+                return valid.Get(doc) ? outerInstance.LongToString(arr.Get(doc)) : null;
+            }
+
+            protected override long ExternalToLong(string extVal)
+            {
+                return outerInstance.ExternalToLong(extVal);
+            }
+
+            public override AbstractValueFiller ValueFiller
+            {
+                get
+                {
+                    return new ValueFillerAnonymousInnerClassHelper(this);
+                }
+            }
+
+            private class ValueFillerAnonymousInnerClassHelper : AbstractValueFiller
+            {
+                private readonly LongDocValuesAnonymousInnerClassHelper outerInstance;
+
+                public ValueFillerAnonymousInnerClassHelper(LongDocValuesAnonymousInnerClassHelper outerInstance)
+                {
+                    this.outerInstance = outerInstance;
+                    mval = outerInstance.outerInstance.NewMutableValueLong();
+                }
+
+                private readonly MutableValueLong mval;
+
+                public override MutableValue Value
+                {
+                    get
+                    {
+                        return mval;
+                    }
+                }
+
+                public override void FillValue(int doc)
+                {
+                    mval.Value = outerInstance.arr.Get(doc);
+                    mval.Exists = mval.Value != 0 || outerInstance.valid.Get(doc);
+                }
+            }
+        }
+
+        protected virtual MutableValueLong NewMutableValueLong()
+        {
+            return new MutableValueLong();
+        }
+
+        public override bool Equals(object o)
+        {
+            if (o.GetType() != this.GetType())
+            {
+                return false;
+            }
+            var other = o as LongFieldSource;
+            if (other == null)
+                return false;
+            return base.Equals(other) && (this.parser == null ? other.parser == null : this.parser.GetType() == other.parser.GetType());
+        }
+
+        public override int GetHashCode()
+        {
+            int h = parser == null ? this.GetType().GetHashCode() : parser.GetType().GetHashCode();
+            h += base.GetHashCode();
+            return h;
+        }
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Queries/Function/ValueSources/MaxDocValueSource.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/MaxDocValueSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/MaxDocValueSource.cs
index be0e939..a65dfcb 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/MaxDocValueSource.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/MaxDocValueSource.cs
@@ -15,54 +15,47 @@
  * limitations under the License.
  */
 using System.Collections;
-using org.apache.lucene.queries.function;
+using Lucene.Net.Index;
+using Lucene.Net.Search;
 
 namespace Lucene.Net.Queries.Function.ValueSources
 {
-    // javadocs
-
-
     /// <summary>
-	/// Returns the value of <seealso cref="IndexReader#maxDoc()"/>
-	/// for every document. This is the number of documents
-	/// including deletions.
-	/// </summary>
-	public class MaxDocValueSource : ValueSource
-	{
-	  public virtual string name()
-	  {
-		return "maxdoc";
-	  }
-
-	  public override string description()
-	  {
-		return name() + "()";
-	  }
-
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: @Override public void CreateWeight(java.util.Map context, org.apache.lucene.search.IndexSearcher searcher) throws java.io.IOException
-	  public override void CreateWeight(IDictionary context, IndexSearcher searcher)
-	  {
-		context["searcher"] = searcher;
-	  }
-
-//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)
-	  {
-		IndexSearcher searcher = (IndexSearcher)context["searcher"];
-		return new ConstIntDocValues(searcher.IndexReader.maxDoc(), this);
-	  }
-
-	  public override bool Equals(object o)
-	  {
-		return this.GetType() == o.GetType();
-	  }
-
-	  public override int GetHashCode()
-	  {
-		return this.GetType().GetHashCode();
-	  }
-	}
-
+    /// Returns the value of <seealso cref="IndexReader#maxDoc()"/>
+    /// for every document. This is the number of documents
+    /// including deletions.
+    /// </summary>
+    public class MaxDocValueSource : ValueSource
+    {
+        public virtual string Name
+        {
+            get { return "maxdoc"; }
+        }
+
+        public override string Description
+        {
+            get { return Name + "()"; }
+        }
+
+        public override void CreateWeight(IDictionary context, IndexSearcher searcher)
+        {
+            context["searcher"] = searcher;
+        }
+
+        public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext)
+        {
+            var searcher = (IndexSearcher)context["searcher"];
+            return new ConstIntDocValues(searcher.IndexReader.MaxDoc, this);
+        }
+
+        public override bool Equals(object o)
+        {
+            return this.GetType() == o.GetType();
+        }
+
+        public override int GetHashCode()
+        {
+            return this.GetType().GetHashCode();
+        }
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Queries/Function/ValueSources/MaxFloatFunction.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/MaxFloatFunction.cs b/src/Lucene.Net.Queries/Function/ValueSources/MaxFloatFunction.cs
index 417c4ba..6e6126c 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/MaxFloatFunction.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/MaxFloatFunction.cs
@@ -15,39 +15,36 @@
  * limitations under the License.
  */
 using System;
-using org.apache.lucene.queries.function;
 
 namespace Lucene.Net.Queries.Function.ValueSources
 {
+    /// <summary>
+    /// <code>MaxFloatFunction</code> returns the max of it's components.
+    /// </summary>
+    public class MaxFloatFunction : MultiFloatFunction
+    {
+        public MaxFloatFunction(ValueSource[] sources)
+            : base(sources)
+        {
+        }
 
+        protected override string Name
+        {
+            get { return "max"; }
+        }
 
-	/// <summary>
-	/// <code>MaxFloatFunction</code> returns the max of it's components.
-	/// </summary>
-	public class MaxFloatFunction : MultiFloatFunction
-	{
-	  public MaxFloatFunction(ValueSource[] sources) : base(sources)
-	  {
-	  }
-
-	  protected internal override string name()
-	  {
-		return "max";
-	  }
-
-	  protected internal override float func(int doc, FunctionValues[] valsArr)
-	  {
-		if (valsArr.Length == 0)
-		{
-			return 0.0f;
-		}
-		float val = float.NegativeInfinity;
-		foreach (FunctionValues vals in valsArr)
-		{
-		  val = Math.Max(vals.FloatVal(doc), val);
-		}
-		return val;
-	  }
-	}
-
+        protected override float Func(int doc, FunctionValues[] valsArr)
+        {
+            if (valsArr.Length == 0)
+            {
+                return 0.0f;
+            }
+            float val = float.NegativeInfinity;
+            foreach (FunctionValues vals in valsArr)
+            {
+                val = Math.Max(vals.FloatVal(doc), val);
+            }
+            return val;
+        }
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Queries/Function/ValueSources/MinFloatFunction.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/MinFloatFunction.cs b/src/Lucene.Net.Queries/Function/ValueSources/MinFloatFunction.cs
index 9457ee1..3284b44 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/MinFloatFunction.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/MinFloatFunction.cs
@@ -15,39 +15,36 @@
  * limitations under the License.
  */
 using System;
-using org.apache.lucene.queries.function;
 
 namespace Lucene.Net.Queries.Function.ValueSources
 {
+    /// <summary>
+    /// <code>MinFloatFunction</code> returns the min of it's components.
+    /// </summary>
+    public class MinFloatFunction : MultiFloatFunction
+    {
+        public MinFloatFunction(ValueSource[] sources)
+            : base(sources)
+        {
+        }
 
+        protected override string Name
+        {
+            get { return "min"; }
+        }
 
-	/// <summary>
-	/// <code>MinFloatFunction</code> returns the min of it's components.
-	/// </summary>
-	public class MinFloatFunction : MultiFloatFunction
-	{
-	  public MinFloatFunction(ValueSource[] sources) : base(sources)
-	  {
-	  }
-
-	  protected internal override string name()
-	  {
-		return "min";
-	  }
-
-	  protected internal override float func(int doc, FunctionValues[] valsArr)
-	  {
-		if (valsArr.Length == 0)
-		{
-			return 0.0f;
-		}
-		float val = float.PositiveInfinity;
-		foreach (FunctionValues vals in valsArr)
-		{
-		  val = Math.Min(vals.FloatVal(doc), val);
-		}
-		return val;
-	  }
-	}
-
+        protected override float Func(int doc, FunctionValues[] valsArr)
+        {
+            if (valsArr.Length == 0)
+            {
+                return 0.0f;
+            }
+            float val = float.PositiveInfinity;
+            foreach (FunctionValues vals in valsArr)
+            {
+                val = Math.Min(vals.FloatVal(doc), val);
+            }
+            return val;
+        }
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Queries/Function/ValueSources/MultiBoolFunction.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/MultiBoolFunction.cs b/src/Lucene.Net.Queries/Function/ValueSources/MultiBoolFunction.cs
index 7e44df3..e938720 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/MultiBoolFunction.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/MultiBoolFunction.cs
@@ -17,127 +17,127 @@
 using System.Collections;
 using System.Collections.Generic;
 using System.Text;
+using Lucene.Net.Index;
 using Lucene.Net.Queries.Function.DocValues;
-using org.apache.lucene.queries.function;
+using Lucene.Net.Search;
 
 namespace Lucene.Net.Queries.Function.ValueSources
 {
     /// <summary>
-	/// Abstract <seealso cref="ValueSource"/> implementation which wraps multiple ValueSources
-	/// and applies an extendible boolean function to their values.
-	/// 
-	/// </summary>
-	public abstract class MultiBoolFunction : BoolFunction
-	{
-	  protected internal readonly IList<ValueSource> sources;
-
-	  public MultiBoolFunction(IList<ValueSource> sources)
-	  {
-		this.sources = sources;
-	  }
-
-	  protected internal abstract string name();
-
-	  protected internal abstract bool func(int doc, FunctionValues[] vals);
-
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: @Override public org.apache.lucene.queries.function.docvalues.BoolDocValues GetValues(java.util.Map context, org.apache.lucene.index.AtomicReaderContext readerContext) throws java.io.IOException
-	  public override BoolDocValues GetValues(IDictionary context, AtomicReaderContext readerContext)
-	  {
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final org.apache.lucene.queries.function.FunctionValues[] vals = new org.apache.lucene.queries.function.FunctionValues[sources.size()];
-		FunctionValues[] vals = new FunctionValues[sources.Count];
-		int i = 0;
-		foreach (ValueSource source in sources)
-		{
-		  vals[i++] = source.GetValues(context, readerContext);
-		}
-
-		return new BoolDocValuesAnonymousInnerClassHelper(this, this, vals);
-	  }
-
-	  private class BoolDocValuesAnonymousInnerClassHelper : BoolDocValues
-	  {
-		  private readonly MultiBoolFunction outerInstance;
-
-		  private FunctionValues[] vals;
-
-		  public BoolDocValuesAnonymousInnerClassHelper(MultiBoolFunction outerInstance, MultiBoolFunction this, FunctionValues[] vals) : base(this)
-		  {
-			  this.outerInstance = outerInstance;
-			  this.vals = vals;
-		  }
-
-		  public override bool boolVal(int doc)
-		  {
-			return outerInstance.func(doc, vals);
-		  }
-
-		  public override string ToString(int doc)
-		  {
-			StringBuilder sb = new StringBuilder(outerInstance.name());
-			sb.Append('(');
-			bool first = true;
-			foreach (FunctionValues dv in vals)
-			{
-			  if (first)
-			  {
-				first = false;
-			  }
-			  else
-			  {
-				sb.Append(',');
-			  }
-			  sb.Append(dv.ToString(doc));
-			}
-			return sb.ToString();
-		  }
-	  }
-
-	  public override string description()
-	  {
-		StringBuilder sb = new StringBuilder(name());
-		sb.Append('(');
-		bool first = true;
-		foreach (ValueSource source in sources)
-		{
-		  if (first)
-		  {
-			first = false;
-		  }
-		  else
-		  {
-			sb.Append(',');
-		  }
-		  sb.Append(source.description());
-		}
-		return sb.ToString();
-	  }
-
-	  public override int GetHashCode()
-	  {
-		return sources.GetHashCode() + name().GetHashCode();
-	  }
-
-	  public override bool Equals(object o)
-	  {
-		if (this.GetType() != o.GetType())
-		{
-			return false;
-		}
-		MultiBoolFunction other = (MultiBoolFunction)o;
-		return this.sources.Equals(other.sources);
-	  }
-
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: @Override public void CreateWeight(java.util.Map context, org.apache.lucene.search.IndexSearcher searcher) throws java.io.IOException
-	  public override void CreateWeight(IDictionary context, IndexSearcher searcher)
-	  {
-		foreach (ValueSource source in sources)
-		{
-		  source.CreateWeight(context, searcher);
-		}
-	  }
-	}
-
+    /// Abstract <seealso cref="ValueSource"/> implementation which wraps multiple ValueSources
+    /// and applies an extendible boolean function to their values.
+    /// 
+    /// </summary>
+    public abstract class MultiBoolFunction : BoolFunction
+    {
+        protected readonly IList<ValueSource> sources;
+
+        protected MultiBoolFunction(IList<ValueSource> sources)
+        {
+            this.sources = sources;
+        }
+
+        protected abstract string Name { get; }
+
+        protected abstract bool Func(int doc, FunctionValues[] vals);
+
+        public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext)
+        {
+            var vals = new FunctionValues[sources.Count];
+            int i = 0;
+            foreach (ValueSource source in sources)
+            {
+                vals[i++] = source.GetValues(context, readerContext);
+            }
+
+            return new BoolDocValuesAnonymousInnerClassHelper(this, this, vals);
+        }
+
+        private class BoolDocValuesAnonymousInnerClassHelper : BoolDocValues
+        {
+            private readonly MultiBoolFunction outerInstance;
+
+            private readonly FunctionValues[] vals;
+
+            public BoolDocValuesAnonymousInnerClassHelper(MultiBoolFunction outerInstance, MultiBoolFunction @this, FunctionValues[] vals)
+                : base(@this)
+            {
+                this.outerInstance = outerInstance;
+                this.vals = vals;
+            }
+
+            public override bool BoolVal(int doc)
+            {
+                return outerInstance.Func(doc, vals);
+            }
+
+            public override string ToString(int doc)
+            {
+                var sb = new StringBuilder(outerInstance.Name);
+                sb.Append('(');
+                bool first = true;
+                foreach (FunctionValues dv in vals)
+                {
+                    if (first)
+                    {
+                        first = false;
+                    }
+                    else
+                    {
+                        sb.Append(',');
+                    }
+                    sb.Append(dv.ToString(doc));
+                }
+                return sb.ToString();
+            }
+        }
+
+        public override string Description
+        {
+            get
+            {
+                var sb = new StringBuilder(Name);
+                sb.Append('(');
+                bool first = true;
+                foreach (ValueSource source in sources)
+                {
+                    if (first)
+                    {
+                        first = false;
+                    }
+                    else
+                    {
+                        sb.Append(',');
+                    }
+                    sb.Append(source.Description);
+                }
+                return sb.ToString();
+            }
+        }
+
+        public override int GetHashCode()
+        {
+            return sources.GetHashCode() + Name.GetHashCode();
+        }
+
+        public override bool Equals(object o)
+        {
+            if (this.GetType() != o.GetType())
+            {
+                return false;
+            }
+            var other = o as MultiBoolFunction;
+            if (other == null)
+                return false;
+            return this.sources.Equals(other.sources);
+        }
+
+        public override void CreateWeight(IDictionary context, IndexSearcher searcher)
+        {
+            foreach (ValueSource source in sources)
+            {
+                source.CreateWeight(context, searcher);
+            }
+        }
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Queries/Function/ValueSources/MultiFloatFunction.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/MultiFloatFunction.cs b/src/Lucene.Net.Queries/Function/ValueSources/MultiFloatFunction.cs
index 98678c9..5445847 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/MultiFloatFunction.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/MultiFloatFunction.cs
@@ -1,140 +1,143 @@
 using System.Collections;
 using System.Text;
+using Lucene.Net.Index;
 using Lucene.Net.Queries.Function.DocValues;
+using Lucene.Net.Search;
+using Lucene.Net.Support;
 
 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>
-	/// Abstract <seealso cref="ValueSource"/> implementation which wraps multiple ValueSources
-	/// and applies an extendible float function to their values.
-	/// 
-	/// </summary>
-	public abstract class MultiFloatFunction : ValueSource
-	{
-	  protected internal readonly ValueSource[] sources;
+    /// Abstract <seealso cref="ValueSource"/> implementation which wraps multiple ValueSources
+    /// and applies an extendible float function to their values.
+    /// 
+    /// </summary>
+    public abstract class MultiFloatFunction : ValueSource
+    {
+        protected internal readonly ValueSource[] sources;
 
-	  public MultiFloatFunction(ValueSource[] sources)
-	  {
-		this.sources = sources;
-	  }
+        protected MultiFloatFunction(ValueSource[] sources)
+        {
+            this.sources = sources;
+        }
 
-	  protected internal abstract string name();
-	  protected internal abstract float func(int doc, FunctionValues[] valsArr);
+        protected abstract string Name { get; }
 
-	  public override string description()
-	  {
-		StringBuilder sb = new StringBuilder();
-		sb.Append(name()).Append('(');
-		bool firstTime = true;
-		foreach (ValueSource source in sources)
-		{
-		  if (firstTime)
-		  {
-			firstTime = false;
-		  }
-		  else
-		  {
-			sb.Append(',');
-		  }
-		  sb.Append((object) source);
-		}
-		sb.Append(')');
-		return sb.ToString();
-	  }
+        protected abstract float Func(int doc, FunctionValues[] valsArr);
 
-//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.queries.function.FunctionValues[] valsArr = new org.apache.lucene.queries.function.FunctionValues[sources.length];
-		FunctionValues[] valsArr = new FunctionValues[sources.Length];
-		for (int i = 0; i < sources.Length; i++)
-		{
-		  valsArr[i] = sources[i].GetValues(context, readerContext);
-		}
+        public override string Description
+        {
+            get
+            {
+                var sb = new StringBuilder();
+                sb.Append(Name).Append('(');
+                bool firstTime = true;
+                foreach (var source in sources)
+                {
+                    if (firstTime)
+                    {
+                        firstTime = false;
+                    }
+                    else
+                    {
+                        sb.Append(',');
+                    }
+                    sb.Append(source);
+                }
+                sb.Append(')');
+                return sb.ToString();
+            }
+        }
 
-		return new FloatDocValuesAnonymousInnerClassHelper(this, this, valsArr);
-	  }
+        public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext)
+        {
+            var valsArr = new FunctionValues[sources.Length];
+            for (int i = 0; i < sources.Length; i++)
+            {
+                valsArr[i] = sources[i].GetValues(context, readerContext);
+            }
 
-	  private class FloatDocValuesAnonymousInnerClassHelper : FloatDocValues
-	  {
-		  private readonly MultiFloatFunction outerInstance;
+            return new FloatDocValuesAnonymousInnerClassHelper(this, this, valsArr);
+        }
 
-		  private FunctionValues[] valsArr;
+        private class FloatDocValuesAnonymousInnerClassHelper : FloatDocValues
+        {
+            private readonly MultiFloatFunction outerInstance;
 
-		  public FloatDocValuesAnonymousInnerClassHelper(MultiFloatFunction outerInstance, MultiFloatFunction this, FunctionValues[] valsArr) : base(this)
-		  {
-			  this.outerInstance = outerInstance;
-			  this.valsArr = valsArr;
-		  }
+            private readonly FunctionValues[] valsArr;
 
-		  public override float FloatVal(int doc)
-		  {
-			return outerInstance.func(doc, valsArr);
-		  }
-		   public override string ToString(int doc)
-		   {
-			StringBuilder sb = new StringBuilder();
-			sb.Append(outerInstance.name()).Append('(');
-			bool firstTime = true;
-			foreach (FunctionValues vals in valsArr)
-			{
-			  if (firstTime)
-			  {
-				firstTime = false;
-			  }
-			  else
-			  {
-				sb.Append(',');
-			  }
-			  sb.Append(vals.ToString(doc));
-			}
-			sb.Append(')');
-			return sb.ToString();
-		   }
-	  }
+            public FloatDocValuesAnonymousInnerClassHelper(MultiFloatFunction outerInstance, MultiFloatFunction @this, FunctionValues[] valsArr)
+                : base(@this)
+            {
+                this.outerInstance = outerInstance;
+                this.valsArr = valsArr;
+            }
 
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: @Override public void CreateWeight(java.util.Map context, org.apache.lucene.search.IndexSearcher searcher) throws java.io.IOException
-	  public override void CreateWeight(IDictionary context, IndexSearcher searcher)
-	  {
-		foreach (ValueSource source in sources)
-		{
-		  source.CreateWeight(context, searcher);
-		}
-	  }
+            public override float FloatVal(int doc)
+            {
+                return outerInstance.Func(doc, valsArr);
+            }
+            public override string ToString(int doc)
+            {
+                var sb = new StringBuilder();
+                sb.Append(outerInstance.Name).Append('(');
+                bool firstTime = true;
+                foreach (FunctionValues vals in valsArr)
+                {
+                    if (firstTime)
+                    {
+                        firstTime = false;
+                    }
+                    else
+                    {
+                        sb.Append(',');
+                    }
+                    sb.Append(vals.ToString(doc));
+                }
+                sb.Append(')');
+                return sb.ToString();
+            }
+        }
 
-	  public override int GetHashCode()
-	  {
-		return Arrays.GetHashCode(sources) + name().GetHashCode();
-	  }
+        public override void CreateWeight(IDictionary context, IndexSearcher searcher)
+        {
+            foreach (ValueSource source in sources)
+            {
+                source.CreateWeight(context, searcher);
+            }
+        }
 
-	  public override bool Equals(object o)
-	  {
-		if (this.GetType() != o.GetType())
-		{
-			return false;
-		}
-		MultiFloatFunction other = (MultiFloatFunction)o;
-		return this.name().Equals(other.name()) && Arrays.Equals(this.sources, other.sources);
-	  }
-	}
+        public override int GetHashCode()
+        {
+            return Arrays.GetHashCode(sources) + Name.GetHashCode();
+        }
 
+        public override bool Equals(object o)
+        {
+            if (this.GetType() != o.GetType())
+            {
+                return false;
+            }
+            var other = o as MultiFloatFunction;
+            if (other == null)
+                return false;
+            return Name.Equals(other.Name) && Arrays.Equals(this.sources, other.sources);
+        }
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Queries/Function/ValueSources/MultiFunction.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/MultiFunction.cs b/src/Lucene.Net.Queries/Function/ValueSources/MultiFunction.cs
index e45c77f..3351701 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/MultiFunction.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/MultiFunction.cs
@@ -30,7 +30,7 @@ namespace Lucene.Net.Queries.Function.ValueSources
     {
         protected internal readonly IList<ValueSource> sources;
 
-        public MultiFunction(IList<ValueSource> sources)
+        protected MultiFunction(IList<ValueSource> sources)
         {
             this.sources = sources;
         }
@@ -44,7 +44,7 @@ namespace Lucene.Net.Queries.Function.ValueSources
 
         public static string GetDescription(string name, IList<ValueSource> sources)
         {
-            StringBuilder sb = new StringBuilder();
+            var sb = new StringBuilder();
             sb.Append(name).Append('(');
             bool firstTime = true;
             foreach (ValueSource source in sources)
@@ -95,7 +95,7 @@ namespace Lucene.Net.Queries.Function.ValueSources
 
         public static string ToString(string name, FunctionValues[] valsArr, int doc)
         {
-            StringBuilder sb = new StringBuilder();
+            var sb = new StringBuilder();
             sb.Append(name).Append('(');
             bool firstTime = true;
             foreach (FunctionValues vals in valsArr)

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Queries/Function/ValueSources/MultiValueSource.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/MultiValueSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/MultiValueSource.cs
index 215d74e..72e4781 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/MultiValueSource.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/MultiValueSource.cs
@@ -25,8 +25,6 @@
 	/// </summary>
 	public abstract class MultiValueSource : ValueSource
 	{
-
-	  public abstract int dimension();
+        public abstract int Dimension { get; }
 	}
-
 }
\ No newline at end of file


[2/4] More work on Lucene.Net.Queries

Posted by sy...@apache.org.
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Queries/Function/ValueSources/NormValueSource.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/NormValueSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/NormValueSource.cs
index a948905..56edfbd 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/NormValueSource.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/NormValueSource.cs
@@ -15,104 +15,97 @@
  * limitations under the License.
  */
 using System.Collections;
+using Lucene.Net.Index;
 using Lucene.Net.Queries.Function.DocValues;
-using org.apache.lucene.queries.function;
+using Lucene.Net.Search;
+using Lucene.Net.Search.Similarities;
 
 namespace Lucene.Net.Queries.Function.ValueSources
 {
     /// <summary>
-	/// Function that returns <seealso cref="TFIDFSimilarity#decodeNormValue(long)"/>
-	/// 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 NormValueSource : ValueSource
-	{
-	  protected internal readonly string field;
-	  public NormValueSource(string field)
-	  {
-		this.field = field;
-	  }
-
-	  public virtual string name()
-	  {
-		return "norm";
-	  }
-
-	  public override string description()
-	  {
-		return name() + '(' + field + ')';
-	  }
-
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: @Override public void CreateWeight(java.util.Map context, org.apache.lucene.search.IndexSearcher searcher) throws java.io.IOException
-	  public override void CreateWeight(IDictionary context, IndexSearcher searcher)
-	  {
-		context["searcher"] = searcher;
-	  }
-
-//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)
-	  {
-		IndexSearcher searcher = (IndexSearcher)context["searcher"];
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final org.apache.lucene.search.similarities.TFIDFSimilarity similarity = IDFValueSource.asTFIDF(searcher.getSimilarity(), field);
-		TFIDFSimilarity similarity = IDFValueSource.asTFIDF(searcher.Similarity, field);
-		if (similarity == null)
-		{
-		  throw new System.NotSupportedException("requires a TFIDFSimilarity (such as DefaultSimilarity)");
-		}
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final org.apache.lucene.index.NumericDocValues norms = readerContext.reader().getNormValues(field);
-		NumericDocValues norms = readerContext.reader().getNormValues(field);
-
-		if (norms == null)
-		{
-		  return new ConstDoubleDocValues(0.0, this);
-		}
-
-		return new FloatDocValuesAnonymousInnerClassHelper(this, this, similarity, norms);
-	  }
-
-	  private class FloatDocValuesAnonymousInnerClassHelper : FloatDocValues
-	  {
-		  private readonly NormValueSource outerInstance;
-
-		  private TFIDFSimilarity similarity;
-		  private NumericDocValues norms;
-
-		  public FloatDocValuesAnonymousInnerClassHelper(NormValueSource outerInstance, NormValueSource this, TFIDFSimilarity similarity, NumericDocValues norms) : base(this)
-		  {
-			  this.outerInstance = outerInstance;
-			  this.similarity = similarity;
-			  this.norms = norms;
-		  }
-
-		  public override float FloatVal(int doc)
-		  {
-			return similarity.decodeNormValue(norms.get(doc));
-		  }
-	  }
-
-	  public override bool Equals(object o)
-	  {
-		if (this.GetType() != o.GetType())
-		{
-		  return false;
-		}
-		return this.field.Equals(((NormValueSource)o).field);
-	  }
-
-	  public override int GetHashCode()
-	  {
-		return this.GetType().GetHashCode() + field.GetHashCode();
-	  }
-	}
-
-
-
+    /// Function that returns <seealso cref="TFIDFSimilarity#decodeNormValue(long)"/>
+    /// 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 NormValueSource : ValueSource
+    {
+        protected internal readonly string field;
+
+        public NormValueSource(string field)
+        {
+            this.field = field;
+        }
+
+        public virtual string Name
+        {
+            get { return "norm"; }
+        }
+
+        public override string Description
+        {
+            get { return Name + '(' + field + ')'; }
+        }
+
+        public override void CreateWeight(IDictionary context, IndexSearcher searcher)
+        {
+            context["searcher"] = searcher;
+        }
+
+        public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext)
+        {
+            var searcher = (IndexSearcher)context["searcher"];
+            TFIDFSimilarity similarity = IDFValueSource.AsTFIDF(searcher.Similarity, field);
+            if (similarity == null)
+            {
+                throw new System.NotSupportedException("requires a TFIDFSimilarity (such as DefaultSimilarity)");
+            }
+
+            NumericDocValues norms = readerContext.AtomicReader.GetNormValues(field);
+            if (norms == null)
+            {
+                return new ConstDoubleDocValues(0.0, this);
+            }
+
+            return new FloatDocValuesAnonymousInnerClassHelper(this, this, similarity, norms);
+        }
+
+        private class FloatDocValuesAnonymousInnerClassHelper : FloatDocValues
+        {
+            private readonly NormValueSource outerInstance;
+
+            private readonly TFIDFSimilarity similarity;
+            private readonly NumericDocValues norms;
+
+            public FloatDocValuesAnonymousInnerClassHelper(NormValueSource outerInstance, NormValueSource @this, TFIDFSimilarity similarity, NumericDocValues norms)
+                : base(@this)
+            {
+                this.outerInstance = outerInstance;
+                this.similarity = similarity;
+                this.norms = norms;
+            }
+
+            public override float FloatVal(int doc)
+            {
+                return similarity.DecodeNormValue(norms.Get(doc));
+            }
+        }
+
+        public override bool Equals(object o)
+        {
+            if (this.GetType() != o.GetType())
+            {
+                return false;
+            }
+            return this.field.Equals(((NormValueSource)o).field);
+        }
+
+        public override int GetHashCode()
+        {
+            return this.GetType().GetHashCode() + field.GetHashCode();
+        }
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Queries/Function/ValueSources/NumDocsValueSource.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/NumDocsValueSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/NumDocsValueSource.cs
index ea30074..6d59703 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/NumDocsValueSource.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/NumDocsValueSource.cs
@@ -16,44 +16,40 @@
  */
 using System.Collections;
 using Lucene.Net.Index;
-using org.apache.lucene.queries.function;
 
 namespace Lucene.Net.Queries.Function.ValueSources
 {
     /// <summary>
-	/// Returns the value of <seealso cref="IndexReader#numDocs()"/>
-	/// for every document. This is the number of documents
-	/// excluding deletions.
-	/// </summary>
-	public class NumDocsValueSource : ValueSource
-	{
-	  public virtual string name()
-	  {
-		return "numdocs";
-	  }
+    /// Returns the value of <seealso cref="IndexReader#numDocs()"/>
+    /// for every document. This is the number of documents
+    /// excluding deletions.
+    /// </summary>
+    public class NumDocsValueSource : ValueSource
+    {
+        public virtual string Name
+        {
+            get { return "numdocs"; }
+        }
 
-	  public override string description()
-	  {
-		return name() + "()";
-	  }
+        public override string Description
+        {
+            get { return Name + "()"; }
+        }
 
-//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)
-	  {
-		// Searcher has no numdocs so we must use the reader instead
-		return new ConstIntDocValues(ReaderUtil.getTopLevelContext(readerContext).reader().numDocs(), this);
-	  }
+        public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext)
+        {
+            // Searcher has no numdocs so we must use the reader instead
+            return new ConstIntDocValues(ReaderUtil.GetTopLevelContext(readerContext).Reader.NumDocs, this);
+        }
 
-	  public override bool Equals(object o)
-	  {
-		return this.GetType() == o.GetType();
-	  }
-
-	  public override int GetHashCode()
-	  {
-		return this.GetType().GetHashCode();
-	  }
-	}
+        public override bool Equals(object o)
+        {
+            return this.GetType() == o.GetType();
+        }
 
+        public override int GetHashCode()
+        {
+            return this.GetType().GetHashCode();
+        }
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Queries/Function/ValueSources/OrdFieldSource.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/OrdFieldSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/OrdFieldSource.cs
index 8a46432..93eecab 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/OrdFieldSource.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/OrdFieldSource.cs
@@ -15,148 +15,140 @@
  * limitations under the License.
  */
 using System.Collections;
+using Lucene.Net.Index;
 using Lucene.Net.Queries.Function.DocValues;
-using org.apache.lucene.queries.function;
+using Lucene.Net.Search;
+using Lucene.Net.Util.Mutable;
 
 namespace Lucene.Net.Queries.Function.ValueSources
 {
     /// <summary>
-	/// Obtains the ordinal of the field value from the default Lucene <seealso cref="org.apache.lucene.search.FieldCache"/> using getStringIndex().
-	/// <br>
-	/// The native lucene index order is used to assign an ordinal value for each field value.
-	/// <br>Field values (terms) are lexicographically ordered by unicode value, and numbered starting at 1.
-	/// <br>
-	/// Example:<br>
-	///  If there were only three field values: "apple","banana","pear"
-	/// <br>then ord("apple")=1, ord("banana")=2, ord("pear")=3
-	/// <para>
-	/// WARNING: ord() depends on the position in an index and can thus change when other documents are inserted or deleted,
-	///  or if a MultiSearcher is used.
-	/// <br>WARNING: as of Solr 1.4, ord() and rord() can cause excess memory use since they must use a FieldCache entry
-	/// at the top level reader, while sorting and function queries now use entries at the segment level.  Hence sorting
-	/// or using a different function query, in addition to ord()/rord() will double memory use.
-	/// 
-	/// </para>
-	/// </summary>
-
-	public class OrdFieldSource : ValueSource
-	{
-	  protected internal readonly string field;
-
-	  public OrdFieldSource(string field)
-	  {
-		this.field = field;
-	  }
-
-	  public override string description()
-	  {
-		return "ord(" + field + ')';
-	  }
-
-
-	  // TODO: this is trappy? perhaps this query instead should make you pass a slow reader yourself?
-//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 int off = readerContext.docBase;
-		int off = readerContext.docBase;
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final org.apache.lucene.index.IndexReader topReader = org.apache.lucene.index.ReaderUtil.getTopLevelContext(readerContext).reader();
-		IndexReader topReader = ReaderUtil.getTopLevelContext(readerContext).reader();
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final org.apache.lucene.index.AtomicReader r = org.apache.lucene.index.SlowCompositeReaderWrapper.wrap(topReader);
-		AtomicReader r = SlowCompositeReaderWrapper.wrap(topReader);
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final org.apache.lucene.index.SortedDocValues sindex = org.apache.lucene.search.FieldCache.DEFAULT.getTermsIndex(r, field);
-		SortedDocValues sindex = FieldCache.DEFAULT.getTermsIndex(r, field);
-		return new IntDocValuesAnonymousInnerClassHelper(this, this, off, sindex);
-	  }
-
-	  private class IntDocValuesAnonymousInnerClassHelper : IntDocValues
-	  {
-		  private readonly OrdFieldSource outerInstance;
-
-		  private int off;
-		  private SortedDocValues sindex;
-
-		  public IntDocValuesAnonymousInnerClassHelper(OrdFieldSource outerInstance, OrdFieldSource this, int off, SortedDocValues sindex) : base(this)
-		  {
-			  this.outerInstance = outerInstance;
-			  this.off = off;
-			  this.sindex = sindex;
-		  }
-
-		  protected internal virtual string toTerm(string readableValue)
-		  {
-			return readableValue;
-		  }
-		  public override int intVal(int doc)
-		  {
-			return sindex.getOrd(doc + off);
-		  }
-		  public override int ordVal(int doc)
-		  {
-			return sindex.getOrd(doc + off);
-		  }
-		  public override int numOrd()
-		  {
-			return sindex.ValueCount;
-		  }
-
-		  public override bool exists(int doc)
-		  {
-			return sindex.getOrd(doc + off) != 0;
-		  }
-
-		  public override ValueFiller ValueFiller
-		  {
-			  get
-			  {
-				return new ValueFillerAnonymousInnerClassHelper(this);
-			  }
-		  }
-
-		  private class ValueFillerAnonymousInnerClassHelper : ValueFiller
-		  {
-			  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.sindex.getOrd(doc);
-				mval.exists = mval.value != 0;
-			  }
-		  }
-	  }
-
-	  public override bool Equals(object o)
-	  {
-		return o != null && o.GetType() == typeof(OrdFieldSource) && this.field.Equals(((OrdFieldSource)o).field);
-	  }
-
-	  private static readonly int hcode = typeof(OrdFieldSource).GetHashCode();
-	  public override int GetHashCode()
-	  {
-		return hcode + field.GetHashCode();
-	  }
-
-	}
-
+    /// Obtains the ordinal of the field value from the default Lucene <seealso cref="FieldCache"/> using getStringIndex().
+    /// <br>
+    /// The native lucene index order is used to assign an ordinal value for each field value.
+    /// <br>Field values (terms) are lexicographically ordered by unicode value, and numbered starting at 1.
+    /// <br>
+    /// Example:<br>
+    ///  If there were only three field values: "apple","banana","pear"
+    /// <br>then ord("apple")=1, ord("banana")=2, ord("pear")=3
+    /// <para>
+    /// WARNING: ord() depends on the position in an index and can thus change when other documents are inserted or deleted,
+    ///  or if a MultiSearcher is used.
+    /// <br>WARNING: as of Solr 1.4, ord() and rord() can cause excess memory use since they must use a FieldCache entry
+    /// at the top level reader, while sorting and function queries now use entries at the segment level.  Hence sorting
+    /// or using a different function query, in addition to ord()/rord() will double memory use.
+    /// 
+    /// </para>
+    /// </summary>
+
+    public class OrdFieldSource : ValueSource
+    {
+        protected readonly string field;
+
+        public OrdFieldSource(string field)
+        {
+            this.field = field;
+        }
+
+        public override string Description
+        {
+            get { return "ord(" + field + ')'; }
+        }
+
+
+        // TODO: this is trappy? perhaps this query instead should make you pass a slow reader yourself?
+        public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext)
+        {
+            int off = readerContext.DocBase;
+            IndexReader topReader = ReaderUtil.GetTopLevelContext(readerContext).Reader;
+            AtomicReader r = SlowCompositeReaderWrapper.Wrap(topReader);
+            SortedDocValues sindex = FieldCache.DEFAULT.GetTermsIndex(r, field);
+            return new IntDocValuesAnonymousInnerClassHelper(this, this, off, sindex);
+        }
+
+        private class IntDocValuesAnonymousInnerClassHelper : IntDocValues
+        {
+            private readonly OrdFieldSource outerInstance;
+
+            private readonly int off;
+            private readonly SortedDocValues sindex;
+
+            public IntDocValuesAnonymousInnerClassHelper(OrdFieldSource outerInstance, OrdFieldSource @this, int off, SortedDocValues sindex)
+                : base(@this)
+            {
+                this.outerInstance = outerInstance;
+                this.off = off;
+                this.sindex = sindex;
+            }
+
+            protected virtual string ToTerm(string readableValue)
+            {
+                return readableValue;
+            }
+            public override int IntVal(int doc)
+            {
+                return sindex.GetOrd(doc + off);
+            }
+            public override int OrdVal(int doc)
+            {
+                return sindex.GetOrd(doc + off);
+            }
+            public override int NumOrd()
+            {
+                return sindex.ValueCount;
+            }
+
+            public override bool Exists(int doc)
+            {
+                return sindex.GetOrd(doc + off) != 0;
+            }
+
+            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.sindex.GetOrd(doc);
+                    mval.Exists = mval.Value != 0;
+                }
+            }
+        }
+
+        public override bool Equals(object o)
+        {
+            return o != null && o.GetType() == typeof(OrdFieldSource) && this.field.Equals(((OrdFieldSource)o).field);
+        }
+
+        private static readonly int hcode = typeof(OrdFieldSource).GetHashCode();
+
+        public override int GetHashCode()
+        {
+            return hcode + field.GetHashCode();
+        }
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Queries/Function/ValueSources/PowFloatFunction.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/PowFloatFunction.cs b/src/Lucene.Net.Queries/Function/ValueSources/PowFloatFunction.cs
index da8c3bc..711af7a 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/PowFloatFunction.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/PowFloatFunction.cs
@@ -15,34 +15,29 @@
  * limitations under the License.
  */
 using System;
-using org.apache.lucene.queries.function;
 
 namespace Lucene.Net.Queries.Function.ValueSources
 {
-
-
-	/// <summary>
-	/// Function to raise the base "a" to the power "b"
-	/// </summary>
-	public class PowFloatFunction : DualFloatFunction
-	{
-	 /// <param name="a">  the base. </param>
-	 /// <param name="b">  the exponent. </param>
-	  public PowFloatFunction(ValueSource a, ValueSource b) : base(a,b)
-	  {
-	  }
-
-	  protected internal override string name()
-	  {
-		return "pow";
-	  }
-
-	  protected internal override float func(int doc, FunctionValues aVals, FunctionValues bVals)
-	  {
-		return (float)Math.Pow(aVals.FloatVal(doc), bVals.FloatVal(doc));
-	  }
-	}
-
-
-
+    /// <summary>
+    /// Function to raise the base "a" to the power "b"
+    /// </summary>
+    public class PowFloatFunction : DualFloatFunction
+    {
+        /// <param name="a">  the base. </param>
+        /// <param name="b">  the exponent. </param>
+        public PowFloatFunction(ValueSource a, ValueSource b)
+            : base(a, b)
+        {
+        }
+
+        protected override string Name
+        {
+            get { return "pow"; }
+        }
+
+        protected override float Func(int doc, FunctionValues aVals, FunctionValues bVals)
+        {
+            return (float)Math.Pow(aVals.FloatVal(doc), bVals.FloatVal(doc));
+        }
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Queries/Function/ValueSources/ProductFloatFunction.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/ProductFloatFunction.cs b/src/Lucene.Net.Queries/Function/ValueSources/ProductFloatFunction.cs
index 2a21615..94c7969 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/ProductFloatFunction.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/ProductFloatFunction.cs
@@ -15,35 +15,28 @@
  * limitations under the License.
  */
 
-using org.apache.lucene.queries.function;
+using System.Linq;
 
 namespace Lucene.Net.Queries.Function.ValueSources
 {
+    /// <summary>
+    /// <code>ProductFloatFunction</code> returns the product of it's components.
+    /// </summary>
+    public class ProductFloatFunction : MultiFloatFunction
+    {
+        public ProductFloatFunction(ValueSource[] sources)
+            : base(sources)
+        {
+        }
 
+        protected override string Name
+        {
+            get { return "product"; }
+        }
 
-	/// <summary>
-	/// <code>ProductFloatFunction</code> returns the product of it's components.
-	/// </summary>
-	public class ProductFloatFunction : MultiFloatFunction
-	{
-	  public ProductFloatFunction(ValueSource[] sources) : base(sources)
-	  {
-	  }
-
-	  protected internal override string name()
-	  {
-		return "product";
-	  }
-
-	  protected internal override float func(int doc, FunctionValues[] valsArr)
-	  {
-		float val = 1.0f;
-		foreach (FunctionValues vals in valsArr)
-		{
-		  val *= vals.FloatVal(doc);
-		}
-		return val;
-	  }
-	}
-
+        protected override float Func(int doc, FunctionValues[] valsArr)
+        {
+            return valsArr.Aggregate(1.0f, (current, vals) => current * vals.FloatVal(doc));
+        }
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Queries/Function/ValueSources/QueryValueSource.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/QueryValueSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/QueryValueSource.cs
index 2949747..0f2ff47 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/QueryValueSource.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/QueryValueSource.cs
@@ -16,304 +16,304 @@
  */
 using System;
 using System.Collections;
+using System.IO;
+using Lucene.Net.Index;
 using Lucene.Net.Queries.Function.DocValues;
-using org.apache.lucene.queries.function;
+using Lucene.Net.Search;
+using Lucene.Net.Util;
+using Lucene.Net.Util.Mutable;
 
 namespace Lucene.Net.Queries.Function.ValueSources
 {
     /// <summary>
-	/// <code>QueryValueSource</code> returns the relevance score of the query
-	/// </summary>
-	public class QueryValueSource : ValueSource
-	{
-	  internal readonly Query q;
-	  internal readonly float defVal;
-
-	  public QueryValueSource(Query q, float defVal)
-	  {
-		this.q = q;
-		this.defVal = defVal;
-	  }
-
-	  public virtual Query Query
-	  {
-		  get
-		  {
-			  return q;
-		  }
-	  }
-	  public virtual float DefaultValue
-	  {
-		  get
-		  {
-			  return defVal;
-		  }
-	  }
-
-	  public override string description()
-	  {
-		return "query(" + q + ",def=" + defVal + ")";
-	  }
-
-//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 fcontext, org.apache.lucene.index.AtomicReaderContext readerContext) throws java.io.IOException
-	  public override FunctionValues GetValues(IDictionary fcontext, AtomicReaderContext readerContext)
-	  {
-		return new QueryDocValues(this, readerContext, fcontext);
-	  }
-
-	  public override int GetHashCode()
-	  {
-		return q.GetHashCode() * 29;
-	  }
-
-	  public override bool Equals(object o)
-	  {
-		if (typeof(QueryValueSource) != o.GetType())
-		{
-			return false;
-		}
-		QueryValueSource other = (QueryValueSource)o;
-		return this.q.Equals(other.q) && this.defVal == other.defVal;
-	  }
-
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: @Override public void CreateWeight(java.util.Map context, IndexSearcher searcher) throws java.io.IOException
-	  public override void CreateWeight(IDictionary context, IndexSearcher searcher)
-	  {
-		Weight w = searcher.createNormalizedWeight(q);
-		context[this] = w;
-	  }
-	}
-
-
-	internal class QueryDocValues : FloatDocValues
-	{
-	  internal readonly AtomicReaderContext readerContext;
-	  internal readonly Bits acceptDocs;
-	  internal readonly Weight weight;
-	  internal readonly float defVal;
-	  internal readonly IDictionary fcontext;
-	  internal readonly Query q;
-
-	  internal Scorer scorer;
-	  internal int scorerDoc; // the document the scorer is on
-	  internal bool noMatches = false;
-
-	  // the last document requested... start off with high value
-	  // to trigger a scorer reset on first access.
-	  internal int lastDocRequested = int.MaxValue;
-
-
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: public QueryDocValues(QueryValueSource vs, org.apache.lucene.index.AtomicReaderContext readerContext, java.util.Map fcontext) throws java.io.IOException
-	  public QueryDocValues(QueryValueSource vs, AtomicReaderContext readerContext, IDictionary fcontext) : base(vs)
-	  {
-
-		this.readerContext = readerContext;
-		this.acceptDocs = readerContext.reader().LiveDocs;
-		this.defVal = vs.defVal;
-		this.q = vs.q;
-		this.fcontext = fcontext;
-
-		Weight w = fcontext == null ? null : (Weight)fcontext[vs];
-		if (w == null)
-		{
-		  IndexSearcher weightSearcher;
-		  if (fcontext == null)
-		  {
-			weightSearcher = new IndexSearcher(ReaderUtil.getTopLevelContext(readerContext));
-		  }
-		  else
-		  {
-			weightSearcher = (IndexSearcher)fcontext["searcher"];
-			if (weightSearcher == null)
-			{
-			  weightSearcher = new IndexSearcher(ReaderUtil.getTopLevelContext(readerContext));
-			}
-		  }
-		  vs.CreateWeight(fcontext, weightSearcher);
-		  w = (Weight)fcontext[vs];
-		}
-		weight = w;
-	  }
-
-	  public override float FloatVal(int doc)
-	  {
-		try
-		{
-		  if (doc < lastDocRequested)
-		  {
-			if (noMatches)
-			{
-				return defVal;
-			}
-			scorer = weight.scorer(readerContext, acceptDocs);
-			if (scorer == null)
-			{
-			  noMatches = true;
-			  return defVal;
-			}
-			scorerDoc = -1;
-		  }
-		  lastDocRequested = doc;
-
-		  if (scorerDoc < doc)
-		  {
-			scorerDoc = scorer.advance(doc);
-		  }
-
-		  if (scorerDoc > doc)
-		  {
-			// query doesn't match this document... either because we hit the
-			// end, or because the next doc is after this doc.
-			return defVal;
-		  }
-
-		  // a match!
-		  return scorer.score();
-		}
-		catch (IOException e)
-		{
-		  throw new Exception("caught exception in QueryDocVals(" + q + ") doc=" + doc, e);
-		}
-	  }
-
-	  public override bool exists(int doc)
-	  {
-		try
-		{
-		  if (doc < lastDocRequested)
-		  {
-			if (noMatches)
-			{
-				return false;
-			}
-			scorer = weight.scorer(readerContext, acceptDocs);
-			scorerDoc = -1;
-			if (scorer == null)
-			{
-			  noMatches = true;
-			  return false;
-			}
-		  }
-		  lastDocRequested = doc;
-
-		  if (scorerDoc < doc)
-		  {
-			scorerDoc = scorer.advance(doc);
-		  }
-
-		  if (scorerDoc > doc)
-		  {
-			// query doesn't match this document... either because we hit the
-			// end, or because the next doc is after this doc.
-			return false;
-		  }
-
-		  // a match!
-		  return true;
-		}
-		catch (IOException e)
-		{
-		  throw new Exception("caught exception in QueryDocVals(" + q + ") doc=" + doc, e);
-		}
-	  }
-
-	   public override object objectVal(int doc)
-	   {
-		 try
-		 {
-		   return exists(doc) ? scorer.score() : null;
-		 }
-		 catch (IOException e)
-		 {
-		   throw new Exception("caught exception in QueryDocVals(" + q + ") doc=" + doc, e);
-		 }
-	   }
-
-	  public override ValueFiller ValueFiller
-	  {
-		  get
-		  {
-			//
-			// TODO: if we want to support more than one value-filler or a value-filler in conjunction with
-			// the FunctionValues, then members like "scorer" should be per ValueFiller instance.
-			// Or we can say that the user should just instantiate multiple FunctionValues.
-			//
-			return new ValueFillerAnonymousInnerClassHelper(this);
-		  }
-	  }
-
-	  private class ValueFillerAnonymousInnerClassHelper : ValueFiller
-	  {
-		  private readonly QueryDocValues outerInstance;
-
-		  public ValueFillerAnonymousInnerClassHelper(QueryDocValues outerInstance)
-		  {
-			  this.outerInstance = outerInstance;
-			  mval = new MutableValueFloat();
-		  }
-
-		  private readonly MutableValueFloat mval;
-
-		  public override MutableValue Value
-		  {
-			  get
-			  {
-				return mval;
-			  }
-		  }
-
-		  public override void fillValue(int doc)
-		  {
-			try
-			{
-			  if (outerInstance.noMatches)
-			  {
-				mval.value = outerInstance.defVal;
-				mval.exists = false;
-				return;
-			  }
-			  outerInstance.scorer = outerInstance.weight.scorer(outerInstance.readerContext, outerInstance.acceptDocs);
-			  outerInstance.scorerDoc = -1;
-			  if (outerInstance.scorer == null)
-			  {
-				outerInstance.noMatches = true;
-				mval.value = outerInstance.defVal;
-				mval.exists = false;
-				return;
-			  }
-			  outerInstance.lastDocRequested = doc;
-
-			  if (outerInstance.scorerDoc < doc)
-			  {
-				outerInstance.scorerDoc = outerInstance.scorer.advance(doc);
-			  }
-
-			  if (outerInstance.scorerDoc > doc)
-			  {
-				// query doesn't match this document... either because we hit the
-				// end, or because the next doc is after this doc.
-				mval.value = outerInstance.defVal;
-				mval.exists = false;
-				return;
-			  }
-
-			  // a match!
-			  mval.value = outerInstance.scorer.score();
-			  mval.exists = true;
-			}
-			catch (IOException e)
-			{
-			  throw new Exception("caught exception in QueryDocVals(" + outerInstance.q + ") doc=" + doc, e);
-			}
-		  }
-	  }
-
-	  public override string ToString(int doc)
-	  {
-		return "query(" + q + ",def=" + defVal + ")=" + FloatVal(doc);
-	  }
-	}
+    /// <code>QueryValueSource</code> returns the relevance score of the query
+    /// </summary>
+    public class QueryValueSource : ValueSource
+    {
+        internal readonly Query q;
+        internal readonly float defVal;
+
+        public QueryValueSource(Query q, float defVal)
+        {
+            this.q = q;
+            this.defVal = defVal;
+        }
+
+        public virtual Query Query
+        {
+            get
+            {
+                return q;
+            }
+        }
+        public virtual float DefaultValue
+        {
+            get
+            {
+                return defVal;
+            }
+        }
+
+        public override string Description
+        {
+            get { return "query(" + q + ",def=" + defVal + ")"; }
+        }
+
+        public override FunctionValues GetValues(IDictionary fcontext, AtomicReaderContext readerContext)
+        {
+            return new QueryDocValues(this, readerContext, fcontext);
+        }
+
+        public override int GetHashCode()
+        {
+            return q.GetHashCode() * 29;
+        }
+
+        public override bool Equals(object o)
+        {
+            if (typeof(QueryValueSource) != o.GetType())
+            {
+                return false;
+            }
+            var other = o as QueryValueSource;
+            if (other == null)
+                return false;
+            return this.q.Equals(other.q) && this.defVal == other.defVal;
+        }
+
+        public override void CreateWeight(IDictionary context, IndexSearcher searcher)
+        {
+            Weight w = searcher.CreateNormalizedWeight(q);
+            context[this] = w;
+        }
+    }
+
+
+    internal class QueryDocValues : FloatDocValues
+    {
+        internal readonly AtomicReaderContext readerContext;
+        internal readonly Bits acceptDocs;
+        internal readonly Weight weight;
+        internal readonly float defVal;
+        internal readonly IDictionary fcontext;
+        internal readonly Query q;
+
+        internal Scorer scorer;
+        internal int scorerDoc; // the document the scorer is on
+        internal bool noMatches = false;
+
+        // the last document requested... start off with high value
+        // to trigger a scorer reset on first access.
+        internal int lastDocRequested = int.MaxValue;
+
+        public QueryDocValues(QueryValueSource vs, AtomicReaderContext readerContext, IDictionary fcontext)
+            : base(vs)
+        {
+
+            this.readerContext = readerContext;
+            this.acceptDocs = readerContext.AtomicReader.LiveDocs;
+            this.defVal = vs.defVal;
+            this.q = vs.q;
+            this.fcontext = fcontext;
+
+            Weight w = fcontext == null ? null : (Weight)fcontext[vs];
+            if (w == null)
+            {
+                IndexSearcher weightSearcher;
+                if (fcontext == null)
+                {
+                    weightSearcher = new IndexSearcher(ReaderUtil.GetTopLevelContext(readerContext));
+                }
+                else
+                {
+                    weightSearcher = (IndexSearcher)fcontext["searcher"];
+                    if (weightSearcher == null)
+                    {
+                        weightSearcher = new IndexSearcher(ReaderUtil.GetTopLevelContext(readerContext));
+                    }
+                }
+                vs.CreateWeight(fcontext, weightSearcher);
+                w = (Weight)fcontext[vs];
+            }
+            weight = w;
+        }
+
+        public override float FloatVal(int doc)
+        {
+            try
+            {
+                if (doc < lastDocRequested)
+                {
+                    if (noMatches)
+                    {
+                        return defVal;
+                    }
+                    scorer = weight.Scorer(readerContext, acceptDocs);
+                    if (scorer == null)
+                    {
+                        noMatches = true;
+                        return defVal;
+                    }
+                    scorerDoc = -1;
+                }
+                lastDocRequested = doc;
+
+                if (scorerDoc < doc)
+                {
+                    scorerDoc = scorer.Advance(doc);
+                }
+
+                if (scorerDoc > doc)
+                {
+                    // query doesn't match this document... either because we hit the
+                    // end, or because the next doc is after this doc.
+                    return defVal;
+                }
+
+                // a match!
+                return scorer.Score();
+            }
+            catch (IOException e)
+            {
+                throw new Exception("caught exception in QueryDocVals(" + q + ") doc=" + doc, e);
+            }
+        }
+
+        public override bool Exists(int doc)
+        {
+            try
+            {
+                if (doc < lastDocRequested)
+                {
+                    if (noMatches)
+                    {
+                        return false;
+                    }
+                    scorer = weight.Scorer(readerContext, acceptDocs);
+                    scorerDoc = -1;
+                    if (scorer == null)
+                    {
+                        noMatches = true;
+                        return false;
+                    }
+                }
+                lastDocRequested = doc;
+
+                if (scorerDoc < doc)
+                {
+                    scorerDoc = scorer.Advance(doc);
+                }
+
+                if (scorerDoc > doc)
+                {
+                    // query doesn't match this document... either because we hit the
+                    // end, or because the next doc is after this doc.
+                    return false;
+                }
+
+                // a match!
+                return true;
+            }
+            catch (IOException e)
+            {
+                throw new Exception("caught exception in QueryDocVals(" + q + ") doc=" + doc, e);
+            }
+        }
+
+        public override object ObjectVal(int doc)
+        {
+            try
+            {
+                return Exists(doc) ? scorer.Score() : (float?)null;
+            }
+            catch (IOException e)
+            {
+                throw new Exception("caught exception in QueryDocVals(" + q + ") doc=" + doc, e);
+            }
+        }
+
+        public override AbstractValueFiller ValueFiller
+        {
+            get
+            {
+                //
+                // TODO: if we want to support more than one value-filler or a value-filler in conjunction with
+                // the FunctionValues, then members like "scorer" should be per ValueFiller instance.
+                // Or we can say that the user should just instantiate multiple FunctionValues.
+                //
+                return new ValueFillerAnonymousInnerClassHelper(this);
+            }
+        }
+
+        private class ValueFillerAnonymousInnerClassHelper : AbstractValueFiller
+        {
+            private readonly QueryDocValues outerInstance;
+
+            public ValueFillerAnonymousInnerClassHelper(QueryDocValues outerInstance)
+            {
+                this.outerInstance = outerInstance;
+                mval = new MutableValueFloat();
+            }
+
+            private readonly MutableValueFloat mval;
+
+            public override MutableValue Value
+            {
+                get
+                {
+                    return mval;
+                }
+            }
+
+            public override void FillValue(int doc)
+            {
+                try
+                {
+                    if (outerInstance.noMatches)
+                    {
+                        mval.Value = outerInstance.defVal;
+                        mval.Exists = false;
+                        return;
+                    }
+                    outerInstance.scorer = outerInstance.weight.Scorer(outerInstance.readerContext, outerInstance.acceptDocs);
+                    outerInstance.scorerDoc = -1;
+                    if (outerInstance.scorer == null)
+                    {
+                        outerInstance.noMatches = true;
+                        mval.Value = outerInstance.defVal;
+                        mval.Exists = false;
+                        return;
+                    }
+                    outerInstance.lastDocRequested = doc;
+
+                    if (outerInstance.scorerDoc < doc)
+                    {
+                        outerInstance.scorerDoc = outerInstance.scorer.Advance(doc);
+                    }
+
+                    if (outerInstance.scorerDoc > doc)
+                    {
+                        // query doesn't match this document... either because we hit the
+                        // end, or because the next doc is after this doc.
+                        mval.Value = outerInstance.defVal;
+                        mval.Exists = false;
+                        return;
+                    }
+
+                    // a match!
+                    mval.Value = outerInstance.scorer.Score();
+                    mval.Exists = true;
+                }
+                catch (IOException e)
+                {
+                    throw new Exception("caught exception in QueryDocVals(" + outerInstance.q + ") doc=" + doc, e);
+                }
+            }
+        }
+
+        public override string ToString(int doc)
+        {
+            return "query(" + q + ",def=" + defVal + ")=" + FloatVal(doc);
+        }
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Queries/Function/ValueSources/RangeMapFloatFunction.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/RangeMapFloatFunction.cs b/src/Lucene.Net.Queries/Function/ValueSources/RangeMapFloatFunction.cs
index de729df..5c2fe5f 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/RangeMapFloatFunction.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/RangeMapFloatFunction.cs
@@ -15,119 +15,114 @@
  * limitations under the License.
  */
 using System.Collections;
+using Lucene.Net.Index;
 using Lucene.Net.Queries.Function.DocValues;
-using org.apache.lucene.queries.function;
+using Lucene.Net.Search;
+using Lucene.Net.Support;
 
 namespace Lucene.Net.Queries.Function.ValueSources
 {
     /// <summary>
-	/// <code>RangeMapFloatFunction</code> implements a map function over
-	/// another <seealso cref="ValueSource"/> whose values fall within min and max inclusive to target.
-	/// <br>
-	/// Normally Used as an argument to a <seealso cref="FunctionQuery"/>
-	/// 
-	/// 
-	/// </summary>
-	public class RangeMapFloatFunction : ValueSource
-	{
-	  protected internal readonly ValueSource source;
-	  protected internal readonly float min;
-	  protected internal readonly float max;
-	  protected internal readonly ValueSource target;
-	  protected internal readonly ValueSource defaultVal;
+    /// <code>RangeMapFloatFunction</code> implements a map function over
+    /// another <seealso cref="ValueSource"/> whose values fall within min and max inclusive to target.
+    /// <br>
+    /// Normally Used as an argument to a <seealso cref="FunctionQuery"/>
+    /// 
+    /// 
+    /// </summary>
+    public class RangeMapFloatFunction : ValueSource
+    {
+        protected readonly ValueSource source;
+        protected readonly float min;
+        protected readonly float max;
+        protected readonly ValueSource target;
+        protected readonly ValueSource defaultVal;
 
-	  public RangeMapFloatFunction(ValueSource source, float min, float max, float target, float? def) : this(source, min, max, (ValueSource) new ConstValueSource(target), (ValueSource) (def == null ? null : new ConstValueSource(def.Value)))
-	  {
-	  }
+        public RangeMapFloatFunction(ValueSource source, float min, float max, float target, float? def)
+            : this(source, min, max, new ConstValueSource(target), def == null ? null : new ConstValueSource(def.Value))
+        {
+        }
 
-	  public RangeMapFloatFunction(ValueSource source, float min, float max, ValueSource target, ValueSource def)
-	  {
-		this.source = source;
-		this.min = min;
-		this.max = max;
-		this.target = target;
-		this.defaultVal = def;
-	  }
+        public RangeMapFloatFunction(ValueSource source, float min, float max, ValueSource target, ValueSource def)
+        {
+            this.source = source;
+            this.min = min;
+            this.max = max;
+            this.target = target;
+            this.defaultVal = def;
+        }
 
-	  public override string description()
-	  {
-		return "map(" + source.description() + "," + min + "," + max + "," + target.description() + ")";
-	  }
+        public override string Description
+        {
+            get { return "map(" + source.Description + "," + min + "," + max + "," + target.Description + ")"; }
+        }
 
-//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.queries.function.FunctionValues vals = source.GetValues(context, readerContext);
-		FunctionValues vals = source.GetValues(context, readerContext);
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final org.apache.lucene.queries.function.FunctionValues targets = target.GetValues(context, readerContext);
-		FunctionValues targets = target.GetValues(context, readerContext);
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final org.apache.lucene.queries.function.FunctionValues defaults = (this.defaultVal == null) ? null : defaultVal.GetValues(context, readerContext);
-		FunctionValues defaults = (this.defaultVal == null) ? null : defaultVal.GetValues(context, readerContext);
-		return new FloatDocValuesAnonymousInnerClassHelper(this, this, vals, targets, defaults);
-	  }
+        public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext)
+        {
+            FunctionValues vals = source.GetValues(context, readerContext);
+            FunctionValues targets = target.GetValues(context, readerContext);
+            FunctionValues defaults = (this.defaultVal == null) ? null : defaultVal.GetValues(context, readerContext);
+            return new FloatDocValuesAnonymousInnerClassHelper(this, this, vals, targets, defaults);
+        }
 
-	  private class FloatDocValuesAnonymousInnerClassHelper : FloatDocValues
-	  {
-		  private readonly RangeMapFloatFunction outerInstance;
+        private class FloatDocValuesAnonymousInnerClassHelper : FloatDocValues
+        {
+            private readonly RangeMapFloatFunction outerInstance;
 
-		  private FunctionValues vals;
-		  private FunctionValues targets;
-		  private FunctionValues defaults;
+            private readonly FunctionValues vals;
+            private readonly FunctionValues targets;
+            private readonly FunctionValues defaults;
 
-		  public FloatDocValuesAnonymousInnerClassHelper(RangeMapFloatFunction outerInstance, RangeMapFloatFunction this, FunctionValues vals, FunctionValues targets, FunctionValues defaults) : base(this)
-		  {
-			  this.outerInstance = outerInstance;
-			  this.vals = vals;
-			  this.targets = targets;
-			  this.defaults = defaults;
-		  }
+            public FloatDocValuesAnonymousInnerClassHelper(RangeMapFloatFunction outerInstance, RangeMapFloatFunction @this, FunctionValues vals, FunctionValues targets, FunctionValues defaults)
+                : base(@this)
+            {
+                this.outerInstance = outerInstance;
+                this.vals = vals;
+                this.targets = targets;
+                this.defaults = defaults;
+            }
 
-		  public override float FloatVal(int doc)
-		  {
-			float val = vals.FloatVal(doc);
-			return (val >= outerInstance.min && val <= outerInstance.max) ? targets.FloatVal(doc) : (outerInstance.defaultVal == null ? val : defaults.FloatVal(doc));
-		  }
-		  public override string ToString(int doc)
-		  {
-			return "map(" + vals.ToString(doc) + ",min=" + outerInstance.min + ",max=" + outerInstance.max + ",target=" + targets.ToString(doc) + ")";
-		  }
-	  }
+            public override float FloatVal(int doc)
+            {
+                float val = vals.FloatVal(doc);
+                return (val >= outerInstance.min && val <= outerInstance.max) ? targets.FloatVal(doc) : (outerInstance.defaultVal == null ? val : defaults.FloatVal(doc));
+            }
+            public override string ToString(int doc)
+            {
+                return "map(" + vals.ToString(doc) + ",min=" + outerInstance.min + ",max=" + outerInstance.max + ",target=" + targets.ToString(doc) + ")";
+            }
+        }
 
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: @Override public void CreateWeight(java.util.Map context, org.apache.lucene.search.IndexSearcher searcher) throws java.io.IOException
-	  public override void CreateWeight(IDictionary context, IndexSearcher searcher)
-	  {
-		source.CreateWeight(context, searcher);
-	  }
+        public override void CreateWeight(IDictionary context, IndexSearcher searcher)
+        {
+            source.CreateWeight(context, searcher);
+        }
 
-	  public override int GetHashCode()
-	  {
-		int h = source.GetHashCode();
-		h ^= (h << 10) | ((int)((uint)h >> 23));
-		h += Number.FloatToIntBits(min);
-		h ^= (h << 14) | ((int)((uint)h >> 19));
-		h += Number.FloatToIntBits(max);
-		h += target.GetHashCode();
-		if (defaultVal != null)
-		{
-		  h += defaultVal.GetHashCode();
-		}
-		return h;
-	  }
-
-	  public override bool Equals(object o)
-	  {
-		if (typeof(RangeMapFloatFunction) != o.GetType())
-		{
-			return false;
-		}
-		RangeMapFloatFunction other = (RangeMapFloatFunction)o;
-		return this.min == other.min && this.max == other.max && this.target.Equals(other.target) && this.source.Equals(other.source) && (this.defaultVal == other.defaultVal || (this.defaultVal != null && this.defaultVal.Equals(other.defaultVal)));
-	  }
-	}
+        public override int GetHashCode()
+        {
+            int h = source.GetHashCode();
+            h ^= (h << 10) | ((int)((uint)h >> 23));
+            h += Number.FloatToIntBits(min);
+            h ^= (h << 14) | ((int)((uint)h >> 19));
+            h += Number.FloatToIntBits(max);
+            h += target.GetHashCode();
+            if (defaultVal != null)
+            {
+                h += defaultVal.GetHashCode();
+            }
+            return h;
+        }
 
+        public override bool Equals(object o)
+        {
+            if (typeof(RangeMapFloatFunction) != o.GetType())
+            {
+                return false;
+            }
+            var other = o as RangeMapFloatFunction;
+            if (other == null)
+                return false;
+            return this.min == other.min && this.max == other.max && this.target.Equals(other.target) && this.source.Equals(other.source) && (this.defaultVal == other.defaultVal || (this.defaultVal != null && this.defaultVal.Equals(other.defaultVal)));
+        }
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Queries/Function/ValueSources/ReciprocalFloatFunction.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/ReciprocalFloatFunction.cs b/src/Lucene.Net.Queries/Function/ValueSources/ReciprocalFloatFunction.cs
index 6a4a248..275436b 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/ReciprocalFloatFunction.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/ReciprocalFloatFunction.cs
@@ -16,110 +16,107 @@
  */
 using System;
 using System.Collections;
+using Lucene.Net.Index;
 using Lucene.Net.Queries.Function.DocValues;
-using org.apache.lucene.queries.function;
+using Lucene.Net.Search;
+using Lucene.Net.Support;
 
 namespace Lucene.Net.Queries.Function.ValueSources
 {
     /// <summary>
-	/// <code>ReciprocalFloatFunction</code> implements a reciprocal function f(x) = a/(mx+b), based on
-	/// the float value of a field or function as exported by <seealso cref="ValueSource"/>.
-	/// <br>
-	/// 
-	/// When a and b are equal, and x>=0, this function has a maximum value of 1 that drops as x increases.
-	/// Increasing the value of a and b together results in a movement of the entire function to a flatter part of the curve.
-	/// <para>These properties make this an idea function for boosting more recent documents.
-	/// </para>
-	/// <para>Example:<code>  recip(ms(NOW,mydatefield),3.16e-11,1,1)</code>
-	/// </para>
-	/// <para>A multiplier of 3.16e-11 changes the units from milliseconds to years (since there are about 3.16e10 milliseconds
-	/// per year).  Thus, a very recent date will yield a value close to 1/(0+1) or 1,
-	/// a date a year in the past will get a multiplier of about 1/(1+1) or 1/2,
-	/// and date two years old will yield 1/(2+1) or 1/3.
-	/// 
-	/// </para>
-	/// </summary>
-	/// <seealso cref= org.apache.lucene.queries.function.FunctionQuery
-	/// 
-	///  </seealso>
-	public class ReciprocalFloatFunction : ValueSource
-	{
-	  protected internal readonly ValueSource source;
-	  protected internal readonly float m;
-	  protected internal readonly float a;
-	  protected internal readonly float b;
+    /// <code>ReciprocalFloatFunction</code> implements a reciprocal function f(x) = a/(mx+b), based on
+    /// the float value of a field or function as exported by <seealso cref="ValueSource"/>.
+    /// <br>
+    /// 
+    /// When a and b are equal, and x>=0, this function has a maximum value of 1 that drops as x increases.
+    /// Increasing the value of a and b together results in a movement of the entire function to a flatter part of the curve.
+    /// <para>These properties make this an idea function for boosting more recent documents.
+    /// </para>
+    /// <para>Example:<code>  recip(ms(NOW,mydatefield),3.16e-11,1,1)</code>
+    /// </para>
+    /// <para>A multiplier of 3.16e-11 changes the units from milliseconds to years (since there are about 3.16e10 milliseconds
+    /// per year).  Thus, a very recent date will yield a value close to 1/(0+1) or 1,
+    /// a date a year in the past will get a multiplier of about 1/(1+1) or 1/2,
+    /// and date two years old will yield 1/(2+1) or 1/3.
+    /// 
+    /// </para>
+    /// </summary>
+    /// <seealso cref= org.apache.lucene.queries.function.FunctionQuery
+    /// 
+    ///  </seealso>
+    public class ReciprocalFloatFunction : ValueSource
+    {
+        protected internal readonly ValueSource source;
+        protected internal readonly float m;
+        protected internal readonly float a;
+        protected internal readonly float b;
 
-	  /// <summary>
-	  ///  f(source) = a/(m*float(source)+b)
-	  /// </summary>
-	  public ReciprocalFloatFunction(ValueSource source, float m, float a, float b)
-	  {
-		this.source = source;
-		this.m = m;
-		this.a = a;
-		this.b = b;
-	  }
+        /// <summary>
+        ///  f(source) = a/(m*float(source)+b)
+        /// </summary>
+        public ReciprocalFloatFunction(ValueSource source, float m, float a, float b)
+        {
+            this.source = source;
+            this.m = m;
+            this.a = a;
+            this.b = b;
+        }
 
-//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.queries.function.FunctionValues vals = source.GetValues(context, readerContext);
-		FunctionValues vals = source.GetValues(context, readerContext);
-		return new FloatDocValuesAnonymousInnerClassHelper(this, this, vals);
-	  }
+        public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext)
+        {
+            var vals = source.GetValues(context, readerContext);
+            return new FloatDocValuesAnonymousInnerClassHelper(this, this, vals);
+        }
 
-	  private class FloatDocValuesAnonymousInnerClassHelper : FloatDocValues
-	  {
-		  private readonly ReciprocalFloatFunction outerInstance;
+        private class FloatDocValuesAnonymousInnerClassHelper : FloatDocValues
+        {
+            private readonly ReciprocalFloatFunction outerInstance;
+            private readonly FunctionValues vals;
 
-		  private FunctionValues vals;
+            public FloatDocValuesAnonymousInnerClassHelper(ReciprocalFloatFunction outerInstance, ReciprocalFloatFunction @this, FunctionValues vals)
+                : base(@this)
+            {
+                this.outerInstance = outerInstance;
+                this.vals = vals;
+            }
 
-		  public FloatDocValuesAnonymousInnerClassHelper(ReciprocalFloatFunction outerInstance, ReciprocalFloatFunction this, FunctionValues vals) : base(this)
-		  {
-			  this.outerInstance = outerInstance;
-			  this.vals = vals;
-		  }
+            public override float FloatVal(int doc)
+            {
+                return outerInstance.a / (outerInstance.m * vals.FloatVal(doc) + outerInstance.b);
+            }
+            public override string ToString(int doc)
+            {
+                return Convert.ToString(outerInstance.a) + "/(" + outerInstance.m + "*float(" + vals.ToString(doc) + ')' + '+' + outerInstance.b + ')';
+            }
+        }
 
-		  public override float FloatVal(int doc)
-		  {
-			return outerInstance.a / (outerInstance.m * vals.FloatVal(doc) + outerInstance.b);
-		  }
-		  public override string ToString(int doc)
-		  {
-			return Convert.ToString(outerInstance.a) + "/(" + outerInstance.m + "*float(" + vals.ToString(doc) + ')' + '+' + outerInstance.b + ')';
-		  }
-	  }
+        public override void CreateWeight(IDictionary context, IndexSearcher searcher)
+        {
+            source.CreateWeight(context, searcher);
+        }
 
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: @Override public void CreateWeight(java.util.Map context, org.apache.lucene.search.IndexSearcher searcher) throws java.io.IOException
-	  public override void CreateWeight(IDictionary context, IndexSearcher searcher)
-	  {
-		source.CreateWeight(context, searcher);
-	  }
+        public override string Description
+        {
+            get { return Convert.ToString(a) + "/(" + m + "*float(" + source.Description + ")" + "+" + b + ')'; }
+        }
 
-	  public override string description()
-	  {
-		return Convert.ToString(a) + "/(" + m + "*float(" + source.description() + ")" + "+" + b + ')';
-	  }
-
-	  public override int GetHashCode()
-	  {
-		int h = Number.FloatToIntBits(a) + Number.FloatToIntBits(m);
-		h ^= (h << 13) | ((int)((uint)h >> 20));
-		return h + (Number.FloatToIntBits(b)) + source.GetHashCode();
-	  }
-
-	  public override bool Equals(object o)
-	  {
-		if (typeof(ReciprocalFloatFunction) != o.GetType())
-		{
-			return false;
-		}
-		ReciprocalFloatFunction other = (ReciprocalFloatFunction)o;
-		return this.m == other.m && this.a == other.a && this.b == other.b && this.source.Equals(other.source);
-	  }
-	}
+        public override int GetHashCode()
+        {
+            int h = Number.FloatToIntBits(a) + Number.FloatToIntBits(m);
+            h ^= (h << 13) | ((int)((uint)h >> 20));
+            return h + (Number.FloatToIntBits(b)) + source.GetHashCode();
+        }
 
+        public override bool Equals(object o)
+        {
+            if (typeof(ReciprocalFloatFunction) != o.GetType())
+            {
+                return false;
+            }
+            var other = o as ReciprocalFloatFunction;
+            if (other == null)
+                return false;
+            return this.m == other.m && this.a == other.a && this.b == other.b && this.source.Equals(other.source);
+        }
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Queries/Function/ValueSources/ReverseOrdFieldSource.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/ReverseOrdFieldSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/ReverseOrdFieldSource.cs
index 7a67668..e111881 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/ReverseOrdFieldSource.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/ReverseOrdFieldSource.cs
@@ -15,110 +15,100 @@
  * limitations under the License.
  */
 using System.Collections;
+using Lucene.Net.Index;
 using Lucene.Net.Queries.Function.DocValues;
-using org.apache.lucene.queries.function;
+using Lucene.Net.Search;
 
 namespace Lucene.Net.Queries.Function.ValueSources
 {
     /// <summary>
-	/// Obtains the ordinal of the field value from the default Lucene <seealso cref="org.apache.lucene.search.FieldCache"/> using getTermsIndex()
-	/// and reverses the order.
-	/// <br>
-	/// The native lucene index order is used to assign an ordinal value for each field value.
-	/// <br>Field values (terms) are lexicographically ordered by unicode value, and numbered starting at 1.
-	/// <br>
-	/// Example of reverse ordinal (rord):<br>
-	///  If there were only three field values: "apple","banana","pear"
-	/// <br>then rord("apple")=3, rord("banana")=2, ord("pear")=1
-	/// <para>
-	///  WARNING: ord() depends on the position in an index and can thus change when other documents are inserted or deleted,
-	///  or if a MultiSearcher is used.
-	/// <br>
-	///  WARNING: as of Solr 1.4, ord() and rord() can cause excess memory use since they must use a FieldCache entry
-	/// at the top level reader, while sorting and function queries now use entries at the segment level.  Hence sorting
-	/// or using a different function query, in addition to ord()/rord() will double memory use.
-	/// 
-	/// 
-	/// </para>
-	/// </summary>
+    /// Obtains the ordinal of the field value from the default Lucene <seealso cref="FieldCache"/> using getTermsIndex()
+    /// and reverses the order.
+    /// <br>
+    /// The native lucene index order is used to assign an ordinal value for each field value.
+    /// <br>Field values (terms) are lexicographically ordered by unicode value, and numbered starting at 1.
+    /// <br>
+    /// Example of reverse ordinal (rord):<br>
+    ///  If there were only three field values: "apple","banana","pear"
+    /// <br>then rord("apple")=3, rord("banana")=2, ord("pear")=1
+    /// <para>
+    ///  WARNING: ord() depends on the position in an index and can thus change when other documents are inserted or deleted,
+    ///  or if a MultiSearcher is used.
+    /// <br>
+    ///  WARNING: as of Solr 1.4, ord() and rord() can cause excess memory use since they must use a FieldCache entry
+    /// at the top level reader, while sorting and function queries now use entries at the segment level.  Hence sorting
+    /// or using a different function query, in addition to ord()/rord() will double memory use.
+    /// 
+    /// 
+    /// </para>
+    /// </summary>
 
-	public class ReverseOrdFieldSource : ValueSource
-	{
-	  public readonly string field;
+    public class ReverseOrdFieldSource : ValueSource
+    {
+        public readonly string field;
 
-	  public ReverseOrdFieldSource(string field)
-	  {
-		this.field = field;
-	  }
+        public ReverseOrdFieldSource(string field)
+        {
+            this.field = field;
+        }
 
-	  public override string description()
-	  {
-		return "rord(" + field + ')';
-	  }
+        public override string Description
+        {
+            get { return "rord(" + field + ')'; }
+        }
 
-	  // TODO: this is trappy? perhaps this query instead should make you pass a slow reader yourself?
-//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.index.IndexReader topReader = org.apache.lucene.index.ReaderUtil.getTopLevelContext(readerContext).reader();
-		IndexReader topReader = ReaderUtil.getTopLevelContext(readerContext).reader();
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final org.apache.lucene.index.AtomicReader r = org.apache.lucene.index.SlowCompositeReaderWrapper.wrap(topReader);
-		AtomicReader r = SlowCompositeReaderWrapper.wrap(topReader);
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final int off = readerContext.docBase;
-		int off = readerContext.docBase;
+        // TODO: this is trappy? perhaps this query instead should make you pass a slow reader yourself?
+        public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext)
+        {
+            IndexReader topReader = ReaderUtil.GetTopLevelContext(readerContext).Reader;
+            AtomicReader r = SlowCompositeReaderWrapper.Wrap(topReader);
+            int off = readerContext.DocBase;
 
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final org.apache.lucene.index.SortedDocValues sindex = org.apache.lucene.search.FieldCache.DEFAULT.getTermsIndex(r, field);
-		SortedDocValues sindex = FieldCache.DEFAULT.getTermsIndex(r, field);
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final int end = sindex.getValueCount();
-		int end = sindex.ValueCount;
+            var sindex = FieldCache.DEFAULT.GetTermsIndex(r, field);
+            var end = sindex.ValueCount;
 
-		return new IntDocValuesAnonymousInnerClassHelper(this, this, off, sindex, end);
-	  }
+            return new IntDocValuesAnonymousInnerClassHelper(this, this, off, sindex, end);
+        }
 
-	  private class IntDocValuesAnonymousInnerClassHelper : IntDocValues
-	  {
-		  private readonly ReverseOrdFieldSource outerInstance;
+        private class IntDocValuesAnonymousInnerClassHelper : IntDocValues
+        {
+            private readonly ReverseOrdFieldSource outerInstance;
 
-		  private int off;
-		  private SortedDocValues sindex;
-		  private int end;
+            private readonly int off;
+            private readonly SortedDocValues sindex;
+            private readonly int end;
 
-		  public IntDocValuesAnonymousInnerClassHelper(ReverseOrdFieldSource outerInstance, ReverseOrdFieldSource this, int off, SortedDocValues sindex, int end) : base(this)
-		  {
-			  this.outerInstance = outerInstance;
-			  this.off = off;
-			  this.sindex = sindex;
-			  this.end = end;
-		  }
+            public IntDocValuesAnonymousInnerClassHelper(ReverseOrdFieldSource outerInstance, ReverseOrdFieldSource @this, int off, SortedDocValues sindex, int end)
+                : base(@this)
+            {
+                this.outerInstance = outerInstance;
+                this.off = off;
+                this.sindex = sindex;
+                this.end = end;
+            }
 
-		  public override int intVal(int doc)
-		  {
-			 return (end - sindex.getOrd(doc + off) - 1);
-		  }
-	  }
+            public override int IntVal(int doc)
+            {
+                return (end - sindex.GetOrd(doc + off) - 1);
+            }
+        }
 
-	  public override bool Equals(object o)
-	  {
-		if (o == null || (o.GetType() != typeof(ReverseOrdFieldSource)))
-		{
-			return false;
-		}
-		ReverseOrdFieldSource other = (ReverseOrdFieldSource)o;
-		return this.field.Equals(other.field);
-	  }
-
-	  private static readonly int hcode = typeof(ReverseOrdFieldSource).GetHashCode();
-	  public override int GetHashCode()
-	  {
-		return hcode + field.GetHashCode();
-	  }
-
-	}
+        public override bool Equals(object o)
+        {
+            if (o == null || (o.GetType() != typeof(ReverseOrdFieldSource)))
+            {
+                return false;
+            }
+            var other = o as ReverseOrdFieldSource;
+            if (other == null)
+                return false;
+            return this.field.Equals(other.field);
+        }
 
+        private static readonly int hcode = typeof(ReverseOrdFieldSource).GetHashCode();
+        public override int GetHashCode()
+        {
+            return hcode + field.GetHashCode();
+        }
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/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 95bd2d2..b3e69b9 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/ScaleFloatFunction.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/ScaleFloatFunction.cs
@@ -15,9 +15,9 @@
  * 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;
 using Lucene.Net.Support;
 
 namespace Lucene.Net.Queries.Function.ValueSources
@@ -50,7 +50,7 @@ namespace Lucene.Net.Queries.Function.ValueSources
 
         public override string Description
         {
-            get { return "scale(" + source.Description() + "," + min + "," + max + ")"; }
+            get { return "scale(" + source.Description + "," + min + "," + max + ")"; }
         }
 
         private class ScaleInfo
@@ -59,26 +59,22 @@ namespace Lucene.Net.Queries.Function.ValueSources
 		internal float maxVal;
 	  }
 
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: private ScaleInfo createScaleInfo(java.util.Map context, org.apache.lucene.index.AtomicReaderContext readerContext) throws java.io.IOException
 	  private ScaleInfo CreateScaleInfo(IDictionary context, AtomicReaderContext readerContext)
 	  {
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final java.util.List<org.apache.lucene.index.AtomicReaderContext> leaves = org.apache.lucene.index.ReaderUtil.getTopLevelContext(readerContext).leaves();
-		IList<AtomicReaderContext> leaves = ReaderUtil.GetTopLevelContext(readerContext).leaves();
+		var leaves = ReaderUtil.GetTopLevelContext(readerContext).Leaves;
 
 		float minVal = float.PositiveInfinity;
 		float maxVal = float.NegativeInfinity;
 
 		foreach (AtomicReaderContext leaf in leaves)
 		{
-		  int maxDoc = leaf.reader().maxDoc();
+		  int maxDoc = leaf.Reader.MaxDoc;
 		  FunctionValues vals = source.GetValues(context, leaf);
 		  for (int i = 0; i < maxDoc; i++)
 		  {
 
 		  float val = vals.FloatVal(i);
-		  if ((float.floatToRawIntBits(val) & (0xff << 23)) == 0xff << 23)
+		  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
@@ -108,31 +104,20 @@ namespace Lucene.Net.Queries.Function.ValueSources
 		return scaleInfo;
 	  }
 
-//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)
 	  {
 
-		ScaleInfo scaleInfo = (ScaleInfo)context[ScaleFloatFunction.this];
+		var scaleInfo = (ScaleInfo)context[ScaleFloatFunction.this];
 		if (scaleInfo == null)
 		{
-		  scaleInfo = createScaleInfo(context, readerContext);
+		  scaleInfo = CreateScaleInfo(context, readerContext);
 		}
 
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final float scale = (scaleInfo.maxVal-scaleInfo.minVal==0) ? 0 : (max-min)/(scaleInfo.maxVal-scaleInfo.minVal);
 		float scale = (scaleInfo.maxVal - scaleInfo.minVal == 0) ? 0 : (max - min) / (scaleInfo.maxVal - scaleInfo.minVal);
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final float minSource = scaleInfo.minVal;
 		float minSource = scaleInfo.minVal;
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final float maxSource = scaleInfo.maxVal;
 		float maxSource = scaleInfo.maxVal;
 
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final org.apache.lucene.queries.function.FunctionValues vals = source.GetValues(context, readerContext);
-		FunctionValues vals = source.GetValues(context, readerContext);
-
+		var vals = source.GetValues(context, readerContext);
 		return new FloatDocValuesAnonymousInnerClassHelper(this, this, scale, minSource, maxSource, vals);
 	  }
 
@@ -140,12 +125,12 @@ namespace Lucene.Net.Queries.Function.ValueSources
 	  {
 		  private readonly ScaleFloatFunction outerInstance;
 
-		  private float scale;
-		  private float minSource;
-		  private float maxSource;
-		  private FunctionValues vals;
+		  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)
+		  public FloatDocValuesAnonymousInnerClassHelper(ScaleFloatFunction outerInstance, ScaleFloatFunction @this, float scale, float minSource, float maxSource, FunctionValues vals) : base(@this)
 		  {
 			  this.outerInstance = outerInstance;
 			  this.scale = scale;
@@ -164,8 +149,6 @@ namespace Lucene.Net.Queries.Function.ValueSources
 		  }
 	  }
 
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: @Override public void CreateWeight(java.util.Map context, org.apache.lucene.search.IndexSearcher searcher) throws java.io.IOException
 	  public override void CreateWeight(IDictionary context, IndexSearcher searcher)
 	  {
 		source.CreateWeight(context, searcher);
@@ -183,13 +166,10 @@ namespace Lucene.Net.Queries.Function.ValueSources
 
 	  public override bool Equals(object o)
 	  {
-		if (typeof(ScaleFloatFunction) != o.GetType())
-		{
-			return false;
-		}
-		ScaleFloatFunction other = (ScaleFloatFunction)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);
 	  }
 	}
-
-}s
\ No newline at end of file
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Queries/Function/ValueSources/ShortFieldSource.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/ShortFieldSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/ShortFieldSource.cs
index 9ed5d2a..2c1c581 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/ShortFieldSource.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/ShortFieldSource.cs
@@ -1,132 +1,125 @@
 using System;
 using System.Collections;
-using org.apache.lucene.queries.function;
+using Lucene.Net.Index;
+using Lucene.Net.Search;
 
 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 short field values from the <seealso cref="org.apache.lucene.search.FieldCache"/>
-	/// using <code>getShorts()</code>
-	/// and makes those values available as other numeric types, casting as needed.
-	/// 
-	/// </summary>
-	[Obsolete]
-	public class ShortFieldSource : FieldCacheSource
-	{
-
-	  internal readonly FieldCache.ShortParser parser;
-
-	  public ShortFieldSource(string field) : this(field, null)
-	  {
-	  }
-
-	  public ShortFieldSource(string field, FieldCache.ShortParser parser) : base(field)
-	  {
-		this.parser = parser;
-	  }
-
-	  public override string description()
-	  {
-		return "short(" + field + ')';
-	  }
-
-//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.Shorts arr = cache.getShorts(readerContext.reader(), field, parser, false);
-		FieldCache.Shorts arr = cache.getShorts(readerContext.reader(), field, parser, false);
-
-		return new FunctionValuesAnonymousInnerClassHelper(this, arr);
-	  }
-
-	  private class FunctionValuesAnonymousInnerClassHelper : FunctionValues
-	  {
-		  private readonly ShortFieldSource outerInstance;
-
-		  private FieldCache.Shorts arr;
-
-		  public FunctionValuesAnonymousInnerClassHelper(ShortFieldSource outerInstance, FieldCache.Shorts arr)
-		  {
-			  this.outerInstance = outerInstance;
-			  this.arr = arr;
-		  }
-
-		  public override sbyte ByteVal(int doc)
-		  {
-			return (sbyte) arr.get(doc);
-		  }
-
-		  public override short ShortVal(int doc)
-		  {
-			return arr.get(doc);
-		  }
-
-		  public override float FloatVal(int doc)
-		  {
-			return (float) arr.get(doc);
-		  }
-
-		  public override int intVal(int doc)
-		  {
-			return (int) 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)
-		  {
-			return Convert.ToString(arr.get(doc));
-		  }
-
-		  public override string ToString(int doc)
-		  {
-			return outerInstance.description() + '=' + ShortVal(doc);
-		  }
-
-	  }
-
-	  public override bool Equals(object o)
-	  {
-		if (o.GetType() != typeof(ShortFieldSource))
-		{
-			return false;
-		}
-		ShortFieldSource other = (ShortFieldSource) o;
-		return base.Equals(other) && (this.parser == null ? other.parser == null : this.parser.GetType() == other.parser.GetType());
-	  }
-
-	  public override int GetHashCode()
-	  {
-		int h = parser == null ? typeof(short?).GetHashCode() : parser.GetType().GetHashCode();
-		h += base.GetHashCode();
-		return h;
-	  }
-	}
-
+    /// Obtains short field values from the <seealso cref="org.apache.lucene.search.FieldCache"/>
+    /// using <code>getShorts()</code>
+    /// and makes those values available as other numeric types, casting as needed.
+    /// 
+    /// </summary>
+    [Obsolete]
+    public class ShortFieldSource : FieldCacheSource
+    {
+        readonly FieldCache.IShortParser parser;
+
+        public ShortFieldSource(string field)
+            : this(field, null)
+        {
+        }
+
+        public ShortFieldSource(string field, FieldCache.IShortParser parser)
+            : base(field)
+        {
+            this.parser = parser;
+        }
+
+        public override string Description
+        {
+            get { return "short(" + field + ')'; }
+        }
+
+        public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext)
+        {
+            var arr = cache.GetShorts(readerContext.AtomicReader, field, parser, false);
+            return new FunctionValuesAnonymousInnerClassHelper(this, arr);
+        }
+
+        private class FunctionValuesAnonymousInnerClassHelper : FunctionValues
+        {
+            private readonly ShortFieldSource outerInstance;
+            private readonly FieldCache.Shorts arr;
+
+            public FunctionValuesAnonymousInnerClassHelper(ShortFieldSource outerInstance, FieldCache.Shorts arr)
+            {
+                this.outerInstance = outerInstance;
+                this.arr = arr;
+            }
+
+            public override sbyte ByteVal(int doc)
+            {
+                return (sbyte)arr.Get(doc);
+            }
+
+            public override short ShortVal(int doc)
+            {
+                return arr.Get(doc);
+            }
+
+            public override float FloatVal(int doc)
+            {
+                return (float)arr.Get(doc);
+            }
+
+            public override int IntVal(int doc)
+            {
+                return (int)arr.Get(doc);
+            }
+
+            public override long LongVal(int doc)
+            {
+                return (long)arr.Get(doc);
+            }
+
+            public override double DoubleVal(int doc)
+            {
+                return arr.Get(doc);
+            }
+
+            public override string StrVal(int doc)
+            {
+                return Convert.ToString(arr.Get(doc));
+            }
+
+            public override string ToString(int doc)
+            {
+                return outerInstance.Description + '=' + ShortVal(doc);
+            }
+
+        }
+
+        public override bool Equals(object o)
+        {
+            var other = o as ShortFieldSource;
+            if (other == null)
+                return false;
+            return base.Equals(other) && (parser == null ? other.parser == null : parser.GetType() == other.parser.GetType());
+        }
+
+        public override int GetHashCode()
+        {
+            var h = parser == null ? typeof(short?).GetHashCode() : parser.GetType().GetHashCode();
+            h += base.GetHashCode();
+            return h;
+        }
+    }
 }
\ No newline at end of file