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/19 16:19:43 UTC

[10/21] Moving ValueSource -> ValueSources to avoid name conflicts

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/2b55e53c/src/Lucene.Net.Queries/Function/ValueSources/DocFreqValueSource.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/DocFreqValueSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/DocFreqValueSource.cs
new file mode 100644
index 0000000..c9b467a
--- /dev/null
+++ b/src/Lucene.Net.Queries/Function/ValueSources/DocFreqValueSource.cs
@@ -0,0 +1,177 @@
+/*
+ * 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 System;
+using System.Collections;
+using org.apache.lucene.queries.function;
+using org.apache.lucene.queries.function.docvalues;
+
+namespace Lucene.Net.Queries.Function.ValueSources
+{
+    internal class ConstIntDocValues : IntDocValues
+	{
+	  internal readonly int ival;
+	  internal readonly float fval;
+	  internal readonly double dval;
+	  internal readonly long lval;
+	  internal readonly string sval;
+	  internal readonly ValueSource parent;
+
+	  internal ConstIntDocValues(int val, ValueSource parent) : base(parent)
+	  {
+		ival = val;
+		fval = val;
+		dval = val;
+		lval = val;
+		sval = Convert.ToString(val);
+		this.parent = parent;
+	  }
+
+	  public override float floatVal(int doc)
+	  {
+		return fval;
+	  }
+	  public override int intVal(int doc)
+	  {
+		return ival;
+	  }
+	  public override long longVal(int doc)
+	  {
+		return lval;
+	  }
+	  public override double doubleVal(int doc)
+	  {
+		return dval;
+	  }
+	  public override string strVal(int doc)
+	  {
+		return sval;
+	  }
+	  public override string ToString(int doc)
+	  {
+		return parent.description() + '=' + sval;
+	  }
+	}
+
+	internal class ConstDoubleDocValues : DoubleDocValues
+	{
+	  internal readonly int ival;
+	  internal readonly float fval;
+	  internal readonly double dval;
+	  internal readonly long lval;
+	  internal readonly string sval;
+	  internal readonly ValueSource parent;
+
+	  internal ConstDoubleDocValues(double val, ValueSource parent) : base(parent)
+	  {
+		ival = (int)val;
+		fval = (float)val;
+		dval = val;
+		lval = (long)val;
+		sval = Convert.ToString(val);
+		this.parent = parent;
+	  }
+
+	  public override float floatVal(int doc)
+	  {
+		return fval;
+	  }
+	  public override int intVal(int doc)
+	  {
+		return ival;
+	  }
+	  public override long longVal(int doc)
+	  {
+		return lval;
+	  }
+	  public override double doubleVal(int doc)
+	  {
+		return dval;
+	  }
+	  public override string strVal(int doc)
+	  {
+		return sval;
+	  }
+	  public override string ToString(int doc)
+	  {
+		return parent.description() + '=' + sval;
+	  }
+	}
+
+
+	/// <summary>
+	/// <code>DocFreqValueSource</code> returns the number of documents containing the term.
+	/// @lucene.internal
+	/// </summary>
+	public class DocFreqValueSource : ValueSource
+	{
+	  protected internal readonly string field;
+	  protected internal readonly string indexedField;
+	  protected internal readonly string val;
+	  protected internal readonly BytesRef indexedBytes;
+
+	  public DocFreqValueSource(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 "docfreq";
+	  }
+
+	  public override string description()
+	  {
+		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)
+	  {
+		IndexSearcher searcher = (IndexSearcher)context["searcher"];
+		int docfreq = searcher.IndexReader.docFreq(new Term(indexedField, indexedBytes));
+		return new ConstIntDocValues(docfreq, 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)
+	  {
+		context["searcher"] = searcher;
+	  }
+
+	  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;
+		}
+		DocFreqValueSource other = (DocFreqValueSource)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/2b55e53c/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
new file mode 100644
index 0000000..97806b5
--- /dev/null
+++ b/src/Lucene.Net.Queries/Function/ValueSources/DoubleConstValueSource.cs
@@ -0,0 +1,162 @@
+/*
+ * 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 System;
+using System.Collections;
+using org.apache.lucene.queries.function;
+using org.apache.lucene.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;
+	  }
+
+	  public override string description()
+	  {
+		return "const(" + constant + ")";
+	  }
+
+//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 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 = double.doubleToRawLongBits(constant);
+		return (int)(bits ^ ((long)((ulong)bits >> 32)));
+	  }
+
+	  public override bool Equals(object o)
+	  {
+		if (!(o is DoubleConstValueSource))
+		{
+			return false;
+		}
+		DoubleConstValueSource other = (DoubleConstValueSource) o;
+		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/2b55e53c/src/Lucene.Net.Queries/Function/ValueSources/DoubleFieldSource.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/DoubleFieldSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/DoubleFieldSource.cs
new file mode 100644
index 0000000..d9c09dc
--- /dev/null
+++ b/src/Lucene.Net.Queries/Function/ValueSources/DoubleFieldSource.cs
@@ -0,0 +1,140 @@
+using System.Collections;
+/*
+ * 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 org.apache.lucene.queries.function;
+using org.apache.lucene.queries.function.docvalues;
+
+namespace Lucene.Net.Queries.Function.ValueSources
+{
+    /// <summary>
+	/// Obtains double field values from <seealso cref="FieldCache#getDoubles"/> and makes
+	/// those values available as other numeric types, casting as needed.
+	/// </summary>
+	public class DoubleFieldSource : FieldCacheSource
+	{
+
+	  protected internal readonly FieldCache.DoubleParser parser;
+
+	  public DoubleFieldSource(string field) : this(field, null)
+	  {
+	  }
+
+	  public DoubleFieldSource(string field, FieldCache.DoubleParser parser) : base(field)
+	  {
+		this.parser = parser;
+	  }
+
+	  public override string description()
+	  {
+		return "double(" + 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.Doubles arr = cache.getDoubles(readerContext.reader(), field, parser, true);
+		FieldCache.Doubles arr = cache.getDoubles(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 DoubleDocValuesAnonymousInnerClassHelper(this, this, arr, valid);
+
+	  }
+
+	  private class DoubleDocValuesAnonymousInnerClassHelper : DoubleDocValues
+	  {
+		  private readonly DoubleFieldSource outerInstance;
+
+		  private FieldCache.Doubles arr;
+		  private Bits valid;
+
+		  public DoubleDocValuesAnonymousInnerClassHelper(DoubleFieldSource outerInstance, DoubleFieldSource this, FieldCache.Doubles arr, Bits valid) : base(this)
+		  {
+			  this.outerInstance = outerInstance;
+			  this.arr = arr;
+			  this.valid = valid;
+		  }
+
+		  public override double doubleVal(int doc)
+		  {
+			return arr.get(doc);
+		  }
+
+		  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 DoubleDocValuesAnonymousInnerClassHelper outerInstance;
+
+			  public ValueFillerAnonymousInnerClassHelper(DoubleDocValuesAnonymousInnerClassHelper outerInstance)
+			  {
+				  this.outerInstance = outerInstance;
+				  mval = new MutableValueDouble();
+			  }
+
+			  private readonly MutableValueDouble 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(DoubleFieldSource))
+		{
+			return false;
+		}
+		DoubleFieldSource other = (DoubleFieldSource) 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(double?).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/2b55e53c/src/Lucene.Net.Queries/Function/ValueSources/DualFloatFunction.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/DualFloatFunction.cs b/src/Lucene.Net.Queries/Function/ValueSources/DualFloatFunction.cs
new file mode 100644
index 0000000..47a0b42
--- /dev/null
+++ b/src/Lucene.Net.Queries/Function/ValueSources/DualFloatFunction.cs
@@ -0,0 +1,116 @@
+/*
+ * 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 System.Collections;
+using org.apache.lucene.queries.function;
+using org.apache.lucene.queries.function.docvalues;
+
+namespace Lucene.Net.Queries.Function.ValueSources
+{
+    /// <summary>
+	/// Abstract <seealso cref="ValueSource"/> implementation which wraps two ValueSources
+	/// and applies an extendible float function to their values.
+	/// 
+	/// </summary>
+	public abstract class DualFloatFunction : ValueSource
+	{
+	  protected internal readonly ValueSource a;
+	  protected internal readonly ValueSource b;
+
+	 /// <param name="a">  the base. </param>
+	 /// <param name="b">  the exponent. </param>
+	  public DualFloatFunction(ValueSource a, ValueSource b)
+	  {
+		this.a = a;
+		this.b = b;
+	  }
+
+	  protected internal abstract string name();
+	  protected internal abstract float func(int doc, FunctionValues aVals, FunctionValues bVals);
+
+	  public override string description()
+	  {
+		return name() + "(" + a.description() + "," + b.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 aVals = a.getValues(context, readerContext);
+		FunctionValues aVals = a.getValues(context, readerContext);
+//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
+//ORIGINAL LINE: final org.apache.lucene.queries.function.FunctionValues bVals = b.getValues(context, readerContext);
+		FunctionValues bVals = b.getValues(context, readerContext);
+		return new FloatDocValuesAnonymousInnerClassHelper(this, this, aVals, bVals);
+	  }
+
+	  private class FloatDocValuesAnonymousInnerClassHelper : FloatDocValues
+	  {
+		  private readonly DualFloatFunction outerInstance;
+
+		  private FunctionValues aVals;
+		  private FunctionValues bVals;
+
+		  public FloatDocValuesAnonymousInnerClassHelper(DualFloatFunction outerInstance, DualFloatFunction this, FunctionValues aVals, FunctionValues bVals) : base(this)
+		  {
+			  this.outerInstance = outerInstance;
+			  this.aVals = aVals;
+			  this.bVals = bVals;
+		  }
+
+		  public override float floatVal(int doc)
+		  {
+			return outerInstance.func(doc, aVals, bVals);
+		  }
+
+		  public override string ToString(int doc)
+		  {
+			return outerInstance.name() + '(' + aVals.ToString(doc) + ',' + bVals.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)
+	  {
+		a.createWeight(context,searcher);
+		b.createWeight(context,searcher);
+	  }
+
+	  public override int GetHashCode()
+	  {
+		int h = a.GetHashCode();
+		h ^= (h << 13) | ((int)((uint)h >> 20));
+		h += b.GetHashCode();
+		h ^= (h << 23) | ((int)((uint)h >> 10));
+		h += name().GetHashCode();
+		return h;
+	  }
+
+	  public override bool Equals(object o)
+	  {
+		if (this.GetType() != o.GetType())
+		{
+			return false;
+		}
+		DualFloatFunction other = (DualFloatFunction)o;
+		return this.a.Equals(other.a) && this.b.Equals(other.b);
+	  }
+	}
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/2b55e53c/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
new file mode 100644
index 0000000..a7fe04c
--- /dev/null
+++ b/src/Lucene.Net.Queries/Function/ValueSources/EnumFieldSource.cs
@@ -0,0 +1,335 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using org.apache.lucene.queries.function;
+using org.apache.lucene.queries.function.docvalues;
+
+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.
+	 */
+    /// <summary>
+	/// Obtains int field values from <seealso cref="FieldCache#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
+	/// </summary>
+	public class EnumFieldSource : FieldCacheSource
+	{
+	  internal const int? DEFAULT_VALUE = -1;
+
+	  internal readonly FieldCache.IntParser parser;
+	  internal readonly IDictionary<int?, string> enumIntToStringMap;
+	  internal readonly IDictionary<string, int?> enumStringToIntMap;
+
+	  public EnumFieldSource(string field, FieldCache.IntParser parser, IDictionary<int?, string> enumIntToStringMap, IDictionary<string, int?> enumStringToIntMap) : base(field)
+	  {
+		this.parser = parser;
+		this.enumIntToStringMap = enumIntToStringMap;
+		this.enumStringToIntMap = enumStringToIntMap;
+	  }
+
+	  private static int? tryParseInt(string valueStr)
+	  {
+		int? intValue = null;
+		try
+		{
+		  intValue = Convert.ToInt32(valueStr);
+		}
+		catch (NumberFormatException)
+		{
+		}
+		return intValue;
+	  }
+
+	  private string intValueToStringValue(int? intVal)
+	  {
+		if (intVal == null)
+		{
+		  return null;
+		}
+
+//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
+//ORIGINAL LINE: final String enumString = enumIntToStringMap.get(intVal);
+		string enumString = enumIntToStringMap[intVal];
+		if (enumString != null)
+		{
+		  return enumString;
+		}
+		// can't find matching enum name - return DEFAULT_VALUE.toString()
+		return DEFAULT_VALUE.ToString();
+	  }
+
+	  private int? stringValueToIntValue(string stringVal)
+	  {
+		if (stringVal == null)
+		{
+		  return null;
+		}
+
+		int? intValue;
+//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
+//ORIGINAL LINE: final Integer enumInt = enumStringToIntMap.get(stringVal);
+		int? enumInt = enumStringToIntMap[stringVal];
+		if (enumInt != null) //enum int found for string
+		{
+		  return enumInt;
+		}
+
+		//enum int not found for string
+		intValue = tryParseInt(stringVal);
+		if (intValue == null) //not Integer
+		{
+		  intValue = DEFAULT_VALUE;
+		}
+//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
+//ORIGINAL LINE: final String enumString = enumIntToStringMap.get(intValue);
+		string enumString = enumIntToStringMap[intValue];
+		if (enumString != null) //has matching string
+		{
+		  return intValue;
+		}
+
+		return DEFAULT_VALUE;
+	  }
+
+	  public override string description()
+	  {
+		return "enum(" + 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 EnumFieldSource outerInstance;
+
+		  private FieldCache.Ints arr;
+		  private Bits valid;
+
+		  public IntDocValuesAnonymousInnerClassHelper(EnumFieldSource outerInstance, EnumFieldSource this, FieldCache.Ints arr, Bits valid) : base(this)
+		  {
+			  this.outerInstance = outerInstance;
+			  this.arr = arr;
+			  this.valid = valid;
+			  val = new MutableValueInt();
+		  }
+
+		  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)
+		  {
+			int? intValue = arr.get(doc);
+			return outerInstance.intValueToStringValue(intValue);
+		  }
+
+		  public override object objectVal(int doc)
+		  {
+			return valid.get(doc) ? arr.get(doc) : null;
+		  }
+
+		  public override bool exists(int doc)
+		  {
+			return valid.get(doc);
+		  }
+
+		  public override string ToString(int doc)
+		  {
+			return outerInstance.description() + '=' + strVal(doc);
+		  }
+
+
+		  public override ValueSourceScorer getRangeScorer(IndexReader reader, string lowerVal, string upperVal, bool includeLower, bool includeUpper)
+		  {
+			int? lower = outerInstance.stringValueToIntValue(lowerVal);
+			int? upper = outerInstance.stringValueToIntValue(upperVal);
+
+			// instead of using separate comparison functions, adjust the endpoints.
+
+			if (lower == null)
+			{
+			  lower = int.MinValue;
+			}
+			else
+			{
+			  if (!includeLower && lower < int.MaxValue)
+			  {
+				  lower++;
+			  }
+			}
+
+			if (upper == null)
+			{
+			  upper = int.MaxValue;
+			}
+			else
+			{
+			  if (!includeUpper && upper > int.MinValue)
+			  {
+				  upper--;
+			  }
+			}
+
+//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
+//ORIGINAL LINE: final int ll = lower;
+			int ll = lower.Value;
+//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
+//ORIGINAL LINE: final int uu = upper;
+			int uu = upper.Value;
+
+			return new ValueSourceScorerAnonymousInnerClassHelper(this, reader, this, ll, uu);
+		  }
+
+		  private class ValueSourceScorerAnonymousInnerClassHelper : ValueSourceScorer
+		  {
+			  private readonly IntDocValuesAnonymousInnerClassHelper outerInstance;
+
+			  private int ll;
+			  private int uu;
+
+			  public ValueSourceScorerAnonymousInnerClassHelper(IntDocValuesAnonymousInnerClassHelper outerInstance, IndexReader reader, EnumFieldSource this, int ll, int uu) : base(reader, this)
+			  {
+				  this.outerInstance = outerInstance;
+				  this.ll = ll;
+				  this.uu = uu;
+			  }
+
+			  public override bool matchesValue(int doc)
+			  {
+				int val = outerInstance.arr.get(doc);
+				// only check for deleted if it's the default value
+				// if (val==0 && reader.isDeleted(doc)) return false;
+				return val >= ll && val <= uu;
+			  }
+		  }
+
+		  public override 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 = outerInstance.valid.get(doc);
+			  }
+		  }
+
+
+	  }
+
+	  public override bool Equals(object o)
+	  {
+		if (this == o)
+		{
+			return true;
+		}
+		if (o == null || this.GetType() != o.GetType())
+		{
+			return false;
+		}
+		if (!base.Equals(o))
+		{
+			return false;
+		}
+
+		EnumFieldSource that = (EnumFieldSource) o;
+
+		if (!enumIntToStringMap.Equals(that.enumIntToStringMap))
+		{
+			return false;
+		}
+		if (!enumStringToIntMap.Equals(that.enumStringToIntMap))
+		{
+			return false;
+		}
+		if (!parser.Equals(that.parser))
+		{
+			return false;
+		}
+
+		return true;
+	  }
+
+	  public override int GetHashCode()
+	  {
+		int result = base.GetHashCode();
+		result = 31 * result + parser.GetHashCode();
+		result = 31 * result + enumIntToStringMap.GetHashCode();
+		result = 31 * result + enumStringToIntMap.GetHashCode();
+		return result;
+	  }
+	}
+
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/2b55e53c/src/Lucene.Net.Queries/Function/ValueSources/FieldCacheSource.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/FieldCacheSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/FieldCacheSource.cs
new file mode 100644
index 0000000..ab76bfa
--- /dev/null
+++ b/src/Lucene.Net.Queries/Function/ValueSources/FieldCacheSource.cs
@@ -0,0 +1,74 @@
+/*
+ * 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.
+ */
+
+namespace Lucene.Net.Queries.Function.ValueSources
+{
+    /// <summary>
+	/// A base class for ValueSource implementations that retrieve values for
+	/// a single field from the <seealso cref="org.apache.lucene.search.FieldCache"/>.
+	/// 
+	/// 
+	/// </summary>
+	public abstract class FieldCacheSource : ValueSource
+	{
+	  protected internal readonly string field;
+	  protected internal readonly FieldCache cache = FieldCache.DEFAULT;
+
+	  public FieldCacheSource(string field)
+	  {
+		this.field = field;
+	  }
+
+	  public virtual FieldCache FieldCache
+	  {
+		  get
+		  {
+			return cache;
+		  }
+	  }
+
+	  public virtual string Field
+	  {
+		  get
+		  {
+			return field;
+		  }
+	  }
+
+	  public override string description()
+	  {
+		return field;
+	  }
+
+	  public override bool Equals(object o)
+	  {
+		if (!(o is FieldCacheSource))
+		{
+			return false;
+		}
+		FieldCacheSource other = (FieldCacheSource)o;
+		return this.field.Equals(other.field) && this.cache == other.cache;
+	  }
+
+	  public override int GetHashCode()
+	  {
+		return cache.GetHashCode() + field.GetHashCode();
+	  }
+
+	}
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/2b55e53c/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
new file mode 100644
index 0000000..a40f119
--- /dev/null
+++ b/src/Lucene.Net.Queries/Function/ValueSources/FloatFieldSource.cs
@@ -0,0 +1,144 @@
+/*
+ * 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 System.Collections;
+using org.apache.lucene.queries.function;
+using org.apache.lucene.queries.function.docvalues;
+
+namespace Lucene.Net.Queries.Function.ValueSources
+{
+    /// <summary>
+	/// Obtains float field values from <seealso cref="FieldCache#getFloats"/> and makes those
+	/// values available as other numeric types, casting as needed.
+	/// </summary>
+	public class FloatFieldSource : FieldCacheSource
+	{
+
+	  protected internal readonly FieldCache.FloatParser parser;
+
+	  public FloatFieldSource(string field) : this(field, null)
+	  {
+	  }
+
+	  public FloatFieldSource(string field, FieldCache.FloatParser parser) : base(field)
+	  {
+		this.parser = parser;
+	  }
+
+	  public override string description()
+	  {
+		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.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 FloatDocValuesAnonymousInnerClassHelper(this, this, arr, valid);
+	  }
+
+	  private class FloatDocValuesAnonymousInnerClassHelper : FloatDocValues
+	  {
+		  private readonly FloatFieldSource outerInstance;
+
+		  private FieldCache.Floats arr;
+		  private 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;
+	  }
+	}
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/2b55e53c/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
new file mode 100644
index 0000000..38532e2
--- /dev/null
+++ b/src/Lucene.Net.Queries/Function/ValueSources/IDFValueSource.cs
@@ -0,0 +1,76 @@
+/*
+ * 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 System.Collections;
+using org.apache.lucene.queries.function;
+
+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)
+	  {
+	  }
+
+	  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;
+		}
+	  }
+	}
+
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/2b55e53c/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
new file mode 100644
index 0000000..8fee427
--- /dev/null
+++ b/src/Lucene.Net.Queries/Function/ValueSources/IfFunction.cs
@@ -0,0 +1,177 @@
+/*
+ * 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 System.Collections;
+using org.apache.lucene.queries.function;
+
+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);
+	  }
+	}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/2b55e53c/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
new file mode 100644
index 0000000..5ed7345
--- /dev/null
+++ b/src/Lucene.Net.Queries/Function/ValueSources/IntFieldSource.cs
@@ -0,0 +1,174 @@
+/*
+ * 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 System;
+using System.Collections;
+using org.apache.lucene.queries.function;
+using org.apache.lucene.queries.function.docvalues;
+
+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;
+	  }
+	}
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/2b55e53c/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
new file mode 100644
index 0000000..3319eda
--- /dev/null
+++ b/src/Lucene.Net.Queries/Function/ValueSources/JoinDocFreqValueSource.cs
@@ -0,0 +1,122 @@
+/*
+ * 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 System;
+using System.Collections;
+using org.apache.lucene.queries.function;
+using org.apache.lucene.queries.function.docvalues;
+
+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
+	{
+
+	  public const string NAME = "joindf";
+
+	  protected internal readonly string qfield;
+
+	  public JoinDocFreqValueSource(string field, string qfield) : base(field)
+	  {
+		this.qfield = qfield;
+	  }
+
+	  public override string description()
+	  {
+		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);
+
+		return new IntDocValuesAnonymousInnerClassHelper(this, this, terms, termsEnum);
+	  }
+
+	  private class IntDocValuesAnonymousInnerClassHelper : IntDocValues
+	  {
+		  private readonly JoinDocFreqValueSource outerInstance;
+
+		  private BinaryDocValues terms;
+		  private 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();
+		  }
+
+		  internal 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 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();
+	  }
+	}
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/2b55e53c/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
new file mode 100644
index 0000000..7924547
--- /dev/null
+++ b/src/Lucene.Net.Queries/Function/ValueSources/LinearFloatFunction.cs
@@ -0,0 +1,108 @@
+/*
+ * 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 System.Collections;
+using org.apache.lucene.queries.function;
+using org.apache.lucene.queries.function.docvalues;
+
+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;
+
+	  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;
+	  }
+
+//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);
+	  }
+
+	  private class FloatDocValuesAnonymousInnerClassHelper : FloatDocValues
+	  {
+		  private readonly LinearFloatFunction outerInstance;
+
+		  private FunctionValues 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;
+		  }
+	  }
+
+//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 = float.floatToIntBits(slope);
+		h = ((int)((uint)h >> 2)) | (h << 30);
+		h += float.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);
+	  }
+	}
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/2b55e53c/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
new file mode 100644
index 0000000..4b91199
--- /dev/null
+++ b/src/Lucene.Net.Queries/Function/ValueSources/LiteralValueSource.cs
@@ -0,0 +1,112 @@
+using System.Collections;
+using org.apache.lucene.queries.function;
+using org.apache.lucene.queries.function.docvalues;
+
+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.
+	 */
+    /// <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();
+	  }
+	}
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/2b55e53c/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
new file mode 100644
index 0000000..00b902f
--- /dev/null
+++ b/src/Lucene.Net.Queries/Function/ValueSources/LongFieldSource.cs
@@ -0,0 +1,175 @@
+/*
+ * 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 System;
+using System.Collections;
+using org.apache.lucene.queries.function;
+using org.apache.lucene.queries.function.docvalues;
+
+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;
+	  }
+	}
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/2b55e53c/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
new file mode 100644
index 0000000..0d65888
--- /dev/null
+++ b/src/Lucene.Net.Queries/Function/ValueSources/MaxDocValueSource.cs
@@ -0,0 +1,68 @@
+/*
+ * 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 System.Collections;
+using org.apache.lucene.queries.function;
+
+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();
+	  }
+	}
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/2b55e53c/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
new file mode 100644
index 0000000..ba86891
--- /dev/null
+++ b/src/Lucene.Net.Queries/Function/ValueSources/MaxFloatFunction.cs
@@ -0,0 +1,53 @@
+/*
+ * 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 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 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;
+	  }
+	}
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/2b55e53c/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
new file mode 100644
index 0000000..8905f5b
--- /dev/null
+++ b/src/Lucene.Net.Queries/Function/ValueSources/MinFloatFunction.cs
@@ -0,0 +1,53 @@
+/*
+ * 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 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 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;
+	  }
+	}
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/2b55e53c/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
new file mode 100644
index 0000000..5419e47
--- /dev/null
+++ b/src/Lucene.Net.Queries/Function/ValueSources/MultiBoolFunction.cs
@@ -0,0 +1,143 @@
+/*
+ * 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 System.Collections;
+using System.Collections.Generic;
+using System.Text;
+using org.apache.lucene.queries.function;
+using org.apache.lucene.queries.function.docvalues;
+
+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);
+		}
+	  }
+	}
+
+}
\ No newline at end of file