lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From synhers...@apache.org
Subject [05/11] Skeleton porting of Lucene.Net.Queries
Date Mon, 15 Sep 2014 22:47:03 GMT
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/882f487d/src/Lucene.Net.Queries/Function/ValueSource/DivFloatFunction.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSource/DivFloatFunction.cs b/src/Lucene.Net.Queries/Function/ValueSource/DivFloatFunction.cs
new file mode 100644
index 0000000..08912e5
--- /dev/null
+++ b/src/Lucene.Net.Queries/Function/ValueSource/DivFloatFunction.cs
@@ -0,0 +1,44 @@
+/*
+ * 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 org.apache.lucene.queries.function.valuesource
+{
+
+
+	/// <summary>
+	/// Function to divide "a" by "b"
+	/// </summary>
+	public class DivFloatFunction : DualFloatFunction
+	{
+	 /// <param name="a">  the numerator. </param>
+	 /// <param name="b">  the denominator. </param>
+	  public DivFloatFunction(ValueSource a, ValueSource b) : base(a,b)
+	  {
+	  }
+
+	  protected internal override string name()
+	  {
+		return "div";
+	  }
+
+	  protected internal override float func(int doc, FunctionValues aVals, FunctionValues bVals)
+	  {
+		return aVals.floatVal(doc) / bVals.floatVal(doc);
+	  }
+	}
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/882f487d/src/Lucene.Net.Queries/Function/ValueSource/DocFreqValueSource.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSource/DocFreqValueSource.cs b/src/Lucene.Net.Queries/Function/ValueSource/DocFreqValueSource.cs
new file mode 100644
index 0000000..56ea07d
--- /dev/null
+++ b/src/Lucene.Net.Queries/Function/ValueSource/DocFreqValueSource.cs
@@ -0,0 +1,186 @@
+using System;
+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.
+ */
+
+namespace org.apache.lucene.queries.function.valuesource
+{
+
+	using AtomicReaderContext = org.apache.lucene.index.AtomicReaderContext;
+	using Term = org.apache.lucene.index.Term;
+	using DoubleDocValues = org.apache.lucene.queries.function.docvalues.DoubleDocValues;
+	using IntDocValues = org.apache.lucene.queries.function.docvalues.IntDocValues;
+	using IndexSearcher = org.apache.lucene.search.IndexSearcher;
+	using BytesRef = org.apache.lucene.util.BytesRef;
+
+
+
+	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/882f487d/src/Lucene.Net.Queries/Function/ValueSource/DoubleConstValueSource.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSource/DoubleConstValueSource.cs b/src/Lucene.Net.Queries/Function/ValueSource/DoubleConstValueSource.cs
new file mode 100644
index 0000000..e21be0c
--- /dev/null
+++ b/src/Lucene.Net.Queries/Function/ValueSource/DoubleConstValueSource.cs
@@ -0,0 +1,166 @@
+using System;
+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.
+ */
+
+namespace org.apache.lucene.queries.function.valuesource
+{
+
+	using AtomicReaderContext = org.apache.lucene.index.AtomicReaderContext;
+	using DoubleDocValues = org.apache.lucene.queries.function.docvalues.DoubleDocValues;
+
+
+	/// <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, org.apache.lucene.queries.function.valuesource.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/882f487d/src/Lucene.Net.Queries/Function/ValueSource/DoubleFieldSource.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSource/DoubleFieldSource.cs b/src/Lucene.Net.Queries/Function/ValueSource/DoubleFieldSource.cs
new file mode 100644
index 0000000..188974f
--- /dev/null
+++ b/src/Lucene.Net.Queries/Function/ValueSource/DoubleFieldSource.cs
@@ -0,0 +1,149 @@
+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.
+ */
+
+namespace org.apache.lucene.queries.function.valuesource
+{
+
+
+	using AtomicReaderContext = org.apache.lucene.index.AtomicReaderContext;
+	using IndexReader = org.apache.lucene.index.IndexReader;
+	using DoubleDocValues = org.apache.lucene.queries.function.docvalues.DoubleDocValues;
+	using FieldCache = org.apache.lucene.search.FieldCache;
+	using Bits = org.apache.lucene.util.Bits;
+	using MutableValue = org.apache.lucene.util.mutable.MutableValue;
+	using MutableValueDouble = org.apache.lucene.util.mutable.MutableValueDouble;
+
+	/// <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, org.apache.lucene.queries.function.valuesource.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/882f487d/src/Lucene.Net.Queries/Function/ValueSource/DualFloatFunction.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSource/DualFloatFunction.cs b/src/Lucene.Net.Queries/Function/ValueSource/DualFloatFunction.cs
new file mode 100644
index 0000000..9a9c069
--- /dev/null
+++ b/src/Lucene.Net.Queries/Function/ValueSource/DualFloatFunction.cs
@@ -0,0 +1,121 @@
+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.
+ */
+
+namespace org.apache.lucene.queries.function.valuesource
+{
+
+	using AtomicReaderContext = org.apache.lucene.index.AtomicReaderContext;
+	using FloatDocValues = org.apache.lucene.queries.function.docvalues.FloatDocValues;
+	using IndexSearcher = org.apache.lucene.search.IndexSearcher;
+
+
+	/// <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, org.apache.lucene.queries.function.valuesource.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/882f487d/src/Lucene.Net.Queries/Function/ValueSource/EnumFieldSource.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSource/EnumFieldSource.cs b/src/Lucene.Net.Queries/Function/ValueSource/EnumFieldSource.cs
new file mode 100644
index 0000000..cbdf2cb
--- /dev/null
+++ b/src/Lucene.Net.Queries/Function/ValueSource/EnumFieldSource.cs
@@ -0,0 +1,343 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+
+namespace org.apache.lucene.queries.function.valuesource
+{
+
+	/*
+	 * 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 AtomicReaderContext = org.apache.lucene.index.AtomicReaderContext;
+	using IndexReader = org.apache.lucene.index.IndexReader;
+	using IntDocValues = org.apache.lucene.queries.function.docvalues.IntDocValues;
+	using FieldCache = org.apache.lucene.search.FieldCache;
+	using Bits = org.apache.lucene.util.Bits;
+	using MutableValue = org.apache.lucene.util.mutable.MutableValue;
+	using MutableValueInt = org.apache.lucene.util.mutable.MutableValueInt;
+
+	/// <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, org.apache.lucene.queries.function.valuesource.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, org.apache.lucene.queries.function.valuesource.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/882f487d/src/Lucene.Net.Queries/Function/ValueSource/FieldCacheSource.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSource/FieldCacheSource.cs b/src/Lucene.Net.Queries/Function/ValueSource/FieldCacheSource.cs
new file mode 100644
index 0000000..92c2cb4
--- /dev/null
+++ b/src/Lucene.Net.Queries/Function/ValueSource/FieldCacheSource.cs
@@ -0,0 +1,77 @@
+/*
+ * 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 org.apache.lucene.queries.function.valuesource
+{
+
+	using FieldCache = org.apache.lucene.search.FieldCache;
+
+	/// <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/882f487d/src/Lucene.Net.Queries/Function/ValueSource/FloatFieldSource.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSource/FloatFieldSource.cs b/src/Lucene.Net.Queries/Function/ValueSource/FloatFieldSource.cs
new file mode 100644
index 0000000..c60d99f
--- /dev/null
+++ b/src/Lucene.Net.Queries/Function/ValueSource/FloatFieldSource.cs
@@ -0,0 +1,152 @@
+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.
+ */
+
+namespace org.apache.lucene.queries.function.valuesource
+{
+
+
+	using AtomicReaderContext = org.apache.lucene.index.AtomicReaderContext;
+	using FloatDocValues = org.apache.lucene.queries.function.docvalues.FloatDocValues;
+	using FieldCache = org.apache.lucene.search.FieldCache;
+	using Bits = org.apache.lucene.util.Bits;
+	using MutableValue = org.apache.lucene.util.mutable.MutableValue;
+	using MutableValueFloat = org.apache.lucene.util.mutable.MutableValueFloat;
+
+	/// <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, org.apache.lucene.queries.function.valuesource.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/882f487d/src/Lucene.Net.Queries/Function/ValueSource/IDFValueSource.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSource/IDFValueSource.cs b/src/Lucene.Net.Queries/Function/ValueSource/IDFValueSource.cs
new file mode 100644
index 0000000..13456ff
--- /dev/null
+++ b/src/Lucene.Net.Queries/Function/ValueSource/IDFValueSource.cs
@@ -0,0 +1,85 @@
+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.
+ */
+
+namespace org.apache.lucene.queries.function.valuesource
+{
+
+	using org.apache.lucene.index;
+	using IndexSearcher = org.apache.lucene.search.IndexSearcher;
+	using PerFieldSimilarityWrapper = org.apache.lucene.search.similarities.PerFieldSimilarityWrapper;
+	using Similarity = org.apache.lucene.search.similarities.Similarity;
+	using TFIDFSimilarity = org.apache.lucene.search.similarities.TFIDFSimilarity;
+	using BytesRef = org.apache.lucene.util.BytesRef;
+
+
+	/// <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/882f487d/src/Lucene.Net.Queries/Function/ValueSource/IfFunction.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSource/IfFunction.cs b/src/Lucene.Net.Queries/Function/ValueSource/IfFunction.cs
new file mode 100644
index 0000000..a62c801
--- /dev/null
+++ b/src/Lucene.Net.Queries/Function/ValueSource/IfFunction.cs
@@ -0,0 +1,186 @@
+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.
+ */
+
+namespace org.apache.lucene.queries.function.valuesource
+{
+
+	using AtomicReaderContext = org.apache.lucene.index.AtomicReaderContext;
+	using IndexReader = org.apache.lucene.index.IndexReader;
+	using Explanation = org.apache.lucene.search.Explanation;
+	using IndexSearcher = org.apache.lucene.search.IndexSearcher;
+	using BytesRef = org.apache.lucene.util.BytesRef;
+
+
+
+	/// <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/882f487d/src/Lucene.Net.Queries/Function/ValueSource/IntFieldSource.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSource/IntFieldSource.cs b/src/Lucene.Net.Queries/Function/ValueSource/IntFieldSource.cs
new file mode 100644
index 0000000..bb6cf35
--- /dev/null
+++ b/src/Lucene.Net.Queries/Function/ValueSource/IntFieldSource.cs
@@ -0,0 +1,183 @@
+using System;
+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.
+ */
+
+namespace org.apache.lucene.queries.function.valuesource
+{
+
+
+	using AtomicReaderContext = org.apache.lucene.index.AtomicReaderContext;
+	using IndexReader = org.apache.lucene.index.IndexReader;
+	using IntDocValues = org.apache.lucene.queries.function.docvalues.IntDocValues;
+	using FieldCache = org.apache.lucene.search.FieldCache;
+	using Bits = org.apache.lucene.util.Bits;
+	using MutableValue = org.apache.lucene.util.mutable.MutableValue;
+	using MutableValueInt = org.apache.lucene.util.mutable.MutableValueInt;
+
+	/// <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, org.apache.lucene.queries.function.valuesource.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/882f487d/src/Lucene.Net.Queries/Function/ValueSource/JoinDocFreqValueSource.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSource/JoinDocFreqValueSource.cs b/src/Lucene.Net.Queries/Function/ValueSource/JoinDocFreqValueSource.cs
new file mode 100644
index 0000000..46cc5c7
--- /dev/null
+++ b/src/Lucene.Net.Queries/Function/ValueSource/JoinDocFreqValueSource.cs
@@ -0,0 +1,134 @@
+using System;
+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.
+ */
+
+namespace org.apache.lucene.queries.function.valuesource
+{
+
+
+	using AtomicReaderContext = org.apache.lucene.index.AtomicReaderContext;
+	using BinaryDocValues = org.apache.lucene.index.BinaryDocValues;
+	using IndexReader = org.apache.lucene.index.IndexReader;
+	using MultiFields = org.apache.lucene.index.MultiFields;
+	using ReaderUtil = org.apache.lucene.index.ReaderUtil;
+	using Terms = org.apache.lucene.index.Terms;
+	using TermsEnum = org.apache.lucene.index.TermsEnum;
+	using IntDocValues = org.apache.lucene.queries.function.docvalues.IntDocValues;
+	using BytesRef = org.apache.lucene.util.BytesRef;
+	using PackedInts = org.apache.lucene.util.packed.PackedInts;
+
+	/// <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, org.apache.lucene.queries.function.valuesource.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/882f487d/src/Lucene.Net.Queries/Function/ValueSource/LinearFloatFunction.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSource/LinearFloatFunction.cs b/src/Lucene.Net.Queries/Function/ValueSource/LinearFloatFunction.cs
new file mode 100644
index 0000000..a03268c
--- /dev/null
+++ b/src/Lucene.Net.Queries/Function/ValueSource/LinearFloatFunction.cs
@@ -0,0 +1,113 @@
+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.
+ */
+
+namespace org.apache.lucene.queries.function.valuesource
+{
+
+	using AtomicReaderContext = org.apache.lucene.index.AtomicReaderContext;
+	using FloatDocValues = org.apache.lucene.queries.function.docvalues.FloatDocValues;
+	using IndexSearcher = org.apache.lucene.search.IndexSearcher;
+
+
+	/// <summary>
+	/// <code>LinearFloatFunction</code> implements a linear function over
+	/// another <seealso cref="ValueSource"/>.
+	/// <br>
+	/// Normally Used as an argument to a <seealso cref="org.apache.lucene.queries.function.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, org.apache.lucene.queries.function.valuesource.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/882f487d/src/Lucene.Net.Queries/Function/ValueSource/LiteralValueSource.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSource/LiteralValueSource.cs b/src/Lucene.Net.Queries/Function/ValueSource/LiteralValueSource.cs
new file mode 100644
index 0000000..6107a28
--- /dev/null
+++ b/src/Lucene.Net.Queries/Function/ValueSource/LiteralValueSource.cs
@@ -0,0 +1,117 @@
+using System.Collections;
+
+namespace org.apache.lucene.queries.function.valuesource
+{
+	/*
+	 * 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 AtomicReaderContext = org.apache.lucene.index.AtomicReaderContext;
+	using StrDocValues = org.apache.lucene.queries.function.docvalues.StrDocValues;
+	using BytesRef = org.apache.lucene.util.BytesRef;
+
+
+
+	/// <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, org.apache.lucene.queries.function.valuesource.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/882f487d/src/Lucene.Net.Queries/Function/ValueSource/LongFieldSource.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSource/LongFieldSource.cs b/src/Lucene.Net.Queries/Function/ValueSource/LongFieldSource.cs
new file mode 100644
index 0000000..d831ebd
--- /dev/null
+++ b/src/Lucene.Net.Queries/Function/ValueSource/LongFieldSource.cs
@@ -0,0 +1,184 @@
+using System;
+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.
+ */
+
+namespace org.apache.lucene.queries.function.valuesource
+{
+
+
+	using AtomicReaderContext = org.apache.lucene.index.AtomicReaderContext;
+	using IndexReader = org.apache.lucene.index.IndexReader;
+	using LongDocValues = org.apache.lucene.queries.function.docvalues.LongDocValues;
+	using FieldCache = org.apache.lucene.search.FieldCache;
+	using Bits = org.apache.lucene.util.Bits;
+	using MutableValue = org.apache.lucene.util.mutable.MutableValue;
+	using MutableValueLong = org.apache.lucene.util.mutable.MutableValueLong;
+
+	/// <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, org.apache.lucene.queries.function.valuesource.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/882f487d/src/Lucene.Net.Queries/Function/ValueSource/MaxDocValueSource.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSource/MaxDocValueSource.cs b/src/Lucene.Net.Queries/Function/ValueSource/MaxDocValueSource.cs
new file mode 100644
index 0000000..0e00953
--- /dev/null
+++ b/src/Lucene.Net.Queries/Function/ValueSource/MaxDocValueSource.cs
@@ -0,0 +1,70 @@
+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.
+ */
+namespace org.apache.lucene.queries.function.valuesource
+{
+
+	using AtomicReaderContext = org.apache.lucene.index.AtomicReaderContext;
+	using IndexReader = org.apache.lucene.index.IndexReader; // javadocs
+	using IndexSearcher = org.apache.lucene.search.IndexSearcher;
+
+
+	/// <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/882f487d/src/Lucene.Net.Queries/Function/ValueSource/MaxFloatFunction.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSource/MaxFloatFunction.cs b/src/Lucene.Net.Queries/Function/ValueSource/MaxFloatFunction.cs
new file mode 100644
index 0000000..24034c3
--- /dev/null
+++ b/src/Lucene.Net.Queries/Function/ValueSource/MaxFloatFunction.cs
@@ -0,0 +1,53 @@
+using System;
+
+/*
+ * 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 org.apache.lucene.queries.function.valuesource
+{
+
+
+	/// <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/882f487d/src/Lucene.Net.Queries/Function/ValueSource/MinFloatFunction.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSource/MinFloatFunction.cs b/src/Lucene.Net.Queries/Function/ValueSource/MinFloatFunction.cs
new file mode 100644
index 0000000..f4abce7
--- /dev/null
+++ b/src/Lucene.Net.Queries/Function/ValueSource/MinFloatFunction.cs
@@ -0,0 +1,53 @@
+using System;
+
+/*
+ * 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 org.apache.lucene.queries.function.valuesource
+{
+
+
+	/// <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


Mime
View raw message