You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by sy...@apache.org on 2014/09/22 01:56:44 UTC
[2/4] More work on Lucene.Net.Queries
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Queries/Function/ValueSources/NormValueSource.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/NormValueSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/NormValueSource.cs
index a948905..56edfbd 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/NormValueSource.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/NormValueSource.cs
@@ -15,104 +15,97 @@
* limitations under the License.
*/
using System.Collections;
+using Lucene.Net.Index;
using Lucene.Net.Queries.Function.DocValues;
-using org.apache.lucene.queries.function;
+using Lucene.Net.Search;
+using Lucene.Net.Search.Similarities;
namespace Lucene.Net.Queries.Function.ValueSources
{
/// <summary>
- /// Function that returns <seealso cref="TFIDFSimilarity#decodeNormValue(long)"/>
- /// for every document.
- /// <para>
- /// Note that the configured Similarity for the field must be
- /// a subclass of <seealso cref="TFIDFSimilarity"/>
- /// @lucene.internal
- /// </para>
- /// </summary>
- public class NormValueSource : ValueSource
- {
- protected internal readonly string field;
- public NormValueSource(string field)
- {
- this.field = field;
- }
-
- public virtual string name()
- {
- return "norm";
- }
-
- public override string description()
- {
- return name() + '(' + field + ')';
- }
-
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: @Override public void CreateWeight(java.util.Map context, org.apache.lucene.search.IndexSearcher searcher) throws java.io.IOException
- public override void CreateWeight(IDictionary context, IndexSearcher searcher)
- {
- context["searcher"] = searcher;
- }
-
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: @Override public org.apache.lucene.queries.function.FunctionValues GetValues(java.util.Map context, org.apache.lucene.index.AtomicReaderContext readerContext) throws java.io.IOException
- public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext)
- {
- IndexSearcher searcher = (IndexSearcher)context["searcher"];
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final org.apache.lucene.search.similarities.TFIDFSimilarity similarity = IDFValueSource.asTFIDF(searcher.getSimilarity(), field);
- TFIDFSimilarity similarity = IDFValueSource.asTFIDF(searcher.Similarity, field);
- if (similarity == null)
- {
- throw new System.NotSupportedException("requires a TFIDFSimilarity (such as DefaultSimilarity)");
- }
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final org.apache.lucene.index.NumericDocValues norms = readerContext.reader().getNormValues(field);
- NumericDocValues norms = readerContext.reader().getNormValues(field);
-
- if (norms == null)
- {
- return new ConstDoubleDocValues(0.0, this);
- }
-
- return new FloatDocValuesAnonymousInnerClassHelper(this, this, similarity, norms);
- }
-
- private class FloatDocValuesAnonymousInnerClassHelper : FloatDocValues
- {
- private readonly NormValueSource outerInstance;
-
- private TFIDFSimilarity similarity;
- private NumericDocValues norms;
-
- public FloatDocValuesAnonymousInnerClassHelper(NormValueSource outerInstance, NormValueSource this, TFIDFSimilarity similarity, NumericDocValues norms) : base(this)
- {
- this.outerInstance = outerInstance;
- this.similarity = similarity;
- this.norms = norms;
- }
-
- public override float FloatVal(int doc)
- {
- return similarity.decodeNormValue(norms.get(doc));
- }
- }
-
- public override bool Equals(object o)
- {
- if (this.GetType() != o.GetType())
- {
- return false;
- }
- return this.field.Equals(((NormValueSource)o).field);
- }
-
- public override int GetHashCode()
- {
- return this.GetType().GetHashCode() + field.GetHashCode();
- }
- }
-
-
-
+ /// Function that returns <seealso cref="TFIDFSimilarity#decodeNormValue(long)"/>
+ /// for every document.
+ /// <para>
+ /// Note that the configured Similarity for the field must be
+ /// a subclass of <seealso cref="TFIDFSimilarity"/>
+ /// @lucene.internal
+ /// </para>
+ /// </summary>
+ public class NormValueSource : ValueSource
+ {
+ protected internal readonly string field;
+
+ public NormValueSource(string field)
+ {
+ this.field = field;
+ }
+
+ public virtual string Name
+ {
+ get { return "norm"; }
+ }
+
+ public override string Description
+ {
+ get { return Name + '(' + field + ')'; }
+ }
+
+ public override void CreateWeight(IDictionary context, IndexSearcher searcher)
+ {
+ context["searcher"] = searcher;
+ }
+
+ public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext)
+ {
+ var searcher = (IndexSearcher)context["searcher"];
+ TFIDFSimilarity similarity = IDFValueSource.AsTFIDF(searcher.Similarity, field);
+ if (similarity == null)
+ {
+ throw new System.NotSupportedException("requires a TFIDFSimilarity (such as DefaultSimilarity)");
+ }
+
+ NumericDocValues norms = readerContext.AtomicReader.GetNormValues(field);
+ if (norms == null)
+ {
+ return new ConstDoubleDocValues(0.0, this);
+ }
+
+ return new FloatDocValuesAnonymousInnerClassHelper(this, this, similarity, norms);
+ }
+
+ private class FloatDocValuesAnonymousInnerClassHelper : FloatDocValues
+ {
+ private readonly NormValueSource outerInstance;
+
+ private readonly TFIDFSimilarity similarity;
+ private readonly NumericDocValues norms;
+
+ public FloatDocValuesAnonymousInnerClassHelper(NormValueSource outerInstance, NormValueSource @this, TFIDFSimilarity similarity, NumericDocValues norms)
+ : base(@this)
+ {
+ this.outerInstance = outerInstance;
+ this.similarity = similarity;
+ this.norms = norms;
+ }
+
+ public override float FloatVal(int doc)
+ {
+ return similarity.DecodeNormValue(norms.Get(doc));
+ }
+ }
+
+ public override bool Equals(object o)
+ {
+ if (this.GetType() != o.GetType())
+ {
+ return false;
+ }
+ return this.field.Equals(((NormValueSource)o).field);
+ }
+
+ public override int GetHashCode()
+ {
+ return this.GetType().GetHashCode() + field.GetHashCode();
+ }
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Queries/Function/ValueSources/NumDocsValueSource.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/NumDocsValueSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/NumDocsValueSource.cs
index ea30074..6d59703 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/NumDocsValueSource.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/NumDocsValueSource.cs
@@ -16,44 +16,40 @@
*/
using System.Collections;
using Lucene.Net.Index;
-using org.apache.lucene.queries.function;
namespace Lucene.Net.Queries.Function.ValueSources
{
/// <summary>
- /// Returns the value of <seealso cref="IndexReader#numDocs()"/>
- /// for every document. This is the number of documents
- /// excluding deletions.
- /// </summary>
- public class NumDocsValueSource : ValueSource
- {
- public virtual string name()
- {
- return "numdocs";
- }
+ /// Returns the value of <seealso cref="IndexReader#numDocs()"/>
+ /// for every document. This is the number of documents
+ /// excluding deletions.
+ /// </summary>
+ public class NumDocsValueSource : ValueSource
+ {
+ public virtual string Name
+ {
+ get { return "numdocs"; }
+ }
- public override string description()
- {
- return name() + "()";
- }
+ public override string Description
+ {
+ get { return Name + "()"; }
+ }
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: @Override public org.apache.lucene.queries.function.FunctionValues GetValues(java.util.Map context, org.apache.lucene.index.AtomicReaderContext readerContext) throws java.io.IOException
- public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext)
- {
- // Searcher has no numdocs so we must use the reader instead
- return new ConstIntDocValues(ReaderUtil.getTopLevelContext(readerContext).reader().numDocs(), this);
- }
+ public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext)
+ {
+ // Searcher has no numdocs so we must use the reader instead
+ return new ConstIntDocValues(ReaderUtil.GetTopLevelContext(readerContext).Reader.NumDocs, this);
+ }
- public override bool Equals(object o)
- {
- return this.GetType() == o.GetType();
- }
-
- public override int GetHashCode()
- {
- return this.GetType().GetHashCode();
- }
- }
+ public override bool Equals(object o)
+ {
+ return this.GetType() == o.GetType();
+ }
+ public override int GetHashCode()
+ {
+ return this.GetType().GetHashCode();
+ }
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Queries/Function/ValueSources/OrdFieldSource.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/OrdFieldSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/OrdFieldSource.cs
index 8a46432..93eecab 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/OrdFieldSource.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/OrdFieldSource.cs
@@ -15,148 +15,140 @@
* limitations under the License.
*/
using System.Collections;
+using Lucene.Net.Index;
using Lucene.Net.Queries.Function.DocValues;
-using org.apache.lucene.queries.function;
+using Lucene.Net.Search;
+using Lucene.Net.Util.Mutable;
namespace Lucene.Net.Queries.Function.ValueSources
{
/// <summary>
- /// Obtains the ordinal of the field value from the default Lucene <seealso cref="org.apache.lucene.search.FieldCache"/> using getStringIndex().
- /// <br>
- /// The native lucene index order is used to assign an ordinal value for each field value.
- /// <br>Field values (terms) are lexicographically ordered by unicode value, and numbered starting at 1.
- /// <br>
- /// Example:<br>
- /// If there were only three field values: "apple","banana","pear"
- /// <br>then ord("apple")=1, ord("banana")=2, ord("pear")=3
- /// <para>
- /// WARNING: ord() depends on the position in an index and can thus change when other documents are inserted or deleted,
- /// or if a MultiSearcher is used.
- /// <br>WARNING: as of Solr 1.4, ord() and rord() can cause excess memory use since they must use a FieldCache entry
- /// at the top level reader, while sorting and function queries now use entries at the segment level. Hence sorting
- /// or using a different function query, in addition to ord()/rord() will double memory use.
- ///
- /// </para>
- /// </summary>
-
- public class OrdFieldSource : ValueSource
- {
- protected internal readonly string field;
-
- public OrdFieldSource(string field)
- {
- this.field = field;
- }
-
- public override string description()
- {
- return "ord(" + field + ')';
- }
-
-
- // TODO: this is trappy? perhaps this query instead should make you pass a slow reader yourself?
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: @Override public org.apache.lucene.queries.function.FunctionValues GetValues(java.util.Map context, org.apache.lucene.index.AtomicReaderContext readerContext) throws java.io.IOException
- public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext)
- {
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final int off = readerContext.docBase;
- int off = readerContext.docBase;
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final org.apache.lucene.index.IndexReader topReader = org.apache.lucene.index.ReaderUtil.getTopLevelContext(readerContext).reader();
- IndexReader topReader = ReaderUtil.getTopLevelContext(readerContext).reader();
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final org.apache.lucene.index.AtomicReader r = org.apache.lucene.index.SlowCompositeReaderWrapper.wrap(topReader);
- AtomicReader r = SlowCompositeReaderWrapper.wrap(topReader);
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final org.apache.lucene.index.SortedDocValues sindex = org.apache.lucene.search.FieldCache.DEFAULT.getTermsIndex(r, field);
- SortedDocValues sindex = FieldCache.DEFAULT.getTermsIndex(r, field);
- return new IntDocValuesAnonymousInnerClassHelper(this, this, off, sindex);
- }
-
- private class IntDocValuesAnonymousInnerClassHelper : IntDocValues
- {
- private readonly OrdFieldSource outerInstance;
-
- private int off;
- private SortedDocValues sindex;
-
- public IntDocValuesAnonymousInnerClassHelper(OrdFieldSource outerInstance, OrdFieldSource this, int off, SortedDocValues sindex) : base(this)
- {
- this.outerInstance = outerInstance;
- this.off = off;
- this.sindex = sindex;
- }
-
- protected internal virtual string toTerm(string readableValue)
- {
- return readableValue;
- }
- public override int intVal(int doc)
- {
- return sindex.getOrd(doc + off);
- }
- public override int ordVal(int doc)
- {
- return sindex.getOrd(doc + off);
- }
- public override int numOrd()
- {
- return sindex.ValueCount;
- }
-
- public override bool exists(int doc)
- {
- return sindex.getOrd(doc + off) != 0;
- }
-
- public override ValueFiller ValueFiller
- {
- get
- {
- return new ValueFillerAnonymousInnerClassHelper(this);
- }
- }
-
- private class ValueFillerAnonymousInnerClassHelper : ValueFiller
- {
- private readonly IntDocValuesAnonymousInnerClassHelper outerInstance;
-
- public ValueFillerAnonymousInnerClassHelper(IntDocValuesAnonymousInnerClassHelper outerInstance)
- {
- this.outerInstance = outerInstance;
- mval = new MutableValueInt();
- }
-
- private readonly MutableValueInt mval;
-
- public override MutableValue Value
- {
- get
- {
- return mval;
- }
- }
-
- public override void fillValue(int doc)
- {
- mval.value = outerInstance.sindex.getOrd(doc);
- mval.exists = mval.value != 0;
- }
- }
- }
-
- public override bool Equals(object o)
- {
- return o != null && o.GetType() == typeof(OrdFieldSource) && this.field.Equals(((OrdFieldSource)o).field);
- }
-
- private static readonly int hcode = typeof(OrdFieldSource).GetHashCode();
- public override int GetHashCode()
- {
- return hcode + field.GetHashCode();
- }
-
- }
-
+ /// Obtains the ordinal of the field value from the default Lucene <seealso cref="FieldCache"/> using getStringIndex().
+ /// <br>
+ /// The native lucene index order is used to assign an ordinal value for each field value.
+ /// <br>Field values (terms) are lexicographically ordered by unicode value, and numbered starting at 1.
+ /// <br>
+ /// Example:<br>
+ /// If there were only three field values: "apple","banana","pear"
+ /// <br>then ord("apple")=1, ord("banana")=2, ord("pear")=3
+ /// <para>
+ /// WARNING: ord() depends on the position in an index and can thus change when other documents are inserted or deleted,
+ /// or if a MultiSearcher is used.
+ /// <br>WARNING: as of Solr 1.4, ord() and rord() can cause excess memory use since they must use a FieldCache entry
+ /// at the top level reader, while sorting and function queries now use entries at the segment level. Hence sorting
+ /// or using a different function query, in addition to ord()/rord() will double memory use.
+ ///
+ /// </para>
+ /// </summary>
+
+ public class OrdFieldSource : ValueSource
+ {
+ protected readonly string field;
+
+ public OrdFieldSource(string field)
+ {
+ this.field = field;
+ }
+
+ public override string Description
+ {
+ get { return "ord(" + field + ')'; }
+ }
+
+
+ // TODO: this is trappy? perhaps this query instead should make you pass a slow reader yourself?
+ public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext)
+ {
+ int off = readerContext.DocBase;
+ IndexReader topReader = ReaderUtil.GetTopLevelContext(readerContext).Reader;
+ AtomicReader r = SlowCompositeReaderWrapper.Wrap(topReader);
+ SortedDocValues sindex = FieldCache.DEFAULT.GetTermsIndex(r, field);
+ return new IntDocValuesAnonymousInnerClassHelper(this, this, off, sindex);
+ }
+
+ private class IntDocValuesAnonymousInnerClassHelper : IntDocValues
+ {
+ private readonly OrdFieldSource outerInstance;
+
+ private readonly int off;
+ private readonly SortedDocValues sindex;
+
+ public IntDocValuesAnonymousInnerClassHelper(OrdFieldSource outerInstance, OrdFieldSource @this, int off, SortedDocValues sindex)
+ : base(@this)
+ {
+ this.outerInstance = outerInstance;
+ this.off = off;
+ this.sindex = sindex;
+ }
+
+ protected virtual string ToTerm(string readableValue)
+ {
+ return readableValue;
+ }
+ public override int IntVal(int doc)
+ {
+ return sindex.GetOrd(doc + off);
+ }
+ public override int OrdVal(int doc)
+ {
+ return sindex.GetOrd(doc + off);
+ }
+ public override int NumOrd()
+ {
+ return sindex.ValueCount;
+ }
+
+ public override bool Exists(int doc)
+ {
+ return sindex.GetOrd(doc + off) != 0;
+ }
+
+ public override AbstractValueFiller ValueFiller
+ {
+ get
+ {
+ return new ValueFillerAnonymousInnerClassHelper(this);
+ }
+ }
+
+ private class ValueFillerAnonymousInnerClassHelper : AbstractValueFiller
+ {
+ private readonly IntDocValuesAnonymousInnerClassHelper outerInstance;
+
+ public ValueFillerAnonymousInnerClassHelper(IntDocValuesAnonymousInnerClassHelper outerInstance)
+ {
+ this.outerInstance = outerInstance;
+ mval = new MutableValueInt();
+ }
+
+ private readonly MutableValueInt mval;
+
+ public override MutableValue Value
+ {
+ get
+ {
+ return mval;
+ }
+ }
+
+ public override void FillValue(int doc)
+ {
+ mval.Value = outerInstance.sindex.GetOrd(doc);
+ mval.Exists = mval.Value != 0;
+ }
+ }
+ }
+
+ public override bool Equals(object o)
+ {
+ return o != null && o.GetType() == typeof(OrdFieldSource) && this.field.Equals(((OrdFieldSource)o).field);
+ }
+
+ private static readonly int hcode = typeof(OrdFieldSource).GetHashCode();
+
+ public override int GetHashCode()
+ {
+ return hcode + field.GetHashCode();
+ }
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Queries/Function/ValueSources/PowFloatFunction.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/PowFloatFunction.cs b/src/Lucene.Net.Queries/Function/ValueSources/PowFloatFunction.cs
index da8c3bc..711af7a 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/PowFloatFunction.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/PowFloatFunction.cs
@@ -15,34 +15,29 @@
* limitations under the License.
*/
using System;
-using org.apache.lucene.queries.function;
namespace Lucene.Net.Queries.Function.ValueSources
{
-
-
- /// <summary>
- /// Function to raise the base "a" to the power "b"
- /// </summary>
- public class PowFloatFunction : DualFloatFunction
- {
- /// <param name="a"> the base. </param>
- /// <param name="b"> the exponent. </param>
- public PowFloatFunction(ValueSource a, ValueSource b) : base(a,b)
- {
- }
-
- protected internal override string name()
- {
- return "pow";
- }
-
- protected internal override float func(int doc, FunctionValues aVals, FunctionValues bVals)
- {
- return (float)Math.Pow(aVals.FloatVal(doc), bVals.FloatVal(doc));
- }
- }
-
-
-
+ /// <summary>
+ /// Function to raise the base "a" to the power "b"
+ /// </summary>
+ public class PowFloatFunction : DualFloatFunction
+ {
+ /// <param name="a"> the base. </param>
+ /// <param name="b"> the exponent. </param>
+ public PowFloatFunction(ValueSource a, ValueSource b)
+ : base(a, b)
+ {
+ }
+
+ protected override string Name
+ {
+ get { return "pow"; }
+ }
+
+ protected override float Func(int doc, FunctionValues aVals, FunctionValues bVals)
+ {
+ return (float)Math.Pow(aVals.FloatVal(doc), bVals.FloatVal(doc));
+ }
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Queries/Function/ValueSources/ProductFloatFunction.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/ProductFloatFunction.cs b/src/Lucene.Net.Queries/Function/ValueSources/ProductFloatFunction.cs
index 2a21615..94c7969 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/ProductFloatFunction.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/ProductFloatFunction.cs
@@ -15,35 +15,28 @@
* limitations under the License.
*/
-using org.apache.lucene.queries.function;
+using System.Linq;
namespace Lucene.Net.Queries.Function.ValueSources
{
+ /// <summary>
+ /// <code>ProductFloatFunction</code> returns the product of it's components.
+ /// </summary>
+ public class ProductFloatFunction : MultiFloatFunction
+ {
+ public ProductFloatFunction(ValueSource[] sources)
+ : base(sources)
+ {
+ }
+ protected override string Name
+ {
+ get { return "product"; }
+ }
- /// <summary>
- /// <code>ProductFloatFunction</code> returns the product of it's components.
- /// </summary>
- public class ProductFloatFunction : MultiFloatFunction
- {
- public ProductFloatFunction(ValueSource[] sources) : base(sources)
- {
- }
-
- protected internal override string name()
- {
- return "product";
- }
-
- protected internal override float func(int doc, FunctionValues[] valsArr)
- {
- float val = 1.0f;
- foreach (FunctionValues vals in valsArr)
- {
- val *= vals.FloatVal(doc);
- }
- return val;
- }
- }
-
+ protected override float Func(int doc, FunctionValues[] valsArr)
+ {
+ return valsArr.Aggregate(1.0f, (current, vals) => current * vals.FloatVal(doc));
+ }
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Queries/Function/ValueSources/QueryValueSource.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/QueryValueSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/QueryValueSource.cs
index 2949747..0f2ff47 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/QueryValueSource.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/QueryValueSource.cs
@@ -16,304 +16,304 @@
*/
using System;
using System.Collections;
+using System.IO;
+using Lucene.Net.Index;
using Lucene.Net.Queries.Function.DocValues;
-using org.apache.lucene.queries.function;
+using Lucene.Net.Search;
+using Lucene.Net.Util;
+using Lucene.Net.Util.Mutable;
namespace Lucene.Net.Queries.Function.ValueSources
{
/// <summary>
- /// <code>QueryValueSource</code> returns the relevance score of the query
- /// </summary>
- public class QueryValueSource : ValueSource
- {
- internal readonly Query q;
- internal readonly float defVal;
-
- public QueryValueSource(Query q, float defVal)
- {
- this.q = q;
- this.defVal = defVal;
- }
-
- public virtual Query Query
- {
- get
- {
- return q;
- }
- }
- public virtual float DefaultValue
- {
- get
- {
- return defVal;
- }
- }
-
- public override string description()
- {
- return "query(" + q + ",def=" + defVal + ")";
- }
-
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: @Override public org.apache.lucene.queries.function.FunctionValues GetValues(java.util.Map fcontext, org.apache.lucene.index.AtomicReaderContext readerContext) throws java.io.IOException
- public override FunctionValues GetValues(IDictionary fcontext, AtomicReaderContext readerContext)
- {
- return new QueryDocValues(this, readerContext, fcontext);
- }
-
- public override int GetHashCode()
- {
- return q.GetHashCode() * 29;
- }
-
- public override bool Equals(object o)
- {
- if (typeof(QueryValueSource) != o.GetType())
- {
- return false;
- }
- QueryValueSource other = (QueryValueSource)o;
- return this.q.Equals(other.q) && this.defVal == other.defVal;
- }
-
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: @Override public void CreateWeight(java.util.Map context, IndexSearcher searcher) throws java.io.IOException
- public override void CreateWeight(IDictionary context, IndexSearcher searcher)
- {
- Weight w = searcher.createNormalizedWeight(q);
- context[this] = w;
- }
- }
-
-
- internal class QueryDocValues : FloatDocValues
- {
- internal readonly AtomicReaderContext readerContext;
- internal readonly Bits acceptDocs;
- internal readonly Weight weight;
- internal readonly float defVal;
- internal readonly IDictionary fcontext;
- internal readonly Query q;
-
- internal Scorer scorer;
- internal int scorerDoc; // the document the scorer is on
- internal bool noMatches = false;
-
- // the last document requested... start off with high value
- // to trigger a scorer reset on first access.
- internal int lastDocRequested = int.MaxValue;
-
-
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: public QueryDocValues(QueryValueSource vs, org.apache.lucene.index.AtomicReaderContext readerContext, java.util.Map fcontext) throws java.io.IOException
- public QueryDocValues(QueryValueSource vs, AtomicReaderContext readerContext, IDictionary fcontext) : base(vs)
- {
-
- this.readerContext = readerContext;
- this.acceptDocs = readerContext.reader().LiveDocs;
- this.defVal = vs.defVal;
- this.q = vs.q;
- this.fcontext = fcontext;
-
- Weight w = fcontext == null ? null : (Weight)fcontext[vs];
- if (w == null)
- {
- IndexSearcher weightSearcher;
- if (fcontext == null)
- {
- weightSearcher = new IndexSearcher(ReaderUtil.getTopLevelContext(readerContext));
- }
- else
- {
- weightSearcher = (IndexSearcher)fcontext["searcher"];
- if (weightSearcher == null)
- {
- weightSearcher = new IndexSearcher(ReaderUtil.getTopLevelContext(readerContext));
- }
- }
- vs.CreateWeight(fcontext, weightSearcher);
- w = (Weight)fcontext[vs];
- }
- weight = w;
- }
-
- public override float FloatVal(int doc)
- {
- try
- {
- if (doc < lastDocRequested)
- {
- if (noMatches)
- {
- return defVal;
- }
- scorer = weight.scorer(readerContext, acceptDocs);
- if (scorer == null)
- {
- noMatches = true;
- return defVal;
- }
- scorerDoc = -1;
- }
- lastDocRequested = doc;
-
- if (scorerDoc < doc)
- {
- scorerDoc = scorer.advance(doc);
- }
-
- if (scorerDoc > doc)
- {
- // query doesn't match this document... either because we hit the
- // end, or because the next doc is after this doc.
- return defVal;
- }
-
- // a match!
- return scorer.score();
- }
- catch (IOException e)
- {
- throw new Exception("caught exception in QueryDocVals(" + q + ") doc=" + doc, e);
- }
- }
-
- public override bool exists(int doc)
- {
- try
- {
- if (doc < lastDocRequested)
- {
- if (noMatches)
- {
- return false;
- }
- scorer = weight.scorer(readerContext, acceptDocs);
- scorerDoc = -1;
- if (scorer == null)
- {
- noMatches = true;
- return false;
- }
- }
- lastDocRequested = doc;
-
- if (scorerDoc < doc)
- {
- scorerDoc = scorer.advance(doc);
- }
-
- if (scorerDoc > doc)
- {
- // query doesn't match this document... either because we hit the
- // end, or because the next doc is after this doc.
- return false;
- }
-
- // a match!
- return true;
- }
- catch (IOException e)
- {
- throw new Exception("caught exception in QueryDocVals(" + q + ") doc=" + doc, e);
- }
- }
-
- public override object objectVal(int doc)
- {
- try
- {
- return exists(doc) ? scorer.score() : null;
- }
- catch (IOException e)
- {
- throw new Exception("caught exception in QueryDocVals(" + q + ") doc=" + doc, e);
- }
- }
-
- public override ValueFiller ValueFiller
- {
- get
- {
- //
- // TODO: if we want to support more than one value-filler or a value-filler in conjunction with
- // the FunctionValues, then members like "scorer" should be per ValueFiller instance.
- // Or we can say that the user should just instantiate multiple FunctionValues.
- //
- return new ValueFillerAnonymousInnerClassHelper(this);
- }
- }
-
- private class ValueFillerAnonymousInnerClassHelper : ValueFiller
- {
- private readonly QueryDocValues outerInstance;
-
- public ValueFillerAnonymousInnerClassHelper(QueryDocValues outerInstance)
- {
- this.outerInstance = outerInstance;
- mval = new MutableValueFloat();
- }
-
- private readonly MutableValueFloat mval;
-
- public override MutableValue Value
- {
- get
- {
- return mval;
- }
- }
-
- public override void fillValue(int doc)
- {
- try
- {
- if (outerInstance.noMatches)
- {
- mval.value = outerInstance.defVal;
- mval.exists = false;
- return;
- }
- outerInstance.scorer = outerInstance.weight.scorer(outerInstance.readerContext, outerInstance.acceptDocs);
- outerInstance.scorerDoc = -1;
- if (outerInstance.scorer == null)
- {
- outerInstance.noMatches = true;
- mval.value = outerInstance.defVal;
- mval.exists = false;
- return;
- }
- outerInstance.lastDocRequested = doc;
-
- if (outerInstance.scorerDoc < doc)
- {
- outerInstance.scorerDoc = outerInstance.scorer.advance(doc);
- }
-
- if (outerInstance.scorerDoc > doc)
- {
- // query doesn't match this document... either because we hit the
- // end, or because the next doc is after this doc.
- mval.value = outerInstance.defVal;
- mval.exists = false;
- return;
- }
-
- // a match!
- mval.value = outerInstance.scorer.score();
- mval.exists = true;
- }
- catch (IOException e)
- {
- throw new Exception("caught exception in QueryDocVals(" + outerInstance.q + ") doc=" + doc, e);
- }
- }
- }
-
- public override string ToString(int doc)
- {
- return "query(" + q + ",def=" + defVal + ")=" + FloatVal(doc);
- }
- }
+ /// <code>QueryValueSource</code> returns the relevance score of the query
+ /// </summary>
+ public class QueryValueSource : ValueSource
+ {
+ internal readonly Query q;
+ internal readonly float defVal;
+
+ public QueryValueSource(Query q, float defVal)
+ {
+ this.q = q;
+ this.defVal = defVal;
+ }
+
+ public virtual Query Query
+ {
+ get
+ {
+ return q;
+ }
+ }
+ public virtual float DefaultValue
+ {
+ get
+ {
+ return defVal;
+ }
+ }
+
+ public override string Description
+ {
+ get { return "query(" + q + ",def=" + defVal + ")"; }
+ }
+
+ public override FunctionValues GetValues(IDictionary fcontext, AtomicReaderContext readerContext)
+ {
+ return new QueryDocValues(this, readerContext, fcontext);
+ }
+
+ public override int GetHashCode()
+ {
+ return q.GetHashCode() * 29;
+ }
+
+ public override bool Equals(object o)
+ {
+ if (typeof(QueryValueSource) != o.GetType())
+ {
+ return false;
+ }
+ var other = o as QueryValueSource;
+ if (other == null)
+ return false;
+ return this.q.Equals(other.q) && this.defVal == other.defVal;
+ }
+
+ public override void CreateWeight(IDictionary context, IndexSearcher searcher)
+ {
+ Weight w = searcher.CreateNormalizedWeight(q);
+ context[this] = w;
+ }
+ }
+
+
+ internal class QueryDocValues : FloatDocValues
+ {
+ internal readonly AtomicReaderContext readerContext;
+ internal readonly Bits acceptDocs;
+ internal readonly Weight weight;
+ internal readonly float defVal;
+ internal readonly IDictionary fcontext;
+ internal readonly Query q;
+
+ internal Scorer scorer;
+ internal int scorerDoc; // the document the scorer is on
+ internal bool noMatches = false;
+
+ // the last document requested... start off with high value
+ // to trigger a scorer reset on first access.
+ internal int lastDocRequested = int.MaxValue;
+
+ public QueryDocValues(QueryValueSource vs, AtomicReaderContext readerContext, IDictionary fcontext)
+ : base(vs)
+ {
+
+ this.readerContext = readerContext;
+ this.acceptDocs = readerContext.AtomicReader.LiveDocs;
+ this.defVal = vs.defVal;
+ this.q = vs.q;
+ this.fcontext = fcontext;
+
+ Weight w = fcontext == null ? null : (Weight)fcontext[vs];
+ if (w == null)
+ {
+ IndexSearcher weightSearcher;
+ if (fcontext == null)
+ {
+ weightSearcher = new IndexSearcher(ReaderUtil.GetTopLevelContext(readerContext));
+ }
+ else
+ {
+ weightSearcher = (IndexSearcher)fcontext["searcher"];
+ if (weightSearcher == null)
+ {
+ weightSearcher = new IndexSearcher(ReaderUtil.GetTopLevelContext(readerContext));
+ }
+ }
+ vs.CreateWeight(fcontext, weightSearcher);
+ w = (Weight)fcontext[vs];
+ }
+ weight = w;
+ }
+
+ public override float FloatVal(int doc)
+ {
+ try
+ {
+ if (doc < lastDocRequested)
+ {
+ if (noMatches)
+ {
+ return defVal;
+ }
+ scorer = weight.Scorer(readerContext, acceptDocs);
+ if (scorer == null)
+ {
+ noMatches = true;
+ return defVal;
+ }
+ scorerDoc = -1;
+ }
+ lastDocRequested = doc;
+
+ if (scorerDoc < doc)
+ {
+ scorerDoc = scorer.Advance(doc);
+ }
+
+ if (scorerDoc > doc)
+ {
+ // query doesn't match this document... either because we hit the
+ // end, or because the next doc is after this doc.
+ return defVal;
+ }
+
+ // a match!
+ return scorer.Score();
+ }
+ catch (IOException e)
+ {
+ throw new Exception("caught exception in QueryDocVals(" + q + ") doc=" + doc, e);
+ }
+ }
+
+ public override bool Exists(int doc)
+ {
+ try
+ {
+ if (doc < lastDocRequested)
+ {
+ if (noMatches)
+ {
+ return false;
+ }
+ scorer = weight.Scorer(readerContext, acceptDocs);
+ scorerDoc = -1;
+ if (scorer == null)
+ {
+ noMatches = true;
+ return false;
+ }
+ }
+ lastDocRequested = doc;
+
+ if (scorerDoc < doc)
+ {
+ scorerDoc = scorer.Advance(doc);
+ }
+
+ if (scorerDoc > doc)
+ {
+ // query doesn't match this document... either because we hit the
+ // end, or because the next doc is after this doc.
+ return false;
+ }
+
+ // a match!
+ return true;
+ }
+ catch (IOException e)
+ {
+ throw new Exception("caught exception in QueryDocVals(" + q + ") doc=" + doc, e);
+ }
+ }
+
+ public override object ObjectVal(int doc)
+ {
+ try
+ {
+ return Exists(doc) ? scorer.Score() : (float?)null;
+ }
+ catch (IOException e)
+ {
+ throw new Exception("caught exception in QueryDocVals(" + q + ") doc=" + doc, e);
+ }
+ }
+
+ public override AbstractValueFiller ValueFiller
+ {
+ get
+ {
+ //
+ // TODO: if we want to support more than one value-filler or a value-filler in conjunction with
+ // the FunctionValues, then members like "scorer" should be per ValueFiller instance.
+ // Or we can say that the user should just instantiate multiple FunctionValues.
+ //
+ return new ValueFillerAnonymousInnerClassHelper(this);
+ }
+ }
+
+ private class ValueFillerAnonymousInnerClassHelper : AbstractValueFiller
+ {
+ private readonly QueryDocValues outerInstance;
+
+ public ValueFillerAnonymousInnerClassHelper(QueryDocValues outerInstance)
+ {
+ this.outerInstance = outerInstance;
+ mval = new MutableValueFloat();
+ }
+
+ private readonly MutableValueFloat mval;
+
+ public override MutableValue Value
+ {
+ get
+ {
+ return mval;
+ }
+ }
+
+ public override void FillValue(int doc)
+ {
+ try
+ {
+ if (outerInstance.noMatches)
+ {
+ mval.Value = outerInstance.defVal;
+ mval.Exists = false;
+ return;
+ }
+ outerInstance.scorer = outerInstance.weight.Scorer(outerInstance.readerContext, outerInstance.acceptDocs);
+ outerInstance.scorerDoc = -1;
+ if (outerInstance.scorer == null)
+ {
+ outerInstance.noMatches = true;
+ mval.Value = outerInstance.defVal;
+ mval.Exists = false;
+ return;
+ }
+ outerInstance.lastDocRequested = doc;
+
+ if (outerInstance.scorerDoc < doc)
+ {
+ outerInstance.scorerDoc = outerInstance.scorer.Advance(doc);
+ }
+
+ if (outerInstance.scorerDoc > doc)
+ {
+ // query doesn't match this document... either because we hit the
+ // end, or because the next doc is after this doc.
+ mval.Value = outerInstance.defVal;
+ mval.Exists = false;
+ return;
+ }
+
+ // a match!
+ mval.Value = outerInstance.scorer.Score();
+ mval.Exists = true;
+ }
+ catch (IOException e)
+ {
+ throw new Exception("caught exception in QueryDocVals(" + outerInstance.q + ") doc=" + doc, e);
+ }
+ }
+ }
+
+ public override string ToString(int doc)
+ {
+ return "query(" + q + ",def=" + defVal + ")=" + FloatVal(doc);
+ }
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Queries/Function/ValueSources/RangeMapFloatFunction.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/RangeMapFloatFunction.cs b/src/Lucene.Net.Queries/Function/ValueSources/RangeMapFloatFunction.cs
index de729df..5c2fe5f 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/RangeMapFloatFunction.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/RangeMapFloatFunction.cs
@@ -15,119 +15,114 @@
* limitations under the License.
*/
using System.Collections;
+using Lucene.Net.Index;
using Lucene.Net.Queries.Function.DocValues;
-using org.apache.lucene.queries.function;
+using Lucene.Net.Search;
+using Lucene.Net.Support;
namespace Lucene.Net.Queries.Function.ValueSources
{
/// <summary>
- /// <code>RangeMapFloatFunction</code> implements a map function over
- /// another <seealso cref="ValueSource"/> whose values fall within min and max inclusive to target.
- /// <br>
- /// Normally Used as an argument to a <seealso cref="FunctionQuery"/>
- ///
- ///
- /// </summary>
- public class RangeMapFloatFunction : ValueSource
- {
- protected internal readonly ValueSource source;
- protected internal readonly float min;
- protected internal readonly float max;
- protected internal readonly ValueSource target;
- protected internal readonly ValueSource defaultVal;
+ /// <code>RangeMapFloatFunction</code> implements a map function over
+ /// another <seealso cref="ValueSource"/> whose values fall within min and max inclusive to target.
+ /// <br>
+ /// Normally Used as an argument to a <seealso cref="FunctionQuery"/>
+ ///
+ ///
+ /// </summary>
+ public class RangeMapFloatFunction : ValueSource
+ {
+ protected readonly ValueSource source;
+ protected readonly float min;
+ protected readonly float max;
+ protected readonly ValueSource target;
+ protected readonly ValueSource defaultVal;
- public RangeMapFloatFunction(ValueSource source, float min, float max, float target, float? def) : this(source, min, max, (ValueSource) new ConstValueSource(target), (ValueSource) (def == null ? null : new ConstValueSource(def.Value)))
- {
- }
+ public RangeMapFloatFunction(ValueSource source, float min, float max, float target, float? def)
+ : this(source, min, max, new ConstValueSource(target), def == null ? null : new ConstValueSource(def.Value))
+ {
+ }
- public RangeMapFloatFunction(ValueSource source, float min, float max, ValueSource target, ValueSource def)
- {
- this.source = source;
- this.min = min;
- this.max = max;
- this.target = target;
- this.defaultVal = def;
- }
+ public RangeMapFloatFunction(ValueSource source, float min, float max, ValueSource target, ValueSource def)
+ {
+ this.source = source;
+ this.min = min;
+ this.max = max;
+ this.target = target;
+ this.defaultVal = def;
+ }
- public override string description()
- {
- return "map(" + source.description() + "," + min + "," + max + "," + target.description() + ")";
- }
+ public override string Description
+ {
+ get { return "map(" + source.Description + "," + min + "," + max + "," + target.Description + ")"; }
+ }
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: @Override public org.apache.lucene.queries.function.FunctionValues GetValues(java.util.Map context, org.apache.lucene.index.AtomicReaderContext readerContext) throws java.io.IOException
- public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext)
- {
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final org.apache.lucene.queries.function.FunctionValues vals = source.GetValues(context, readerContext);
- FunctionValues vals = source.GetValues(context, readerContext);
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final org.apache.lucene.queries.function.FunctionValues targets = target.GetValues(context, readerContext);
- FunctionValues targets = target.GetValues(context, readerContext);
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final org.apache.lucene.queries.function.FunctionValues defaults = (this.defaultVal == null) ? null : defaultVal.GetValues(context, readerContext);
- FunctionValues defaults = (this.defaultVal == null) ? null : defaultVal.GetValues(context, readerContext);
- return new FloatDocValuesAnonymousInnerClassHelper(this, this, vals, targets, defaults);
- }
+ public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext)
+ {
+ FunctionValues vals = source.GetValues(context, readerContext);
+ FunctionValues targets = target.GetValues(context, readerContext);
+ FunctionValues defaults = (this.defaultVal == null) ? null : defaultVal.GetValues(context, readerContext);
+ return new FloatDocValuesAnonymousInnerClassHelper(this, this, vals, targets, defaults);
+ }
- private class FloatDocValuesAnonymousInnerClassHelper : FloatDocValues
- {
- private readonly RangeMapFloatFunction outerInstance;
+ private class FloatDocValuesAnonymousInnerClassHelper : FloatDocValues
+ {
+ private readonly RangeMapFloatFunction outerInstance;
- private FunctionValues vals;
- private FunctionValues targets;
- private FunctionValues defaults;
+ private readonly FunctionValues vals;
+ private readonly FunctionValues targets;
+ private readonly FunctionValues defaults;
- public FloatDocValuesAnonymousInnerClassHelper(RangeMapFloatFunction outerInstance, RangeMapFloatFunction this, FunctionValues vals, FunctionValues targets, FunctionValues defaults) : base(this)
- {
- this.outerInstance = outerInstance;
- this.vals = vals;
- this.targets = targets;
- this.defaults = defaults;
- }
+ public FloatDocValuesAnonymousInnerClassHelper(RangeMapFloatFunction outerInstance, RangeMapFloatFunction @this, FunctionValues vals, FunctionValues targets, FunctionValues defaults)
+ : base(@this)
+ {
+ this.outerInstance = outerInstance;
+ this.vals = vals;
+ this.targets = targets;
+ this.defaults = defaults;
+ }
- public override float FloatVal(int doc)
- {
- float val = vals.FloatVal(doc);
- return (val >= outerInstance.min && val <= outerInstance.max) ? targets.FloatVal(doc) : (outerInstance.defaultVal == null ? val : defaults.FloatVal(doc));
- }
- public override string ToString(int doc)
- {
- return "map(" + vals.ToString(doc) + ",min=" + outerInstance.min + ",max=" + outerInstance.max + ",target=" + targets.ToString(doc) + ")";
- }
- }
+ public override float FloatVal(int doc)
+ {
+ float val = vals.FloatVal(doc);
+ return (val >= outerInstance.min && val <= outerInstance.max) ? targets.FloatVal(doc) : (outerInstance.defaultVal == null ? val : defaults.FloatVal(doc));
+ }
+ public override string ToString(int doc)
+ {
+ return "map(" + vals.ToString(doc) + ",min=" + outerInstance.min + ",max=" + outerInstance.max + ",target=" + targets.ToString(doc) + ")";
+ }
+ }
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: @Override public void CreateWeight(java.util.Map context, org.apache.lucene.search.IndexSearcher searcher) throws java.io.IOException
- public override void CreateWeight(IDictionary context, IndexSearcher searcher)
- {
- source.CreateWeight(context, searcher);
- }
+ public override void CreateWeight(IDictionary context, IndexSearcher searcher)
+ {
+ source.CreateWeight(context, searcher);
+ }
- public override int GetHashCode()
- {
- int h = source.GetHashCode();
- h ^= (h << 10) | ((int)((uint)h >> 23));
- h += Number.FloatToIntBits(min);
- h ^= (h << 14) | ((int)((uint)h >> 19));
- h += Number.FloatToIntBits(max);
- h += target.GetHashCode();
- if (defaultVal != null)
- {
- h += defaultVal.GetHashCode();
- }
- return h;
- }
-
- public override bool Equals(object o)
- {
- if (typeof(RangeMapFloatFunction) != o.GetType())
- {
- return false;
- }
- RangeMapFloatFunction other = (RangeMapFloatFunction)o;
- return this.min == other.min && this.max == other.max && this.target.Equals(other.target) && this.source.Equals(other.source) && (this.defaultVal == other.defaultVal || (this.defaultVal != null && this.defaultVal.Equals(other.defaultVal)));
- }
- }
+ public override int GetHashCode()
+ {
+ int h = source.GetHashCode();
+ h ^= (h << 10) | ((int)((uint)h >> 23));
+ h += Number.FloatToIntBits(min);
+ h ^= (h << 14) | ((int)((uint)h >> 19));
+ h += Number.FloatToIntBits(max);
+ h += target.GetHashCode();
+ if (defaultVal != null)
+ {
+ h += defaultVal.GetHashCode();
+ }
+ return h;
+ }
+ public override bool Equals(object o)
+ {
+ if (typeof(RangeMapFloatFunction) != o.GetType())
+ {
+ return false;
+ }
+ var other = o as RangeMapFloatFunction;
+ if (other == null)
+ return false;
+ return this.min == other.min && this.max == other.max && this.target.Equals(other.target) && this.source.Equals(other.source) && (this.defaultVal == other.defaultVal || (this.defaultVal != null && this.defaultVal.Equals(other.defaultVal)));
+ }
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Queries/Function/ValueSources/ReciprocalFloatFunction.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/ReciprocalFloatFunction.cs b/src/Lucene.Net.Queries/Function/ValueSources/ReciprocalFloatFunction.cs
index 6a4a248..275436b 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/ReciprocalFloatFunction.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/ReciprocalFloatFunction.cs
@@ -16,110 +16,107 @@
*/
using System;
using System.Collections;
+using Lucene.Net.Index;
using Lucene.Net.Queries.Function.DocValues;
-using org.apache.lucene.queries.function;
+using Lucene.Net.Search;
+using Lucene.Net.Support;
namespace Lucene.Net.Queries.Function.ValueSources
{
/// <summary>
- /// <code>ReciprocalFloatFunction</code> implements a reciprocal function f(x) = a/(mx+b), based on
- /// the float value of a field or function as exported by <seealso cref="ValueSource"/>.
- /// <br>
- ///
- /// When a and b are equal, and x>=0, this function has a maximum value of 1 that drops as x increases.
- /// Increasing the value of a and b together results in a movement of the entire function to a flatter part of the curve.
- /// <para>These properties make this an idea function for boosting more recent documents.
- /// </para>
- /// <para>Example:<code> recip(ms(NOW,mydatefield),3.16e-11,1,1)</code>
- /// </para>
- /// <para>A multiplier of 3.16e-11 changes the units from milliseconds to years (since there are about 3.16e10 milliseconds
- /// per year). Thus, a very recent date will yield a value close to 1/(0+1) or 1,
- /// a date a year in the past will get a multiplier of about 1/(1+1) or 1/2,
- /// and date two years old will yield 1/(2+1) or 1/3.
- ///
- /// </para>
- /// </summary>
- /// <seealso cref= org.apache.lucene.queries.function.FunctionQuery
- ///
- /// </seealso>
- public class ReciprocalFloatFunction : ValueSource
- {
- protected internal readonly ValueSource source;
- protected internal readonly float m;
- protected internal readonly float a;
- protected internal readonly float b;
+ /// <code>ReciprocalFloatFunction</code> implements a reciprocal function f(x) = a/(mx+b), based on
+ /// the float value of a field or function as exported by <seealso cref="ValueSource"/>.
+ /// <br>
+ ///
+ /// When a and b are equal, and x>=0, this function has a maximum value of 1 that drops as x increases.
+ /// Increasing the value of a and b together results in a movement of the entire function to a flatter part of the curve.
+ /// <para>These properties make this an idea function for boosting more recent documents.
+ /// </para>
+ /// <para>Example:<code> recip(ms(NOW,mydatefield),3.16e-11,1,1)</code>
+ /// </para>
+ /// <para>A multiplier of 3.16e-11 changes the units from milliseconds to years (since there are about 3.16e10 milliseconds
+ /// per year). Thus, a very recent date will yield a value close to 1/(0+1) or 1,
+ /// a date a year in the past will get a multiplier of about 1/(1+1) or 1/2,
+ /// and date two years old will yield 1/(2+1) or 1/3.
+ ///
+ /// </para>
+ /// </summary>
+ /// <seealso cref= org.apache.lucene.queries.function.FunctionQuery
+ ///
+ /// </seealso>
+ public class ReciprocalFloatFunction : ValueSource
+ {
+ protected internal readonly ValueSource source;
+ protected internal readonly float m;
+ protected internal readonly float a;
+ protected internal readonly float b;
- /// <summary>
- /// f(source) = a/(m*float(source)+b)
- /// </summary>
- public ReciprocalFloatFunction(ValueSource source, float m, float a, float b)
- {
- this.source = source;
- this.m = m;
- this.a = a;
- this.b = b;
- }
+ /// <summary>
+ /// f(source) = a/(m*float(source)+b)
+ /// </summary>
+ public ReciprocalFloatFunction(ValueSource source, float m, float a, float b)
+ {
+ this.source = source;
+ this.m = m;
+ this.a = a;
+ this.b = b;
+ }
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: @Override public org.apache.lucene.queries.function.FunctionValues GetValues(java.util.Map context, org.apache.lucene.index.AtomicReaderContext readerContext) throws java.io.IOException
- public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext)
- {
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final org.apache.lucene.queries.function.FunctionValues vals = source.GetValues(context, readerContext);
- FunctionValues vals = source.GetValues(context, readerContext);
- return new FloatDocValuesAnonymousInnerClassHelper(this, this, vals);
- }
+ public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext)
+ {
+ var vals = source.GetValues(context, readerContext);
+ return new FloatDocValuesAnonymousInnerClassHelper(this, this, vals);
+ }
- private class FloatDocValuesAnonymousInnerClassHelper : FloatDocValues
- {
- private readonly ReciprocalFloatFunction outerInstance;
+ private class FloatDocValuesAnonymousInnerClassHelper : FloatDocValues
+ {
+ private readonly ReciprocalFloatFunction outerInstance;
+ private readonly FunctionValues vals;
- private FunctionValues vals;
+ public FloatDocValuesAnonymousInnerClassHelper(ReciprocalFloatFunction outerInstance, ReciprocalFloatFunction @this, FunctionValues vals)
+ : base(@this)
+ {
+ this.outerInstance = outerInstance;
+ this.vals = vals;
+ }
- public FloatDocValuesAnonymousInnerClassHelper(ReciprocalFloatFunction outerInstance, ReciprocalFloatFunction this, FunctionValues vals) : base(this)
- {
- this.outerInstance = outerInstance;
- this.vals = vals;
- }
+ public override float FloatVal(int doc)
+ {
+ return outerInstance.a / (outerInstance.m * vals.FloatVal(doc) + outerInstance.b);
+ }
+ public override string ToString(int doc)
+ {
+ return Convert.ToString(outerInstance.a) + "/(" + outerInstance.m + "*float(" + vals.ToString(doc) + ')' + '+' + outerInstance.b + ')';
+ }
+ }
- public override float FloatVal(int doc)
- {
- return outerInstance.a / (outerInstance.m * vals.FloatVal(doc) + outerInstance.b);
- }
- public override string ToString(int doc)
- {
- return Convert.ToString(outerInstance.a) + "/(" + outerInstance.m + "*float(" + vals.ToString(doc) + ')' + '+' + outerInstance.b + ')';
- }
- }
+ public override void CreateWeight(IDictionary context, IndexSearcher searcher)
+ {
+ source.CreateWeight(context, searcher);
+ }
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: @Override public void CreateWeight(java.util.Map context, org.apache.lucene.search.IndexSearcher searcher) throws java.io.IOException
- public override void CreateWeight(IDictionary context, IndexSearcher searcher)
- {
- source.CreateWeight(context, searcher);
- }
+ public override string Description
+ {
+ get { return Convert.ToString(a) + "/(" + m + "*float(" + source.Description + ")" + "+" + b + ')'; }
+ }
- public override string description()
- {
- return Convert.ToString(a) + "/(" + m + "*float(" + source.description() + ")" + "+" + b + ')';
- }
-
- public override int GetHashCode()
- {
- int h = Number.FloatToIntBits(a) + Number.FloatToIntBits(m);
- h ^= (h << 13) | ((int)((uint)h >> 20));
- return h + (Number.FloatToIntBits(b)) + source.GetHashCode();
- }
-
- public override bool Equals(object o)
- {
- if (typeof(ReciprocalFloatFunction) != o.GetType())
- {
- return false;
- }
- ReciprocalFloatFunction other = (ReciprocalFloatFunction)o;
- return this.m == other.m && this.a == other.a && this.b == other.b && this.source.Equals(other.source);
- }
- }
+ public override int GetHashCode()
+ {
+ int h = Number.FloatToIntBits(a) + Number.FloatToIntBits(m);
+ h ^= (h << 13) | ((int)((uint)h >> 20));
+ return h + (Number.FloatToIntBits(b)) + source.GetHashCode();
+ }
+ public override bool Equals(object o)
+ {
+ if (typeof(ReciprocalFloatFunction) != o.GetType())
+ {
+ return false;
+ }
+ var other = o as ReciprocalFloatFunction;
+ if (other == null)
+ return false;
+ return this.m == other.m && this.a == other.a && this.b == other.b && this.source.Equals(other.source);
+ }
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Queries/Function/ValueSources/ReverseOrdFieldSource.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/ReverseOrdFieldSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/ReverseOrdFieldSource.cs
index 7a67668..e111881 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/ReverseOrdFieldSource.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/ReverseOrdFieldSource.cs
@@ -15,110 +15,100 @@
* limitations under the License.
*/
using System.Collections;
+using Lucene.Net.Index;
using Lucene.Net.Queries.Function.DocValues;
-using org.apache.lucene.queries.function;
+using Lucene.Net.Search;
namespace Lucene.Net.Queries.Function.ValueSources
{
/// <summary>
- /// Obtains the ordinal of the field value from the default Lucene <seealso cref="org.apache.lucene.search.FieldCache"/> using getTermsIndex()
- /// and reverses the order.
- /// <br>
- /// The native lucene index order is used to assign an ordinal value for each field value.
- /// <br>Field values (terms) are lexicographically ordered by unicode value, and numbered starting at 1.
- /// <br>
- /// Example of reverse ordinal (rord):<br>
- /// If there were only three field values: "apple","banana","pear"
- /// <br>then rord("apple")=3, rord("banana")=2, ord("pear")=1
- /// <para>
- /// WARNING: ord() depends on the position in an index and can thus change when other documents are inserted or deleted,
- /// or if a MultiSearcher is used.
- /// <br>
- /// WARNING: as of Solr 1.4, ord() and rord() can cause excess memory use since they must use a FieldCache entry
- /// at the top level reader, while sorting and function queries now use entries at the segment level. Hence sorting
- /// or using a different function query, in addition to ord()/rord() will double memory use.
- ///
- ///
- /// </para>
- /// </summary>
+ /// Obtains the ordinal of the field value from the default Lucene <seealso cref="FieldCache"/> using getTermsIndex()
+ /// and reverses the order.
+ /// <br>
+ /// The native lucene index order is used to assign an ordinal value for each field value.
+ /// <br>Field values (terms) are lexicographically ordered by unicode value, and numbered starting at 1.
+ /// <br>
+ /// Example of reverse ordinal (rord):<br>
+ /// If there were only three field values: "apple","banana","pear"
+ /// <br>then rord("apple")=3, rord("banana")=2, ord("pear")=1
+ /// <para>
+ /// WARNING: ord() depends on the position in an index and can thus change when other documents are inserted or deleted,
+ /// or if a MultiSearcher is used.
+ /// <br>
+ /// WARNING: as of Solr 1.4, ord() and rord() can cause excess memory use since they must use a FieldCache entry
+ /// at the top level reader, while sorting and function queries now use entries at the segment level. Hence sorting
+ /// or using a different function query, in addition to ord()/rord() will double memory use.
+ ///
+ ///
+ /// </para>
+ /// </summary>
- public class ReverseOrdFieldSource : ValueSource
- {
- public readonly string field;
+ public class ReverseOrdFieldSource : ValueSource
+ {
+ public readonly string field;
- public ReverseOrdFieldSource(string field)
- {
- this.field = field;
- }
+ public ReverseOrdFieldSource(string field)
+ {
+ this.field = field;
+ }
- public override string description()
- {
- return "rord(" + field + ')';
- }
+ public override string Description
+ {
+ get { return "rord(" + field + ')'; }
+ }
- // TODO: this is trappy? perhaps this query instead should make you pass a slow reader yourself?
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: @Override public org.apache.lucene.queries.function.FunctionValues GetValues(java.util.Map context, org.apache.lucene.index.AtomicReaderContext readerContext) throws java.io.IOException
- public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext)
- {
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final org.apache.lucene.index.IndexReader topReader = org.apache.lucene.index.ReaderUtil.getTopLevelContext(readerContext).reader();
- IndexReader topReader = ReaderUtil.getTopLevelContext(readerContext).reader();
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final org.apache.lucene.index.AtomicReader r = org.apache.lucene.index.SlowCompositeReaderWrapper.wrap(topReader);
- AtomicReader r = SlowCompositeReaderWrapper.wrap(topReader);
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final int off = readerContext.docBase;
- int off = readerContext.docBase;
+ // TODO: this is trappy? perhaps this query instead should make you pass a slow reader yourself?
+ public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext)
+ {
+ IndexReader topReader = ReaderUtil.GetTopLevelContext(readerContext).Reader;
+ AtomicReader r = SlowCompositeReaderWrapper.Wrap(topReader);
+ int off = readerContext.DocBase;
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final org.apache.lucene.index.SortedDocValues sindex = org.apache.lucene.search.FieldCache.DEFAULT.getTermsIndex(r, field);
- SortedDocValues sindex = FieldCache.DEFAULT.getTermsIndex(r, field);
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final int end = sindex.getValueCount();
- int end = sindex.ValueCount;
+ var sindex = FieldCache.DEFAULT.GetTermsIndex(r, field);
+ var end = sindex.ValueCount;
- return new IntDocValuesAnonymousInnerClassHelper(this, this, off, sindex, end);
- }
+ return new IntDocValuesAnonymousInnerClassHelper(this, this, off, sindex, end);
+ }
- private class IntDocValuesAnonymousInnerClassHelper : IntDocValues
- {
- private readonly ReverseOrdFieldSource outerInstance;
+ private class IntDocValuesAnonymousInnerClassHelper : IntDocValues
+ {
+ private readonly ReverseOrdFieldSource outerInstance;
- private int off;
- private SortedDocValues sindex;
- private int end;
+ private readonly int off;
+ private readonly SortedDocValues sindex;
+ private readonly int end;
- public IntDocValuesAnonymousInnerClassHelper(ReverseOrdFieldSource outerInstance, ReverseOrdFieldSource this, int off, SortedDocValues sindex, int end) : base(this)
- {
- this.outerInstance = outerInstance;
- this.off = off;
- this.sindex = sindex;
- this.end = end;
- }
+ public IntDocValuesAnonymousInnerClassHelper(ReverseOrdFieldSource outerInstance, ReverseOrdFieldSource @this, int off, SortedDocValues sindex, int end)
+ : base(@this)
+ {
+ this.outerInstance = outerInstance;
+ this.off = off;
+ this.sindex = sindex;
+ this.end = end;
+ }
- public override int intVal(int doc)
- {
- return (end - sindex.getOrd(doc + off) - 1);
- }
- }
+ public override int IntVal(int doc)
+ {
+ return (end - sindex.GetOrd(doc + off) - 1);
+ }
+ }
- public override bool Equals(object o)
- {
- if (o == null || (o.GetType() != typeof(ReverseOrdFieldSource)))
- {
- return false;
- }
- ReverseOrdFieldSource other = (ReverseOrdFieldSource)o;
- return this.field.Equals(other.field);
- }
-
- private static readonly int hcode = typeof(ReverseOrdFieldSource).GetHashCode();
- public override int GetHashCode()
- {
- return hcode + field.GetHashCode();
- }
-
- }
+ public override bool Equals(object o)
+ {
+ if (o == null || (o.GetType() != typeof(ReverseOrdFieldSource)))
+ {
+ return false;
+ }
+ var other = o as ReverseOrdFieldSource;
+ if (other == null)
+ return false;
+ return this.field.Equals(other.field);
+ }
+ private static readonly int hcode = typeof(ReverseOrdFieldSource).GetHashCode();
+ public override int GetHashCode()
+ {
+ return hcode + field.GetHashCode();
+ }
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Queries/Function/ValueSources/ScaleFloatFunction.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/ScaleFloatFunction.cs b/src/Lucene.Net.Queries/Function/ValueSources/ScaleFloatFunction.cs
index 95bd2d2..b3e69b9 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/ScaleFloatFunction.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/ScaleFloatFunction.cs
@@ -15,9 +15,9 @@
* limitations under the License.
*/
using System.Collections;
-using System.Collections.Generic;
using Lucene.Net.Index;
using Lucene.Net.Queries.Function.DocValues;
+using Lucene.Net.Search;
using Lucene.Net.Support;
namespace Lucene.Net.Queries.Function.ValueSources
@@ -50,7 +50,7 @@ namespace Lucene.Net.Queries.Function.ValueSources
public override string Description
{
- get { return "scale(" + source.Description() + "," + min + "," + max + ")"; }
+ get { return "scale(" + source.Description + "," + min + "," + max + ")"; }
}
private class ScaleInfo
@@ -59,26 +59,22 @@ namespace Lucene.Net.Queries.Function.ValueSources
internal float maxVal;
}
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: private ScaleInfo createScaleInfo(java.util.Map context, org.apache.lucene.index.AtomicReaderContext readerContext) throws java.io.IOException
private ScaleInfo CreateScaleInfo(IDictionary context, AtomicReaderContext readerContext)
{
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final java.util.List<org.apache.lucene.index.AtomicReaderContext> leaves = org.apache.lucene.index.ReaderUtil.getTopLevelContext(readerContext).leaves();
- IList<AtomicReaderContext> leaves = ReaderUtil.GetTopLevelContext(readerContext).leaves();
+ var leaves = ReaderUtil.GetTopLevelContext(readerContext).Leaves;
float minVal = float.PositiveInfinity;
float maxVal = float.NegativeInfinity;
foreach (AtomicReaderContext leaf in leaves)
{
- int maxDoc = leaf.reader().maxDoc();
+ int maxDoc = leaf.Reader.MaxDoc;
FunctionValues vals = source.GetValues(context, leaf);
for (int i = 0; i < maxDoc; i++)
{
float val = vals.FloatVal(i);
- if ((float.floatToRawIntBits(val) & (0xff << 23)) == 0xff << 23)
+ if ((Number.FloatToRawIntBits(val) & (0xff << 23)) == 0xff << 23)
{
// if the exponent in the float is all ones, then this is +Inf, -Inf or NaN
// which don't make sense to factor into the scale function
@@ -108,31 +104,20 @@ namespace Lucene.Net.Queries.Function.ValueSources
return scaleInfo;
}
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: @Override public org.apache.lucene.queries.function.FunctionValues GetValues(java.util.Map context, org.apache.lucene.index.AtomicReaderContext readerContext) throws java.io.IOException
public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext)
{
- ScaleInfo scaleInfo = (ScaleInfo)context[ScaleFloatFunction.this];
+ var scaleInfo = (ScaleInfo)context[ScaleFloatFunction.this];
if (scaleInfo == null)
{
- scaleInfo = createScaleInfo(context, readerContext);
+ scaleInfo = CreateScaleInfo(context, readerContext);
}
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final float scale = (scaleInfo.maxVal-scaleInfo.minVal==0) ? 0 : (max-min)/(scaleInfo.maxVal-scaleInfo.minVal);
float scale = (scaleInfo.maxVal - scaleInfo.minVal == 0) ? 0 : (max - min) / (scaleInfo.maxVal - scaleInfo.minVal);
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final float minSource = scaleInfo.minVal;
float minSource = scaleInfo.minVal;
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final float maxSource = scaleInfo.maxVal;
float maxSource = scaleInfo.maxVal;
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final org.apache.lucene.queries.function.FunctionValues vals = source.GetValues(context, readerContext);
- FunctionValues vals = source.GetValues(context, readerContext);
-
+ var vals = source.GetValues(context, readerContext);
return new FloatDocValuesAnonymousInnerClassHelper(this, this, scale, minSource, maxSource, vals);
}
@@ -140,12 +125,12 @@ namespace Lucene.Net.Queries.Function.ValueSources
{
private readonly ScaleFloatFunction outerInstance;
- private float scale;
- private float minSource;
- private float maxSource;
- private FunctionValues vals;
+ private readonly float scale;
+ private readonly float minSource;
+ private readonly float maxSource;
+ private readonly FunctionValues vals;
- public FloatDocValuesAnonymousInnerClassHelper(ScaleFloatFunction outerInstance, ScaleFloatFunction this, float scale, float minSource, float maxSource, FunctionValues vals) : base(this)
+ public FloatDocValuesAnonymousInnerClassHelper(ScaleFloatFunction outerInstance, ScaleFloatFunction @this, float scale, float minSource, float maxSource, FunctionValues vals) : base(@this)
{
this.outerInstance = outerInstance;
this.scale = scale;
@@ -164,8 +149,6 @@ namespace Lucene.Net.Queries.Function.ValueSources
}
}
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: @Override public void CreateWeight(java.util.Map context, org.apache.lucene.search.IndexSearcher searcher) throws java.io.IOException
public override void CreateWeight(IDictionary context, IndexSearcher searcher)
{
source.CreateWeight(context, searcher);
@@ -183,13 +166,10 @@ namespace Lucene.Net.Queries.Function.ValueSources
public override bool Equals(object o)
{
- if (typeof(ScaleFloatFunction) != o.GetType())
- {
- return false;
- }
- ScaleFloatFunction other = (ScaleFloatFunction)o;
+ var other = o as ScaleFloatFunction;
+ if (other == null)
+ return false;
return this.min == other.min && this.max == other.max && this.source.Equals(other.source);
}
}
-
-}s
\ No newline at end of file
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Queries/Function/ValueSources/ShortFieldSource.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/ShortFieldSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/ShortFieldSource.cs
index 9ed5d2a..2c1c581 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/ShortFieldSource.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/ShortFieldSource.cs
@@ -1,132 +1,125 @@
using System;
using System.Collections;
-using org.apache.lucene.queries.function;
+using Lucene.Net.Index;
+using Lucene.Net.Search;
namespace Lucene.Net.Queries.Function.ValueSources
{
- /*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
+ /*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
/// <summary>
- /// Obtains short field values from the <seealso cref="org.apache.lucene.search.FieldCache"/>
- /// using <code>getShorts()</code>
- /// and makes those values available as other numeric types, casting as needed.
- ///
- /// </summary>
- [Obsolete]
- public class ShortFieldSource : FieldCacheSource
- {
-
- internal readonly FieldCache.ShortParser parser;
-
- public ShortFieldSource(string field) : this(field, null)
- {
- }
-
- public ShortFieldSource(string field, FieldCache.ShortParser parser) : base(field)
- {
- this.parser = parser;
- }
-
- public override string description()
- {
- return "short(" + field + ')';
- }
-
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: @Override public org.apache.lucene.queries.function.FunctionValues GetValues(java.util.Map context, org.apache.lucene.index.AtomicReaderContext readerContext) throws java.io.IOException
- public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext)
- {
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final org.apache.lucene.search.FieldCache.Shorts arr = cache.getShorts(readerContext.reader(), field, parser, false);
- FieldCache.Shorts arr = cache.getShorts(readerContext.reader(), field, parser, false);
-
- return new FunctionValuesAnonymousInnerClassHelper(this, arr);
- }
-
- private class FunctionValuesAnonymousInnerClassHelper : FunctionValues
- {
- private readonly ShortFieldSource outerInstance;
-
- private FieldCache.Shorts arr;
-
- public FunctionValuesAnonymousInnerClassHelper(ShortFieldSource outerInstance, FieldCache.Shorts arr)
- {
- this.outerInstance = outerInstance;
- this.arr = arr;
- }
-
- public override sbyte ByteVal(int doc)
- {
- return (sbyte) arr.get(doc);
- }
-
- public override short ShortVal(int doc)
- {
- return arr.get(doc);
- }
-
- public override float FloatVal(int doc)
- {
- return (float) arr.get(doc);
- }
-
- public override int intVal(int doc)
- {
- return (int) arr.get(doc);
- }
-
- public override long LongVal(int doc)
- {
- return (long) arr.get(doc);
- }
-
- public override double DoubleVal(int doc)
- {
- return (double) arr.get(doc);
- }
-
- public override string StrVal(int doc)
- {
- return Convert.ToString(arr.get(doc));
- }
-
- public override string ToString(int doc)
- {
- return outerInstance.description() + '=' + ShortVal(doc);
- }
-
- }
-
- public override bool Equals(object o)
- {
- if (o.GetType() != typeof(ShortFieldSource))
- {
- return false;
- }
- ShortFieldSource other = (ShortFieldSource) o;
- return base.Equals(other) && (this.parser == null ? other.parser == null : this.parser.GetType() == other.parser.GetType());
- }
-
- public override int GetHashCode()
- {
- int h = parser == null ? typeof(short?).GetHashCode() : parser.GetType().GetHashCode();
- h += base.GetHashCode();
- return h;
- }
- }
-
+ /// Obtains short field values from the <seealso cref="org.apache.lucene.search.FieldCache"/>
+ /// using <code>getShorts()</code>
+ /// and makes those values available as other numeric types, casting as needed.
+ ///
+ /// </summary>
+ [Obsolete]
+ public class ShortFieldSource : FieldCacheSource
+ {
+ readonly FieldCache.IShortParser parser;
+
+ public ShortFieldSource(string field)
+ : this(field, null)
+ {
+ }
+
+ public ShortFieldSource(string field, FieldCache.IShortParser parser)
+ : base(field)
+ {
+ this.parser = parser;
+ }
+
+ public override string Description
+ {
+ get { return "short(" + field + ')'; }
+ }
+
+ public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext)
+ {
+ var arr = cache.GetShorts(readerContext.AtomicReader, field, parser, false);
+ return new FunctionValuesAnonymousInnerClassHelper(this, arr);
+ }
+
+ private class FunctionValuesAnonymousInnerClassHelper : FunctionValues
+ {
+ private readonly ShortFieldSource outerInstance;
+ private readonly FieldCache.Shorts arr;
+
+ public FunctionValuesAnonymousInnerClassHelper(ShortFieldSource outerInstance, FieldCache.Shorts arr)
+ {
+ this.outerInstance = outerInstance;
+ this.arr = arr;
+ }
+
+ public override sbyte ByteVal(int doc)
+ {
+ return (sbyte)arr.Get(doc);
+ }
+
+ public override short ShortVal(int doc)
+ {
+ return arr.Get(doc);
+ }
+
+ public override float FloatVal(int doc)
+ {
+ return (float)arr.Get(doc);
+ }
+
+ public override int IntVal(int doc)
+ {
+ return (int)arr.Get(doc);
+ }
+
+ public override long LongVal(int doc)
+ {
+ return (long)arr.Get(doc);
+ }
+
+ public override double DoubleVal(int doc)
+ {
+ return arr.Get(doc);
+ }
+
+ public override string StrVal(int doc)
+ {
+ return Convert.ToString(arr.Get(doc));
+ }
+
+ public override string ToString(int doc)
+ {
+ return outerInstance.Description + '=' + ShortVal(doc);
+ }
+
+ }
+
+ public override bool Equals(object o)
+ {
+ var other = o as ShortFieldSource;
+ if (other == null)
+ return false;
+ return base.Equals(other) && (parser == null ? other.parser == null : parser.GetType() == other.parser.GetType());
+ }
+
+ public override int GetHashCode()
+ {
+ var h = parser == null ? typeof(short?).GetHashCode() : parser.GetType().GetHashCode();
+ h += base.GetHashCode();
+ return h;
+ }
+ }
}
\ No newline at end of file