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:45 UTC
[3/4] More work on Lucene.Net.Queries
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Queries/Function/ValueSources/IDFValueSource.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/IDFValueSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/IDFValueSource.cs
index 363cb60..1b487a8 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/IDFValueSource.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/IDFValueSource.cs
@@ -23,57 +23,54 @@ using Lucene.Net.Util;
namespace Lucene.Net.Queries.Function.ValueSources
{
/// <summary>
- /// Function that returns <seealso cref="TFIDFSimilarity #idf(long, long)"/>
- /// for every document.
- /// <para>
- /// Note that the configured Similarity for the field must be
- /// a subclass of <seealso cref="TFIDFSimilarity"/>
- /// @lucene.internal
- /// </para>
- /// </summary>
- public class IDFValueSource : DocFreqValueSource
- {
- public IDFValueSource(string field, string val, string indexedField, BytesRef indexedBytes) : base(field, val, indexedField, indexedBytes)
- {
- }
+ /// Function that returns <seealso cref="TFIDFSimilarity #idf(long, long)"/>
+ /// for every document.
+ /// <para>
+ /// Note that the configured Similarity for the field must be
+ /// a subclass of <seealso cref="TFIDFSimilarity"/>
+ /// @lucene.internal
+ /// </para>
+ /// </summary>
+ public class IDFValueSource : DocFreqValueSource
+ {
+ public IDFValueSource(string field, string val, string indexedField, BytesRef indexedBytes)
+ : base(field, val, indexedField, indexedBytes)
+ {
+ }
- public override string name()
- {
- return "idf";
- }
-
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: @Override public org.apache.lucene.queries.function.FunctionValues GetValues(java.util.Map context, AtomicReaderContext readerContext) throws java.io.IOException
- public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext)
- {
- IndexSearcher searcher = (IndexSearcher)context["searcher"];
- TFIDFSimilarity sim = asTFIDF(searcher.Similarity, field);
- if (sim == null)
- {
- throw new System.NotSupportedException("requires a TFIDFSimilarity (such as DefaultSimilarity)");
- }
- int docfreq = searcher.IndexReader.docFreq(new Term(indexedField, indexedBytes));
- float idf = sim.idf(docfreq, searcher.IndexReader.maxDoc());
- return new ConstDoubleDocValues(idf, this);
- }
-
- // tries extra hard to cast the sim to TFIDFSimilarity
- internal static TFIDFSimilarity AsTFIDF(Similarity sim, string field)
- {
- while (sim is PerFieldSimilarityWrapper)
- {
- sim = ((PerFieldSimilarityWrapper)sim).get(field);
- }
- if (sim is TFIDFSimilarity)
- {
- return (TFIDFSimilarity)sim;
- }
- else
- {
- return null;
- }
- }
- }
+ public override string Name
+ {
+ get { return "idf"; }
+ }
+ public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext)
+ {
+ var searcher = (IndexSearcher)context["searcher"];
+ TFIDFSimilarity sim = AsTFIDF(searcher.Similarity, field);
+ if (sim == null)
+ {
+ throw new System.NotSupportedException("requires a TFIDFSimilarity (such as DefaultSimilarity)");
+ }
+ int docfreq = searcher.IndexReader.DocFreq(new Term(indexedField, indexedBytes));
+ float idf = sim.Idf(docfreq, searcher.IndexReader.MaxDoc);
+ return new ConstDoubleDocValues(idf, this);
+ }
+ // tries extra hard to cast the sim to TFIDFSimilarity
+ internal static TFIDFSimilarity AsTFIDF(Similarity sim, string field)
+ {
+ while (sim is PerFieldSimilarityWrapper)
+ {
+ sim = ((PerFieldSimilarityWrapper)sim).Get(field);
+ }
+ if (sim is TFIDFSimilarity)
+ {
+ return (TFIDFSimilarity)sim;
+ }
+ else
+ {
+ return null;
+ }
+ }
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Queries/Function/ValueSources/IfFunction.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/IfFunction.cs b/src/Lucene.Net.Queries/Function/ValueSources/IfFunction.cs
index 692dae1..0eb8cad 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/IfFunction.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/IfFunction.cs
@@ -15,163 +15,152 @@
* limitations under the License.
*/
using System.Collections;
-using org.apache.lucene.queries.function;
+using Lucene.Net.Index;
+using Lucene.Net.Search;
+using Lucene.Net.Util;
namespace Lucene.Net.Queries.Function.ValueSources
{
/// <summary>
- /// Depending on the boolean value of the <code>ifSource</code> function,
- /// returns the value of the <code>trueSource</code> or <code>falseSource</code> function.
- /// </summary>
- public class IfFunction : BoolFunction
- {
- private readonly ValueSource ifSource;
- private readonly ValueSource trueSource;
- private readonly ValueSource falseSource;
-
-
- public IfFunction(ValueSource ifSource, ValueSource trueSource, ValueSource falseSource)
- {
- this.ifSource = ifSource;
- this.trueSource = trueSource;
- this.falseSource = falseSource;
- }
-
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: @Override public org.apache.lucene.queries.function.FunctionValues GetValues(java.util.Map context, org.apache.lucene.index.AtomicReaderContext readerContext) throws java.io.IOException
- public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext)
- {
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final org.apache.lucene.queries.function.FunctionValues ifVals = ifSource.GetValues(context, readerContext);
- FunctionValues ifVals = ifSource.GetValues(context, readerContext);
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final org.apache.lucene.queries.function.FunctionValues trueVals = trueSource.GetValues(context, readerContext);
- FunctionValues trueVals = trueSource.GetValues(context, readerContext);
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final org.apache.lucene.queries.function.FunctionValues falseVals = falseSource.GetValues(context, readerContext);
- FunctionValues falseVals = falseSource.GetValues(context, readerContext);
-
- return new FunctionValuesAnonymousInnerClassHelper(this, ifVals, trueVals, falseVals);
-
- }
-
- private class FunctionValuesAnonymousInnerClassHelper : FunctionValues
- {
- private readonly IfFunction outerInstance;
-
- private FunctionValues ifVals;
- private FunctionValues trueVals;
- private FunctionValues falseVals;
-
- public FunctionValuesAnonymousInnerClassHelper(IfFunction outerInstance, FunctionValues ifVals, FunctionValues trueVals, FunctionValues falseVals)
- {
- this.outerInstance = outerInstance;
- this.ifVals = ifVals;
- this.trueVals = trueVals;
- this.falseVals = falseVals;
- }
-
- public override sbyte ByteVal(int doc)
- {
- return ifVals.boolVal(doc) ? trueVals.ByteVal(doc) : falseVals.ByteVal(doc);
- }
-
- public override short ShortVal(int doc)
- {
- return ifVals.boolVal(doc) ? trueVals.ShortVal(doc) : falseVals.ShortVal(doc);
- }
-
- public override float FloatVal(int doc)
- {
- return ifVals.boolVal(doc) ? trueVals.FloatVal(doc) : falseVals.FloatVal(doc);
- }
-
- public override int intVal(int doc)
- {
- return ifVals.boolVal(doc) ? trueVals.intVal(doc) : falseVals.intVal(doc);
- }
-
- public override long LongVal(int doc)
- {
- return ifVals.boolVal(doc) ? trueVals.LongVal(doc) : falseVals.LongVal(doc);
- }
-
- public override double DoubleVal(int doc)
- {
- return ifVals.boolVal(doc) ? trueVals.DoubleVal(doc) : falseVals.DoubleVal(doc);
- }
-
- public override string StrVal(int doc)
- {
- return ifVals.boolVal(doc) ? trueVals.StrVal(doc) : falseVals.StrVal(doc);
- }
-
- public override bool boolVal(int doc)
- {
- return ifVals.boolVal(doc) ? trueVals.boolVal(doc) : falseVals.boolVal(doc);
- }
-
- public override bool bytesVal(int doc, BytesRef target)
- {
- return ifVals.boolVal(doc) ? trueVals.bytesVal(doc, target) : falseVals.bytesVal(doc, target);
- }
-
- public override object objectVal(int doc)
- {
- return ifVals.boolVal(doc) ? trueVals.objectVal(doc) : falseVals.objectVal(doc);
- }
-
- public override bool exists(int doc)
- {
- return true; // TODO: flow through to any sub-sources?
- }
-
- public override ValueFiller ValueFiller
- {
- get
- {
- // TODO: we need types of trueSource / falseSource to handle this
- // for now, use float.
- return base.ValueFiller;
- }
- }
-
- public override string ToString(int doc)
- {
- return "if(" + ifVals.ToString(doc) + ',' + trueVals.ToString(doc) + ',' + falseVals.ToString(doc) + ')';
- }
- }
-
- public override string description()
- {
- return "if(" + ifSource.description() + ',' + trueSource.description() + ',' + falseSource + ')';
- }
-
- public override int GetHashCode()
- {
- int h = ifSource.GetHashCode();
- h = h * 31 + trueSource.GetHashCode();
- h = h * 31 + falseSource.GetHashCode();
- return h;
- }
-
- public override bool Equals(object o)
- {
- if (!(o is IfFunction))
- {
- return false;
- }
- IfFunction other = (IfFunction)o;
- return ifSource.Equals(other.ifSource) && trueSource.Equals(other.trueSource) && falseSource.Equals(other.falseSource);
- }
-
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: @Override public void CreateWeight(java.util.Map context, org.apache.lucene.search.IndexSearcher searcher) throws java.io.IOException
- public override void CreateWeight(IDictionary context, IndexSearcher searcher)
- {
- ifSource.CreateWeight(context, searcher);
- trueSource.CreateWeight(context, searcher);
- falseSource.CreateWeight(context, searcher);
- }
- }
+ /// Depending on the boolean value of the <code>ifSource</code> function,
+ /// returns the value of the <code>trueSource</code> or <code>falseSource</code> function.
+ /// </summary>
+ public class IfFunction : BoolFunction
+ {
+ private readonly ValueSource ifSource;
+ private readonly ValueSource trueSource;
+ private readonly ValueSource falseSource;
+
+
+ public IfFunction(ValueSource ifSource, ValueSource trueSource, ValueSource falseSource)
+ {
+ this.ifSource = ifSource;
+ this.trueSource = trueSource;
+ this.falseSource = falseSource;
+ }
+
+ public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext)
+ {
+ FunctionValues ifVals = ifSource.GetValues(context, readerContext);
+ FunctionValues trueVals = trueSource.GetValues(context, readerContext);
+ FunctionValues falseVals = falseSource.GetValues(context, readerContext);
+
+ return new FunctionValuesAnonymousInnerClassHelper(this, ifVals, trueVals, falseVals);
+ }
+
+ private class FunctionValuesAnonymousInnerClassHelper : FunctionValues
+ {
+ private readonly IfFunction outerInstance;
+
+ private readonly FunctionValues ifVals;
+ private readonly FunctionValues trueVals;
+ private readonly FunctionValues falseVals;
+
+ public FunctionValuesAnonymousInnerClassHelper(IfFunction outerInstance, FunctionValues ifVals, FunctionValues trueVals, FunctionValues falseVals)
+ {
+ this.outerInstance = outerInstance;
+ this.ifVals = ifVals;
+ this.trueVals = trueVals;
+ this.falseVals = falseVals;
+ }
+
+ public override sbyte ByteVal(int doc)
+ {
+ return ifVals.BoolVal(doc) ? trueVals.ByteVal(doc) : falseVals.ByteVal(doc);
+ }
+
+ public override short ShortVal(int doc)
+ {
+ return ifVals.BoolVal(doc) ? trueVals.ShortVal(doc) : falseVals.ShortVal(doc);
+ }
+
+ public override float FloatVal(int doc)
+ {
+ return ifVals.BoolVal(doc) ? trueVals.FloatVal(doc) : falseVals.FloatVal(doc);
+ }
+
+ public override int IntVal(int doc)
+ {
+ return ifVals.BoolVal(doc) ? trueVals.IntVal(doc) : falseVals.IntVal(doc);
+ }
+
+ public override long LongVal(int doc)
+ {
+ return ifVals.BoolVal(doc) ? trueVals.LongVal(doc) : falseVals.LongVal(doc);
+ }
+
+ public override double DoubleVal(int doc)
+ {
+ return ifVals.BoolVal(doc) ? trueVals.DoubleVal(doc) : falseVals.DoubleVal(doc);
+ }
+
+ public override string StrVal(int doc)
+ {
+ return ifVals.BoolVal(doc) ? trueVals.StrVal(doc) : falseVals.StrVal(doc);
+ }
+
+ public override bool BoolVal(int doc)
+ {
+ return ifVals.BoolVal(doc) ? trueVals.BoolVal(doc) : falseVals.BoolVal(doc);
+ }
+
+ public override bool BytesVal(int doc, BytesRef target)
+ {
+ return ifVals.BoolVal(doc) ? trueVals.BytesVal(doc, target) : falseVals.BytesVal(doc, target);
+ }
+
+ public override object ObjectVal(int doc)
+ {
+ return ifVals.BoolVal(doc) ? trueVals.ObjectVal(doc) : falseVals.ObjectVal(doc);
+ }
+
+ public override bool Exists(int doc)
+ {
+ return true; // TODO: flow through to any sub-sources?
+ }
+
+ public override AbstractValueFiller ValueFiller
+ {
+ get
+ {
+ // TODO: we need types of trueSource / falseSource to handle this
+ // for now, use float.
+ return base.ValueFiller;
+ }
+ }
+
+ public override string ToString(int doc)
+ {
+ return "if(" + ifVals.ToString(doc) + ',' + trueVals.ToString(doc) + ',' + falseVals.ToString(doc) + ')';
+ }
+ }
+
+ public override string Description
+ {
+ get { return "if(" + ifSource.Description + ',' + trueSource.Description + ',' + falseSource + ')'; }
+ }
+
+ public override int GetHashCode()
+ {
+ int h = ifSource.GetHashCode();
+ h = h * 31 + trueSource.GetHashCode();
+ h = h * 31 + falseSource.GetHashCode();
+ return h;
+ }
+
+ public override bool Equals(object o)
+ {
+ var other = o as IfFunction;
+ if (other == null)
+ return false;
+ return ifSource.Equals(other.ifSource) && trueSource.Equals(other.trueSource) && falseSource.Equals(other.falseSource);
+ }
+
+ public override void CreateWeight(IDictionary context, IndexSearcher searcher)
+ {
+ ifSource.CreateWeight(context, searcher);
+ trueSource.CreateWeight(context, searcher);
+ falseSource.CreateWeight(context, searcher);
+ }
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Queries/Function/ValueSources/IntFieldSource.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/IntFieldSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/IntFieldSource.cs
index 63a8e31..2fc6636 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/IntFieldSource.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/IntFieldSource.cs
@@ -16,159 +16,153 @@
*/
using System;
using System.Collections;
+using Lucene.Net.Index;
using Lucene.Net.Queries.Function.DocValues;
-using org.apache.lucene.queries.function;
+using Lucene.Net.Search;
+using Lucene.Net.Util;
+using Lucene.Net.Util.Mutable;
namespace Lucene.Net.Queries.Function.ValueSources
{
/// <summary>
- /// Obtains int field values from <seealso cref="FieldCache#getInts"/> and makes those
- /// values available as other numeric types, casting as needed.
- /// </summary>
- public class IntFieldSource : FieldCacheSource
- {
- internal readonly FieldCache.IntParser parser;
-
- public IntFieldSource(string field) : this(field, null)
- {
- }
-
- public IntFieldSource(string field, FieldCache.IntParser parser) : base(field)
- {
- this.parser = parser;
- }
-
- public override string description()
- {
- return "int(" + field + ')';
- }
-
-
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: @Override public org.apache.lucene.queries.function.FunctionValues GetValues(java.util.Map context, org.apache.lucene.index.AtomicReaderContext readerContext) throws java.io.IOException
- public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext)
- {
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final org.apache.lucene.search.FieldCache.Ints arr = cache.getInts(readerContext.reader(), field, parser, true);
- FieldCache.Ints arr = cache.getInts(readerContext.reader(), field, parser, true);
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final org.apache.lucene.util.Bits valid = cache.getDocsWithField(readerContext.reader(), field);
- Bits valid = cache.getDocsWithField(readerContext.reader(), field);
-
- return new IntDocValuesAnonymousInnerClassHelper(this, this, arr, valid);
- }
-
- private class IntDocValuesAnonymousInnerClassHelper : IntDocValues
- {
- private readonly IntFieldSource outerInstance;
-
- private FieldCache.Ints arr;
- private Bits valid;
-
- public IntDocValuesAnonymousInnerClassHelper(IntFieldSource outerInstance, IntFieldSource this, FieldCache.Ints arr, Bits valid) : base(this)
- {
- this.outerInstance = outerInstance;
- this.arr = arr;
- this.valid = valid;
- val = new MutableValueInt();
- }
-
- internal readonly MutableValueInt val;
-
- public override float FloatVal(int doc)
- {
- return (float)arr.get(doc);
- }
-
- public override int intVal(int doc)
- {
- return arr.get(doc);
- }
-
- public override long LongVal(int doc)
- {
- return (long)arr.get(doc);
- }
-
- public override double DoubleVal(int doc)
- {
- return (double)arr.get(doc);
- }
-
- public override string StrVal(int doc)
- {
- return Convert.ToString(arr.get(doc));
- }
-
- public override object objectVal(int doc)
- {
- return valid.get(doc) ? arr.get(doc) : null;
- }
-
- public override bool exists(int doc)
- {
- return arr.get(doc) != 0 || valid.get(doc);
- }
-
- public override string ToString(int doc)
- {
- return outerInstance.description() + '=' + intVal(doc);
- }
-
- public override ValueFiller ValueFiller
- {
- get
- {
- return new ValueFillerAnonymousInnerClassHelper(this);
- }
- }
-
- private class ValueFillerAnonymousInnerClassHelper : ValueFiller
- {
- private readonly IntDocValuesAnonymousInnerClassHelper outerInstance;
-
- public ValueFillerAnonymousInnerClassHelper(IntDocValuesAnonymousInnerClassHelper outerInstance)
- {
- this.outerInstance = outerInstance;
- mval = new MutableValueInt();
- }
-
- private readonly MutableValueInt mval;
-
- public override MutableValue Value
- {
- get
- {
- return mval;
- }
- }
-
- public override void fillValue(int doc)
- {
- mval.value = outerInstance.arr.get(doc);
- mval.exists = mval.value != 0 || outerInstance.valid.get(doc);
- }
- }
-
-
- }
-
- public override bool Equals(object o)
- {
- if (o.GetType() != typeof(IntFieldSource))
- {
- return false;
- }
- IntFieldSource other = (IntFieldSource)o;
- return base.Equals(other) && (this.parser == null ? other.parser == null : this.parser.GetType() == other.parser.GetType());
- }
-
- public override int GetHashCode()
- {
- int h = parser == null ? typeof(int?).GetHashCode() : parser.GetType().GetHashCode();
- h += base.GetHashCode();
- return h;
- }
- }
-
+ /// Obtains int field values from <seealso cref="FieldCache#getInts"/> and makes those
+ /// values available as other numeric types, casting as needed.
+ /// </summary>
+ public class IntFieldSource : FieldCacheSource
+ {
+ internal readonly FieldCache.IIntParser parser;
+
+ public IntFieldSource(string field)
+ : this(field, null)
+ {
+ }
+
+ public IntFieldSource(string field, FieldCache.IIntParser parser)
+ : base(field)
+ {
+ this.parser = parser;
+ }
+
+ public override string Description
+ {
+ get { return "int(" + field + ')'; }
+ }
+
+ public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext)
+ {
+ FieldCache.Ints arr = cache.GetInts(readerContext.AtomicReader, field, parser, true);
+ Bits valid = cache.GetDocsWithField(readerContext.AtomicReader, field);
+
+ return new IntDocValuesAnonymousInnerClassHelper(this, this, arr, valid);
+ }
+
+ private class IntDocValuesAnonymousInnerClassHelper : IntDocValues
+ {
+ private readonly IntFieldSource outerInstance;
+
+ private readonly FieldCache.Ints arr;
+ private readonly Bits valid;
+
+ public IntDocValuesAnonymousInnerClassHelper(IntFieldSource outerInstance, IntFieldSource @this, FieldCache.Ints arr, Bits valid)
+ : base(@this)
+ {
+ this.outerInstance = outerInstance;
+ this.arr = arr;
+ this.valid = valid;
+ val = new MutableValueInt();
+ }
+
+ private readonly MutableValueInt val;
+
+ public override float FloatVal(int doc)
+ {
+ return (float)arr.Get(doc);
+ }
+
+ public override int IntVal(int doc)
+ {
+ return arr.Get(doc);
+ }
+
+ public override long LongVal(int doc)
+ {
+ return (long)arr.Get(doc);
+ }
+
+ public override double DoubleVal(int doc)
+ {
+ return (double)arr.Get(doc);
+ }
+
+ public override string StrVal(int doc)
+ {
+ return Convert.ToString(arr.Get(doc));
+ }
+
+ public override object ObjectVal(int doc)
+ {
+ return valid.Get(doc) ? arr.Get(doc) : (int?)null;
+ }
+
+ public override bool Exists(int doc)
+ {
+ return arr.Get(doc) != 0 || valid.Get(doc);
+ }
+
+ public override string ToString(int doc)
+ {
+ return outerInstance.Description + '=' + IntVal(doc);
+ }
+
+ public override AbstractValueFiller ValueFiller
+ {
+ get
+ {
+ return new ValueFillerAnonymousInnerClassHelper(this);
+ }
+ }
+
+ private class ValueFillerAnonymousInnerClassHelper : AbstractValueFiller
+ {
+ private readonly IntDocValuesAnonymousInnerClassHelper outerInstance;
+
+ public ValueFillerAnonymousInnerClassHelper(IntDocValuesAnonymousInnerClassHelper outerInstance)
+ {
+ this.outerInstance = outerInstance;
+ mval = new MutableValueInt();
+ }
+
+ private readonly MutableValueInt mval;
+
+ public override MutableValue Value
+ {
+ get
+ {
+ return mval;
+ }
+ }
+
+ public override void FillValue(int doc)
+ {
+ mval.Value = outerInstance.arr.Get(doc);
+ mval.Exists = mval.Value != 0 || outerInstance.valid.Get(doc);
+ }
+ }
+ }
+
+ public override bool Equals(object o)
+ {
+ var other = o as IntFieldSource;
+ if (other == null)
+ return false;
+ return base.Equals(other) && (this.parser == null ? other.parser == null : this.parser.GetType() == other.parser.GetType());
+ }
+
+ public override int GetHashCode()
+ {
+ int h = parser == null ? typeof(int?).GetHashCode() : parser.GetType().GetHashCode();
+ h += base.GetHashCode();
+ return h;
+ }
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Queries/Function/ValueSources/JoinDocFreqValueSource.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/JoinDocFreqValueSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/JoinDocFreqValueSource.cs
index ba9572f..4b6db96 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/JoinDocFreqValueSource.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/JoinDocFreqValueSource.cs
@@ -16,107 +16,103 @@
*/
using System;
using System.Collections;
+using System.IO;
+using Lucene.Net.Index;
using Lucene.Net.Queries.Function.DocValues;
-using org.apache.lucene.queries.function;
+using Lucene.Net.Util;
+using Lucene.Net.Util.Packed;
namespace Lucene.Net.Queries.Function.ValueSources
{
/// <summary>
- /// Use a field value and find the Document Frequency within another field.
- ///
- /// @since solr 4.0
- /// </summary>
- public class JoinDocFreqValueSource : FieldCacheSource
- {
+ /// Use a field value and find the Document Frequency within another field.
+ ///
+ /// @since solr 4.0
+ /// </summary>
+ public class JoinDocFreqValueSource : FieldCacheSource
+ {
- public const string NAME = "joindf";
+ public const string NAME = "joindf";
- protected internal readonly string qfield;
+ protected internal readonly string qfield;
- public JoinDocFreqValueSource(string field, string qfield) : base(field)
- {
- this.qfield = qfield;
- }
+ public JoinDocFreqValueSource(string field, string qfield)
+ : base(field)
+ {
+ this.qfield = qfield;
+ }
- public override string description()
- {
- return NAME + "(" + field + ":(" + qfield + "))";
- }
+ public override string Description
+ {
+ get { return NAME + "(" + field + ":(" + qfield + "))"; }
+ }
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: @Override public org.apache.lucene.queries.function.FunctionValues GetValues(java.util.Map context, org.apache.lucene.index.AtomicReaderContext readerContext) throws java.io.IOException
- public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext)
- {
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final org.apache.lucene.index.BinaryDocValues terms = cache.getTerms(readerContext.reader(), field, false, org.apache.lucene.util.packed.PackedInts.FAST);
- BinaryDocValues terms = cache.getTerms(readerContext.reader(), field, false, PackedInts.FAST);
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final org.apache.lucene.index.IndexReader top = org.apache.lucene.index.ReaderUtil.getTopLevelContext(readerContext).reader();
- IndexReader top = ReaderUtil.getTopLevelContext(readerContext).reader();
- Terms t = MultiFields.getTerms(top, qfield);
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final org.apache.lucene.index.TermsEnum termsEnum = t == null ? org.apache.lucene.index.TermsEnum.EMPTY : t.iterator(null);
- TermsEnum termsEnum = t == null ? TermsEnum.EMPTY : t.iterator(null);
+ public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext)
+ {
+ BinaryDocValues terms = cache.GetTerms(readerContext.AtomicReader, field, false, PackedInts.FAST);
+ IndexReader top = ReaderUtil.GetTopLevelContext(readerContext).Reader;
+ Terms t = MultiFields.GetTerms(top, qfield);
+ TermsEnum termsEnum = t == null ? TermsEnum.EMPTY : t.Iterator(null);
- return new IntDocValuesAnonymousInnerClassHelper(this, this, terms, termsEnum);
- }
+ return new IntDocValuesAnonymousInnerClassHelper(this, this, terms, termsEnum);
+ }
- private class IntDocValuesAnonymousInnerClassHelper : IntDocValues
- {
- private readonly JoinDocFreqValueSource outerInstance;
+ private class IntDocValuesAnonymousInnerClassHelper : IntDocValues
+ {
+ private readonly JoinDocFreqValueSource outerInstance;
- private BinaryDocValues terms;
- private TermsEnum termsEnum;
+ private readonly BinaryDocValues terms;
+ private readonly TermsEnum termsEnum;
- public IntDocValuesAnonymousInnerClassHelper(JoinDocFreqValueSource outerInstance, JoinDocFreqValueSource this, BinaryDocValues terms, TermsEnum termsEnum) : base(this)
- {
- this.outerInstance = outerInstance;
- this.terms = terms;
- this.termsEnum = termsEnum;
- @ref = new BytesRef();
- }
+ public IntDocValuesAnonymousInnerClassHelper(JoinDocFreqValueSource outerInstance, JoinDocFreqValueSource @this, BinaryDocValues terms, TermsEnum termsEnum)
+ : base(@this)
+ {
+ this.outerInstance = outerInstance;
+ this.terms = terms;
+ this.termsEnum = termsEnum;
+ @ref = new BytesRef();
+ }
- internal readonly BytesRef @ref;
+ private readonly BytesRef @ref;
- public override int intVal(int doc)
- {
- try
- {
- terms.get(doc, @ref);
- if (termsEnum.seekExact(@ref))
- {
- return termsEnum.docFreq();
- }
- else
- {
- return 0;
- }
- }
- catch (IOException e)
- {
- throw new Exception("caught exception in function " + outerInstance.description() + " : doc=" + doc, e);
- }
- }
- }
+ public override int IntVal(int doc)
+ {
+ try
+ {
+ terms.Get(doc, @ref);
+ if (termsEnum.SeekExact(@ref))
+ {
+ return termsEnum.DocFreq();
+ }
+ else
+ {
+ return 0;
+ }
+ }
+ catch (IOException e)
+ {
+ throw new Exception("caught exception in function " + outerInstance.Description + " : doc=" + doc, e);
+ }
+ }
+ }
- public override bool Equals(object o)
- {
- if (o.GetType() != typeof(JoinDocFreqValueSource))
- {
- return false;
- }
- JoinDocFreqValueSource other = (JoinDocFreqValueSource)o;
- if (!qfield.Equals(other.qfield))
- {
- return false;
- }
- return base.Equals(other);
- }
-
- public override int GetHashCode()
- {
- return qfield.GetHashCode() + base.GetHashCode();
- }
- }
+ public override bool Equals(object o)
+ {
+ if (o.GetType() != typeof(JoinDocFreqValueSource))
+ {
+ return false;
+ }
+ var other = (JoinDocFreqValueSource)o;
+ if (!qfield.Equals(other.qfield))
+ {
+ return false;
+ }
+ return base.Equals(other);
+ }
+ public override int GetHashCode()
+ {
+ return qfield.GetHashCode() + base.GetHashCode();
+ }
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Queries/Function/ValueSources/LinearFloatFunction.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/LinearFloatFunction.cs b/src/Lucene.Net.Queries/Function/ValueSources/LinearFloatFunction.cs
index bf92522..6759de7 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/LinearFloatFunction.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/LinearFloatFunction.cs
@@ -15,94 +15,87 @@
* limitations under the License.
*/
using System.Collections;
+using Lucene.Net.Index;
using Lucene.Net.Queries.Function.DocValues;
-using org.apache.lucene.queries.function;
+using Lucene.Net.Search;
+using Lucene.Net.Support;
namespace Lucene.Net.Queries.Function.ValueSources
{
/// <summary>
- /// <code>LinearFloatFunction</code> implements a linear function over
- /// another <seealso cref="ValueSource"/>.
- /// <br>
- /// Normally Used as an argument to a <seealso cref="FunctionQuery"/>
- ///
- ///
- /// </summary>
- public class LinearFloatFunction : ValueSource
- {
- protected internal readonly ValueSource source;
- protected internal readonly float slope;
- protected internal readonly float intercept;
+ /// <code>LinearFloatFunction</code> implements a linear function over
+ /// another <seealso cref="ValueSource"/>.
+ /// <br>
+ /// Normally Used as an argument to a <seealso cref="FunctionQuery"/>
+ ///
+ ///
+ /// </summary>
+ public class LinearFloatFunction : ValueSource
+ {
+ protected internal readonly ValueSource source;
+ protected internal readonly float slope;
+ protected internal readonly float intercept;
- public LinearFloatFunction(ValueSource source, float slope, float intercept)
- {
- this.source = source;
- this.slope = slope;
- this.intercept = intercept;
- }
+ public LinearFloatFunction(ValueSource source, float slope, float intercept)
+ {
+ this.source = source;
+ this.slope = slope;
+ this.intercept = intercept;
+ }
- public override string description()
- {
- return slope + "*float(" + source.description() + ")+" + intercept;
- }
+ public override string Description
+ {
+ get { return slope + "*float(" + source.Description + ")+" + intercept; }
+ }
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: @Override public org.apache.lucene.queries.function.FunctionValues GetValues(java.util.Map context, org.apache.lucene.index.AtomicReaderContext readerContext) throws java.io.IOException
- public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext)
- {
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final org.apache.lucene.queries.function.FunctionValues vals = source.GetValues(context, readerContext);
- FunctionValues vals = source.GetValues(context, readerContext);
- return new FloatDocValuesAnonymousInnerClassHelper(this, this, vals);
- }
+ public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext)
+ {
+ FunctionValues vals = source.GetValues(context, readerContext);
+ return new FloatDocValuesAnonymousInnerClassHelper(this, this, vals);
+ }
- private class FloatDocValuesAnonymousInnerClassHelper : FloatDocValues
- {
- private readonly LinearFloatFunction outerInstance;
+ private class FloatDocValuesAnonymousInnerClassHelper : FloatDocValues
+ {
+ private readonly LinearFloatFunction outerInstance;
+ private readonly FunctionValues vals;
- private FunctionValues vals;
+ public FloatDocValuesAnonymousInnerClassHelper(LinearFloatFunction outerInstance, LinearFloatFunction @this, FunctionValues vals)
+ : base(@this)
+ {
+ this.outerInstance = outerInstance;
+ this.vals = vals;
+ }
- public FloatDocValuesAnonymousInnerClassHelper(LinearFloatFunction outerInstance, LinearFloatFunction this, FunctionValues vals) : base(this)
- {
- this.outerInstance = outerInstance;
- this.vals = vals;
- }
+ public override float FloatVal(int doc)
+ {
+ return vals.FloatVal(doc) * outerInstance.slope + outerInstance.intercept;
+ }
+ public override string ToString(int doc)
+ {
+ return outerInstance.slope + "*float(" + vals.ToString(doc) + ")+" + outerInstance.intercept;
+ }
+ }
- public override float FloatVal(int doc)
- {
- return vals.FloatVal(doc) * outerInstance.slope + outerInstance.intercept;
- }
- public override string ToString(int doc)
- {
- return outerInstance.slope + "*float(" + vals.ToString(doc) + ")+" + outerInstance.intercept;
- }
- }
+ public override void CreateWeight(IDictionary context, IndexSearcher searcher)
+ {
+ source.CreateWeight(context, searcher);
+ }
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: @Override public void CreateWeight(java.util.Map context, org.apache.lucene.search.IndexSearcher searcher) throws java.io.IOException
- public override void CreateWeight(IDictionary context, IndexSearcher searcher)
- {
- source.CreateWeight(context, searcher);
- }
-
- public override int GetHashCode()
- {
- int h = Number.FloatToIntBits(slope);
- h = ((int)((uint)h >> 2)) | (h << 30);
- h += Number.FloatToIntBits(intercept);
- h ^= (h << 14) | ((int)((uint)h >> 19));
- return h + source.GetHashCode();
- }
-
- public override bool Equals(object o)
- {
- if (typeof(LinearFloatFunction) != o.GetType())
- {
- return false;
- }
- LinearFloatFunction other = (LinearFloatFunction)o;
- return this.slope == other.slope && this.intercept == other.intercept && this.source.Equals(other.source);
- }
- }
+ public override int GetHashCode()
+ {
+ int h = Number.FloatToIntBits(slope);
+ h = ((int)((uint)h >> 2)) | (h << 30);
+ h += Number.FloatToIntBits(intercept);
+ h ^= (h << 14) | ((int)((uint)h >> 19));
+ return h + source.GetHashCode();
+ }
+ public override bool Equals(object o)
+ {
+ var other = o as LinearFloatFunction;
+ if (other == null)
+ return false;
+ return this.slope == other.slope && this.intercept == other.intercept && this.source.Equals(other.source);
+ }
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Queries/Function/ValueSources/LiteralValueSource.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/LiteralValueSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/LiteralValueSource.cs
index 0b7bcea..451c613 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/LiteralValueSource.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/LiteralValueSource.cs
@@ -1,112 +1,107 @@
using System.Collections;
+using Lucene.Net.Index;
using Lucene.Net.Queries.Function.DocValues;
-using org.apache.lucene.queries.function;
+using Lucene.Net.Util;
namespace Lucene.Net.Queries.Function.ValueSources
{
- /*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
+ /*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
/// <summary>
- /// Pass a the field value through as a String, no matter the type // Q: doesn't this mean it's a "string"?
- ///
- ///
- /// </summary>
- public class LiteralValueSource : ValueSource
- {
- protected internal readonly string @string;
- protected internal readonly BytesRef bytesRef;
-
- public LiteralValueSource(string @string)
- {
- this.@string = @string;
- this.bytesRef = new BytesRef(@string);
- }
-
- /// <summary>
- /// returns the literal value </summary>
- public virtual string Value
- {
- get
- {
- return @string;
- }
- }
-
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: @Override public org.apache.lucene.queries.function.FunctionValues GetValues(java.util.Map context, org.apache.lucene.index.AtomicReaderContext readerContext) throws java.io.IOException
- public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext)
- {
-
- return new StrDocValuesAnonymousInnerClassHelper(this, this);
- }
-
- private class StrDocValuesAnonymousInnerClassHelper : StrDocValues
- {
- private readonly LiteralValueSource outerInstance;
-
- public StrDocValuesAnonymousInnerClassHelper(LiteralValueSource outerInstance, LiteralValueSource this) : base(this)
- {
- this.outerInstance = outerInstance;
- }
-
- public override string StrVal(int doc)
- {
- return outerInstance.@string;
- }
-
- public override bool bytesVal(int doc, BytesRef target)
- {
- target.copyBytes(outerInstance.bytesRef);
- return true;
- }
-
- public override string ToString(int doc)
- {
- return outerInstance.@string;
- }
- }
-
- public override string description()
- {
- return "literal(" + @string + ")";
- }
-
- public override bool Equals(object o)
- {
- if (this == o)
- {
- return true;
- }
- if (!(o is LiteralValueSource))
- {
- return false;
- }
-
- LiteralValueSource that = (LiteralValueSource) o;
-
- return @string.Equals(that.@string);
-
- }
-
- public static readonly int hash = typeof(LiteralValueSource).GetHashCode();
- public override int GetHashCode()
- {
- return hash + @string.GetHashCode();
- }
- }
-
+ /// Pass a the field value through as a String, no matter the type // Q: doesn't this mean it's a "str"?
+ ///
+ ///
+ /// </summary>
+ public class LiteralValueSource : ValueSource
+ {
+ protected readonly string str;
+ protected readonly BytesRef bytesRef;
+
+ public LiteralValueSource(string str)
+ {
+ this.str = str;
+ this.bytesRef = new BytesRef(str);
+ }
+
+ /// <summary>
+ /// returns the literal value </summary>
+ public virtual string Value
+ {
+ get
+ {
+ return str;
+ }
+ }
+
+ public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext)
+ {
+
+ return new StrDocValuesAnonymousInnerClassHelper(this, this);
+ }
+
+ private class StrDocValuesAnonymousInnerClassHelper : StrDocValues
+ {
+ private readonly LiteralValueSource outerInstance;
+
+ public StrDocValuesAnonymousInnerClassHelper(LiteralValueSource outerInstance, LiteralValueSource @this)
+ : base(@this)
+ {
+ this.outerInstance = outerInstance;
+ }
+
+ public override string StrVal(int doc)
+ {
+ return outerInstance.str;
+ }
+
+ public override bool BytesVal(int doc, BytesRef target)
+ {
+ target.CopyBytes(outerInstance.bytesRef);
+ return true;
+ }
+
+ public override string ToString(int doc)
+ {
+ return outerInstance.str;
+ }
+ }
+
+ public override string Description
+ {
+ get { return "literal(" + str + ")"; }
+ }
+
+ public override bool Equals(object o)
+ {
+ if (this == o)
+ {
+ return true;
+ }
+ var that = o as LiteralValueSource;
+ if (that == null)
+ return false;
+ return str.Equals(that.str);
+
+ }
+
+ public static readonly int hash = typeof(LiteralValueSource).GetHashCode();
+ public override int GetHashCode()
+ {
+ return hash + str.GetHashCode();
+ }
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Queries/Function/ValueSources/LongFieldSource.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/LongFieldSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/LongFieldSource.cs
index 9216c48..9e79096 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/LongFieldSource.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/LongFieldSource.cs
@@ -16,160 +16,159 @@
*/
using System;
using System.Collections;
+using Lucene.Net.Index;
using Lucene.Net.Queries.Function.DocValues;
-using org.apache.lucene.queries.function;
+using Lucene.Net.Search;
+using Lucene.Net.Util;
+using Lucene.Net.Util.Mutable;
namespace Lucene.Net.Queries.Function.ValueSources
{
/// <summary>
- /// Obtains long field values from <seealso cref="FieldCache#getLongs"/> and makes those
- /// values available as other numeric types, casting as needed.
- /// </summary>
- public class LongFieldSource : FieldCacheSource
- {
-
- protected internal readonly FieldCache.LongParser parser;
-
- public LongFieldSource(string field) : this(field, null)
- {
- }
-
- public LongFieldSource(string field, FieldCache.LongParser parser) : base(field)
- {
- this.parser = parser;
- }
-
- public override string description()
- {
- return "long(" + field + ')';
- }
-
- public virtual long externalToLong(string extVal)
- {
- return Convert.ToInt64(extVal);
- }
-
- public virtual object longToObject(long val)
- {
- return val;
- }
-
- public virtual string longToString(long val)
- {
- return longToObject(val).ToString();
- }
-
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: @Override public org.apache.lucene.queries.function.FunctionValues GetValues(java.util.Map context, org.apache.lucene.index.AtomicReaderContext readerContext) throws java.io.IOException
- public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext)
- {
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final org.apache.lucene.search.FieldCache.Longs arr = cache.getLongs(readerContext.reader(), field, parser, true);
- FieldCache.Longs arr = cache.getLongs(readerContext.reader(), field, parser, true);
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final org.apache.lucene.util.Bits valid = cache.getDocsWithField(readerContext.reader(), field);
- Bits valid = cache.getDocsWithField(readerContext.reader(), field);
-
- return new LongDocValuesAnonymousInnerClassHelper(this, this, arr, valid);
- }
-
- private class LongDocValuesAnonymousInnerClassHelper : LongDocValues
- {
- private readonly LongFieldSource outerInstance;
-
- private FieldCache.Longs arr;
- private Bits valid;
-
- public LongDocValuesAnonymousInnerClassHelper(LongFieldSource outerInstance, LongFieldSource this, FieldCache.Longs arr, Bits valid) : base(this)
- {
- this.outerInstance = outerInstance;
- this.arr = arr;
- this.valid = valid;
- }
-
- public override long LongVal(int doc)
- {
- return arr.get(doc);
- }
-
- public override bool exists(int doc)
- {
- return arr.get(doc) != 0 || valid.get(doc);
- }
-
- public override object objectVal(int doc)
- {
- return valid.get(doc) ? outerInstance.longToObject(arr.get(doc)) : null;
- }
-
- public override string StrVal(int doc)
- {
- return valid.get(doc) ? outerInstance.longToString(arr.get(doc)) : null;
- }
-
- protected internal override long externalToLong(string extVal)
- {
- return outerInstance.externalToLong(extVal);
- }
-
- public override ValueFiller ValueFiller
- {
- get
- {
- return new ValueFillerAnonymousInnerClassHelper(this);
- }
- }
-
- private class ValueFillerAnonymousInnerClassHelper : ValueFiller
- {
- private readonly LongDocValuesAnonymousInnerClassHelper outerInstance;
-
- public ValueFillerAnonymousInnerClassHelper(LongDocValuesAnonymousInnerClassHelper outerInstance)
- {
- this.outerInstance = outerInstance;
- mval = outerInstance.outerInstance.newMutableValueLong();
- }
-
- private readonly MutableValueLong mval;
-
- public override MutableValue Value
- {
- get
- {
- return mval;
- }
- }
-
- public override void fillValue(int doc)
- {
- mval.value = outerInstance.arr.get(doc);
- mval.exists = mval.value != 0 || outerInstance.valid.get(doc);
- }
- }
-
- }
-
- protected internal virtual MutableValueLong newMutableValueLong()
- {
- return new MutableValueLong();
- }
-
- public override bool Equals(object o)
- {
- if (o.GetType() != this.GetType())
- {
- return false;
- }
- LongFieldSource other = (LongFieldSource) o;
- return base.Equals(other) && (this.parser == null ? other.parser == null : this.parser.GetType() == other.parser.GetType());
- }
-
- public override int GetHashCode()
- {
- int h = parser == null ? this.GetType().GetHashCode() : parser.GetType().GetHashCode();
- h += base.GetHashCode();
- return h;
- }
- }
-
+ /// Obtains long field values from <seealso cref="FieldCache#getLongs"/> and makes those
+ /// values available as other numeric types, casting as needed.
+ /// </summary>
+ public class LongFieldSource : FieldCacheSource
+ {
+
+ protected readonly FieldCache.ILongParser parser;
+
+ public LongFieldSource(string field)
+ : this(field, null)
+ {
+ }
+
+ public LongFieldSource(string field, FieldCache.ILongParser parser)
+ : base(field)
+ {
+ this.parser = parser;
+ }
+
+ public override string Description
+ {
+ get { return "long(" + field + ')'; }
+ }
+
+ public virtual long ExternalToLong(string extVal)
+ {
+ return Convert.ToInt64(extVal);
+ }
+
+ public virtual object LongToObject(long val)
+ {
+ return val;
+ }
+
+ public virtual string LongToString(long val)
+ {
+ return LongToObject(val).ToString();
+ }
+
+ public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext)
+ {
+ var arr = cache.GetLongs(readerContext.AtomicReader, field, parser, true);
+ var valid = cache.GetDocsWithField(readerContext.AtomicReader, field);
+ return new LongDocValuesAnonymousInnerClassHelper(this, this, arr, valid);
+ }
+
+ private class LongDocValuesAnonymousInnerClassHelper : LongDocValues
+ {
+ private readonly LongFieldSource outerInstance;
+
+ private readonly FieldCache.Longs arr;
+ private readonly Bits valid;
+
+ public LongDocValuesAnonymousInnerClassHelper(LongFieldSource outerInstance, LongFieldSource @this, FieldCache.Longs arr, Bits valid)
+ : base(@this)
+ {
+ this.outerInstance = outerInstance;
+ this.arr = arr;
+ this.valid = valid;
+ }
+
+ public override long LongVal(int doc)
+ {
+ return arr.Get(doc);
+ }
+
+ public override bool Exists(int doc)
+ {
+ return arr.Get(doc) != 0 || valid.Get(doc);
+ }
+
+ public override object ObjectVal(int doc)
+ {
+ return valid.Get(doc) ? outerInstance.LongToObject(arr.Get(doc)) : null;
+ }
+
+ public override string StrVal(int doc)
+ {
+ return valid.Get(doc) ? outerInstance.LongToString(arr.Get(doc)) : null;
+ }
+
+ protected override long ExternalToLong(string extVal)
+ {
+ return outerInstance.ExternalToLong(extVal);
+ }
+
+ public override AbstractValueFiller ValueFiller
+ {
+ get
+ {
+ return new ValueFillerAnonymousInnerClassHelper(this);
+ }
+ }
+
+ private class ValueFillerAnonymousInnerClassHelper : AbstractValueFiller
+ {
+ private readonly LongDocValuesAnonymousInnerClassHelper outerInstance;
+
+ public ValueFillerAnonymousInnerClassHelper(LongDocValuesAnonymousInnerClassHelper outerInstance)
+ {
+ this.outerInstance = outerInstance;
+ mval = outerInstance.outerInstance.NewMutableValueLong();
+ }
+
+ private readonly MutableValueLong mval;
+
+ public override MutableValue Value
+ {
+ get
+ {
+ return mval;
+ }
+ }
+
+ public override void FillValue(int doc)
+ {
+ mval.Value = outerInstance.arr.Get(doc);
+ mval.Exists = mval.Value != 0 || outerInstance.valid.Get(doc);
+ }
+ }
+ }
+
+ protected virtual MutableValueLong NewMutableValueLong()
+ {
+ return new MutableValueLong();
+ }
+
+ public override bool Equals(object o)
+ {
+ if (o.GetType() != this.GetType())
+ {
+ return false;
+ }
+ var other = o as LongFieldSource;
+ if (other == null)
+ return false;
+ return base.Equals(other) && (this.parser == null ? other.parser == null : this.parser.GetType() == other.parser.GetType());
+ }
+
+ public override int GetHashCode()
+ {
+ int h = parser == null ? this.GetType().GetHashCode() : parser.GetType().GetHashCode();
+ h += base.GetHashCode();
+ return h;
+ }
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Queries/Function/ValueSources/MaxDocValueSource.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/MaxDocValueSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/MaxDocValueSource.cs
index be0e939..a65dfcb 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/MaxDocValueSource.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/MaxDocValueSource.cs
@@ -15,54 +15,47 @@
* limitations under the License.
*/
using System.Collections;
-using org.apache.lucene.queries.function;
+using Lucene.Net.Index;
+using Lucene.Net.Search;
namespace Lucene.Net.Queries.Function.ValueSources
{
- // javadocs
-
-
/// <summary>
- /// Returns the value of <seealso cref="IndexReader#maxDoc()"/>
- /// for every document. This is the number of documents
- /// including deletions.
- /// </summary>
- public class MaxDocValueSource : ValueSource
- {
- public virtual string name()
- {
- return "maxdoc";
- }
-
- public override string description()
- {
- return name() + "()";
- }
-
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: @Override public void CreateWeight(java.util.Map context, org.apache.lucene.search.IndexSearcher searcher) throws java.io.IOException
- public override void CreateWeight(IDictionary context, IndexSearcher searcher)
- {
- context["searcher"] = searcher;
- }
-
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: @Override public org.apache.lucene.queries.function.FunctionValues GetValues(java.util.Map context, org.apache.lucene.index.AtomicReaderContext readerContext) throws java.io.IOException
- public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext)
- {
- IndexSearcher searcher = (IndexSearcher)context["searcher"];
- return new ConstIntDocValues(searcher.IndexReader.maxDoc(), this);
- }
-
- public override bool Equals(object o)
- {
- return this.GetType() == o.GetType();
- }
-
- public override int GetHashCode()
- {
- return this.GetType().GetHashCode();
- }
- }
-
+ /// Returns the value of <seealso cref="IndexReader#maxDoc()"/>
+ /// for every document. This is the number of documents
+ /// including deletions.
+ /// </summary>
+ public class MaxDocValueSource : ValueSource
+ {
+ public virtual string Name
+ {
+ get { return "maxdoc"; }
+ }
+
+ public override string Description
+ {
+ get { return Name + "()"; }
+ }
+
+ public override void CreateWeight(IDictionary context, IndexSearcher searcher)
+ {
+ context["searcher"] = searcher;
+ }
+
+ public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext)
+ {
+ var searcher = (IndexSearcher)context["searcher"];
+ return new ConstIntDocValues(searcher.IndexReader.MaxDoc, this);
+ }
+
+ public override bool Equals(object o)
+ {
+ return this.GetType() == o.GetType();
+ }
+
+ public override int GetHashCode()
+ {
+ return this.GetType().GetHashCode();
+ }
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Queries/Function/ValueSources/MaxFloatFunction.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/MaxFloatFunction.cs b/src/Lucene.Net.Queries/Function/ValueSources/MaxFloatFunction.cs
index 417c4ba..6e6126c 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/MaxFloatFunction.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/MaxFloatFunction.cs
@@ -15,39 +15,36 @@
* limitations under the License.
*/
using System;
-using org.apache.lucene.queries.function;
namespace Lucene.Net.Queries.Function.ValueSources
{
+ /// <summary>
+ /// <code>MaxFloatFunction</code> returns the max of it's components.
+ /// </summary>
+ public class MaxFloatFunction : MultiFloatFunction
+ {
+ public MaxFloatFunction(ValueSource[] sources)
+ : base(sources)
+ {
+ }
+ protected override string Name
+ {
+ get { return "max"; }
+ }
- /// <summary>
- /// <code>MaxFloatFunction</code> returns the max of it's components.
- /// </summary>
- public class MaxFloatFunction : MultiFloatFunction
- {
- public MaxFloatFunction(ValueSource[] sources) : base(sources)
- {
- }
-
- protected internal override string name()
- {
- return "max";
- }
-
- protected internal override float func(int doc, FunctionValues[] valsArr)
- {
- if (valsArr.Length == 0)
- {
- return 0.0f;
- }
- float val = float.NegativeInfinity;
- foreach (FunctionValues vals in valsArr)
- {
- val = Math.Max(vals.FloatVal(doc), val);
- }
- return val;
- }
- }
-
+ protected override float Func(int doc, FunctionValues[] valsArr)
+ {
+ if (valsArr.Length == 0)
+ {
+ return 0.0f;
+ }
+ float val = float.NegativeInfinity;
+ foreach (FunctionValues vals in valsArr)
+ {
+ val = Math.Max(vals.FloatVal(doc), val);
+ }
+ return val;
+ }
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Queries/Function/ValueSources/MinFloatFunction.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/MinFloatFunction.cs b/src/Lucene.Net.Queries/Function/ValueSources/MinFloatFunction.cs
index 9457ee1..3284b44 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/MinFloatFunction.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/MinFloatFunction.cs
@@ -15,39 +15,36 @@
* limitations under the License.
*/
using System;
-using org.apache.lucene.queries.function;
namespace Lucene.Net.Queries.Function.ValueSources
{
+ /// <summary>
+ /// <code>MinFloatFunction</code> returns the min of it's components.
+ /// </summary>
+ public class MinFloatFunction : MultiFloatFunction
+ {
+ public MinFloatFunction(ValueSource[] sources)
+ : base(sources)
+ {
+ }
+ protected override string Name
+ {
+ get { return "min"; }
+ }
- /// <summary>
- /// <code>MinFloatFunction</code> returns the min of it's components.
- /// </summary>
- public class MinFloatFunction : MultiFloatFunction
- {
- public MinFloatFunction(ValueSource[] sources) : base(sources)
- {
- }
-
- protected internal override string name()
- {
- return "min";
- }
-
- protected internal override float func(int doc, FunctionValues[] valsArr)
- {
- if (valsArr.Length == 0)
- {
- return 0.0f;
- }
- float val = float.PositiveInfinity;
- foreach (FunctionValues vals in valsArr)
- {
- val = Math.Min(vals.FloatVal(doc), val);
- }
- return val;
- }
- }
-
+ protected override float Func(int doc, FunctionValues[] valsArr)
+ {
+ if (valsArr.Length == 0)
+ {
+ return 0.0f;
+ }
+ float val = float.PositiveInfinity;
+ foreach (FunctionValues vals in valsArr)
+ {
+ val = Math.Min(vals.FloatVal(doc), val);
+ }
+ return val;
+ }
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Queries/Function/ValueSources/MultiBoolFunction.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/MultiBoolFunction.cs b/src/Lucene.Net.Queries/Function/ValueSources/MultiBoolFunction.cs
index 7e44df3..e938720 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/MultiBoolFunction.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/MultiBoolFunction.cs
@@ -17,127 +17,127 @@
using System.Collections;
using System.Collections.Generic;
using System.Text;
+using Lucene.Net.Index;
using Lucene.Net.Queries.Function.DocValues;
-using org.apache.lucene.queries.function;
+using Lucene.Net.Search;
namespace Lucene.Net.Queries.Function.ValueSources
{
/// <summary>
- /// Abstract <seealso cref="ValueSource"/> implementation which wraps multiple ValueSources
- /// and applies an extendible boolean function to their values.
- ///
- /// </summary>
- public abstract class MultiBoolFunction : BoolFunction
- {
- protected internal readonly IList<ValueSource> sources;
-
- public MultiBoolFunction(IList<ValueSource> sources)
- {
- this.sources = sources;
- }
-
- protected internal abstract string name();
-
- protected internal abstract bool func(int doc, FunctionValues[] vals);
-
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: @Override public org.apache.lucene.queries.function.docvalues.BoolDocValues GetValues(java.util.Map context, org.apache.lucene.index.AtomicReaderContext readerContext) throws java.io.IOException
- public override BoolDocValues GetValues(IDictionary context, AtomicReaderContext readerContext)
- {
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final org.apache.lucene.queries.function.FunctionValues[] vals = new org.apache.lucene.queries.function.FunctionValues[sources.size()];
- FunctionValues[] vals = new FunctionValues[sources.Count];
- int i = 0;
- foreach (ValueSource source in sources)
- {
- vals[i++] = source.GetValues(context, readerContext);
- }
-
- return new BoolDocValuesAnonymousInnerClassHelper(this, this, vals);
- }
-
- private class BoolDocValuesAnonymousInnerClassHelper : BoolDocValues
- {
- private readonly MultiBoolFunction outerInstance;
-
- private FunctionValues[] vals;
-
- public BoolDocValuesAnonymousInnerClassHelper(MultiBoolFunction outerInstance, MultiBoolFunction this, FunctionValues[] vals) : base(this)
- {
- this.outerInstance = outerInstance;
- this.vals = vals;
- }
-
- public override bool boolVal(int doc)
- {
- return outerInstance.func(doc, vals);
- }
-
- public override string ToString(int doc)
- {
- StringBuilder sb = new StringBuilder(outerInstance.name());
- sb.Append('(');
- bool first = true;
- foreach (FunctionValues dv in vals)
- {
- if (first)
- {
- first = false;
- }
- else
- {
- sb.Append(',');
- }
- sb.Append(dv.ToString(doc));
- }
- return sb.ToString();
- }
- }
-
- public override string description()
- {
- StringBuilder sb = new StringBuilder(name());
- sb.Append('(');
- bool first = true;
- foreach (ValueSource source in sources)
- {
- if (first)
- {
- first = false;
- }
- else
- {
- sb.Append(',');
- }
- sb.Append(source.description());
- }
- return sb.ToString();
- }
-
- public override int GetHashCode()
- {
- return sources.GetHashCode() + name().GetHashCode();
- }
-
- public override bool Equals(object o)
- {
- if (this.GetType() != o.GetType())
- {
- return false;
- }
- MultiBoolFunction other = (MultiBoolFunction)o;
- return this.sources.Equals(other.sources);
- }
-
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: @Override public void CreateWeight(java.util.Map context, org.apache.lucene.search.IndexSearcher searcher) throws java.io.IOException
- public override void CreateWeight(IDictionary context, IndexSearcher searcher)
- {
- foreach (ValueSource source in sources)
- {
- source.CreateWeight(context, searcher);
- }
- }
- }
-
+ /// Abstract <seealso cref="ValueSource"/> implementation which wraps multiple ValueSources
+ /// and applies an extendible boolean function to their values.
+ ///
+ /// </summary>
+ public abstract class MultiBoolFunction : BoolFunction
+ {
+ protected readonly IList<ValueSource> sources;
+
+ protected MultiBoolFunction(IList<ValueSource> sources)
+ {
+ this.sources = sources;
+ }
+
+ protected abstract string Name { get; }
+
+ protected abstract bool Func(int doc, FunctionValues[] vals);
+
+ public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext)
+ {
+ var vals = new FunctionValues[sources.Count];
+ int i = 0;
+ foreach (ValueSource source in sources)
+ {
+ vals[i++] = source.GetValues(context, readerContext);
+ }
+
+ return new BoolDocValuesAnonymousInnerClassHelper(this, this, vals);
+ }
+
+ private class BoolDocValuesAnonymousInnerClassHelper : BoolDocValues
+ {
+ private readonly MultiBoolFunction outerInstance;
+
+ private readonly FunctionValues[] vals;
+
+ public BoolDocValuesAnonymousInnerClassHelper(MultiBoolFunction outerInstance, MultiBoolFunction @this, FunctionValues[] vals)
+ : base(@this)
+ {
+ this.outerInstance = outerInstance;
+ this.vals = vals;
+ }
+
+ public override bool BoolVal(int doc)
+ {
+ return outerInstance.Func(doc, vals);
+ }
+
+ public override string ToString(int doc)
+ {
+ var sb = new StringBuilder(outerInstance.Name);
+ sb.Append('(');
+ bool first = true;
+ foreach (FunctionValues dv in vals)
+ {
+ if (first)
+ {
+ first = false;
+ }
+ else
+ {
+ sb.Append(',');
+ }
+ sb.Append(dv.ToString(doc));
+ }
+ return sb.ToString();
+ }
+ }
+
+ public override string Description
+ {
+ get
+ {
+ var sb = new StringBuilder(Name);
+ sb.Append('(');
+ bool first = true;
+ foreach (ValueSource source in sources)
+ {
+ if (first)
+ {
+ first = false;
+ }
+ else
+ {
+ sb.Append(',');
+ }
+ sb.Append(source.Description);
+ }
+ return sb.ToString();
+ }
+ }
+
+ public override int GetHashCode()
+ {
+ return sources.GetHashCode() + Name.GetHashCode();
+ }
+
+ public override bool Equals(object o)
+ {
+ if (this.GetType() != o.GetType())
+ {
+ return false;
+ }
+ var other = o as MultiBoolFunction;
+ if (other == null)
+ return false;
+ return this.sources.Equals(other.sources);
+ }
+
+ public override void CreateWeight(IDictionary context, IndexSearcher searcher)
+ {
+ foreach (ValueSource source in sources)
+ {
+ source.CreateWeight(context, searcher);
+ }
+ }
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Queries/Function/ValueSources/MultiFloatFunction.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/MultiFloatFunction.cs b/src/Lucene.Net.Queries/Function/ValueSources/MultiFloatFunction.cs
index 98678c9..5445847 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/MultiFloatFunction.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/MultiFloatFunction.cs
@@ -1,140 +1,143 @@
using System.Collections;
using System.Text;
+using Lucene.Net.Index;
using Lucene.Net.Queries.Function.DocValues;
+using Lucene.Net.Search;
+using Lucene.Net.Support;
namespace Lucene.Net.Queries.Function.ValueSources
{
- /*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
+ /*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
/// <summary>
- /// Abstract <seealso cref="ValueSource"/> implementation which wraps multiple ValueSources
- /// and applies an extendible float function to their values.
- ///
- /// </summary>
- public abstract class MultiFloatFunction : ValueSource
- {
- protected internal readonly ValueSource[] sources;
+ /// Abstract <seealso cref="ValueSource"/> implementation which wraps multiple ValueSources
+ /// and applies an extendible float function to their values.
+ ///
+ /// </summary>
+ public abstract class MultiFloatFunction : ValueSource
+ {
+ protected internal readonly ValueSource[] sources;
- public MultiFloatFunction(ValueSource[] sources)
- {
- this.sources = sources;
- }
+ protected MultiFloatFunction(ValueSource[] sources)
+ {
+ this.sources = sources;
+ }
- protected internal abstract string name();
- protected internal abstract float func(int doc, FunctionValues[] valsArr);
+ protected abstract string Name { get; }
- public override string description()
- {
- StringBuilder sb = new StringBuilder();
- sb.Append(name()).Append('(');
- bool firstTime = true;
- foreach (ValueSource source in sources)
- {
- if (firstTime)
- {
- firstTime = false;
- }
- else
- {
- sb.Append(',');
- }
- sb.Append((object) source);
- }
- sb.Append(')');
- return sb.ToString();
- }
+ protected abstract float Func(int doc, FunctionValues[] valsArr);
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: @Override public org.apache.lucene.queries.function.FunctionValues GetValues(java.util.Map context, org.apache.lucene.index.AtomicReaderContext readerContext) throws java.io.IOException
- public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext)
- {
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final org.apache.lucene.queries.function.FunctionValues[] valsArr = new org.apache.lucene.queries.function.FunctionValues[sources.length];
- FunctionValues[] valsArr = new FunctionValues[sources.Length];
- for (int i = 0; i < sources.Length; i++)
- {
- valsArr[i] = sources[i].GetValues(context, readerContext);
- }
+ public override string Description
+ {
+ get
+ {
+ var sb = new StringBuilder();
+ sb.Append(Name).Append('(');
+ bool firstTime = true;
+ foreach (var source in sources)
+ {
+ if (firstTime)
+ {
+ firstTime = false;
+ }
+ else
+ {
+ sb.Append(',');
+ }
+ sb.Append(source);
+ }
+ sb.Append(')');
+ return sb.ToString();
+ }
+ }
- return new FloatDocValuesAnonymousInnerClassHelper(this, this, valsArr);
- }
+ public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext)
+ {
+ var valsArr = new FunctionValues[sources.Length];
+ for (int i = 0; i < sources.Length; i++)
+ {
+ valsArr[i] = sources[i].GetValues(context, readerContext);
+ }
- private class FloatDocValuesAnonymousInnerClassHelper : FloatDocValues
- {
- private readonly MultiFloatFunction outerInstance;
+ return new FloatDocValuesAnonymousInnerClassHelper(this, this, valsArr);
+ }
- private FunctionValues[] valsArr;
+ private class FloatDocValuesAnonymousInnerClassHelper : FloatDocValues
+ {
+ private readonly MultiFloatFunction outerInstance;
- public FloatDocValuesAnonymousInnerClassHelper(MultiFloatFunction outerInstance, MultiFloatFunction this, FunctionValues[] valsArr) : base(this)
- {
- this.outerInstance = outerInstance;
- this.valsArr = valsArr;
- }
+ private readonly FunctionValues[] valsArr;
- public override float FloatVal(int doc)
- {
- return outerInstance.func(doc, valsArr);
- }
- public override string ToString(int doc)
- {
- StringBuilder sb = new StringBuilder();
- sb.Append(outerInstance.name()).Append('(');
- bool firstTime = true;
- foreach (FunctionValues vals in valsArr)
- {
- if (firstTime)
- {
- firstTime = false;
- }
- else
- {
- sb.Append(',');
- }
- sb.Append(vals.ToString(doc));
- }
- sb.Append(')');
- return sb.ToString();
- }
- }
+ public FloatDocValuesAnonymousInnerClassHelper(MultiFloatFunction outerInstance, MultiFloatFunction @this, FunctionValues[] valsArr)
+ : base(@this)
+ {
+ this.outerInstance = outerInstance;
+ this.valsArr = valsArr;
+ }
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: @Override public void CreateWeight(java.util.Map context, org.apache.lucene.search.IndexSearcher searcher) throws java.io.IOException
- public override void CreateWeight(IDictionary context, IndexSearcher searcher)
- {
- foreach (ValueSource source in sources)
- {
- source.CreateWeight(context, searcher);
- }
- }
+ public override float FloatVal(int doc)
+ {
+ return outerInstance.Func(doc, valsArr);
+ }
+ public override string ToString(int doc)
+ {
+ var sb = new StringBuilder();
+ sb.Append(outerInstance.Name).Append('(');
+ bool firstTime = true;
+ foreach (FunctionValues vals in valsArr)
+ {
+ if (firstTime)
+ {
+ firstTime = false;
+ }
+ else
+ {
+ sb.Append(',');
+ }
+ sb.Append(vals.ToString(doc));
+ }
+ sb.Append(')');
+ return sb.ToString();
+ }
+ }
- public override int GetHashCode()
- {
- return Arrays.GetHashCode(sources) + name().GetHashCode();
- }
+ public override void CreateWeight(IDictionary context, IndexSearcher searcher)
+ {
+ foreach (ValueSource source in sources)
+ {
+ source.CreateWeight(context, searcher);
+ }
+ }
- public override bool Equals(object o)
- {
- if (this.GetType() != o.GetType())
- {
- return false;
- }
- MultiFloatFunction other = (MultiFloatFunction)o;
- return this.name().Equals(other.name()) && Arrays.Equals(this.sources, other.sources);
- }
- }
+ public override int GetHashCode()
+ {
+ return Arrays.GetHashCode(sources) + Name.GetHashCode();
+ }
+ public override bool Equals(object o)
+ {
+ if (this.GetType() != o.GetType())
+ {
+ return false;
+ }
+ var other = o as MultiFloatFunction;
+ if (other == null)
+ return false;
+ return Name.Equals(other.Name) && Arrays.Equals(this.sources, other.sources);
+ }
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Queries/Function/ValueSources/MultiFunction.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/MultiFunction.cs b/src/Lucene.Net.Queries/Function/ValueSources/MultiFunction.cs
index e45c77f..3351701 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/MultiFunction.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/MultiFunction.cs
@@ -30,7 +30,7 @@ namespace Lucene.Net.Queries.Function.ValueSources
{
protected internal readonly IList<ValueSource> sources;
- public MultiFunction(IList<ValueSource> sources)
+ protected MultiFunction(IList<ValueSource> sources)
{
this.sources = sources;
}
@@ -44,7 +44,7 @@ namespace Lucene.Net.Queries.Function.ValueSources
public static string GetDescription(string name, IList<ValueSource> sources)
{
- StringBuilder sb = new StringBuilder();
+ var sb = new StringBuilder();
sb.Append(name).Append('(');
bool firstTime = true;
foreach (ValueSource source in sources)
@@ -95,7 +95,7 @@ namespace Lucene.Net.Queries.Function.ValueSources
public static string ToString(string name, FunctionValues[] valsArr, int doc)
{
- StringBuilder sb = new StringBuilder();
+ var sb = new StringBuilder();
sb.Append(name).Append('(');
bool firstTime = true;
foreach (FunctionValues vals in valsArr)
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/5506faf0/src/Lucene.Net.Queries/Function/ValueSources/MultiValueSource.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/MultiValueSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/MultiValueSource.cs
index 215d74e..72e4781 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/MultiValueSource.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/MultiValueSource.cs
@@ -25,8 +25,6 @@
/// </summary>
public abstract class MultiValueSource : ValueSource
{
-
- public abstract int dimension();
+ public abstract int Dimension { get; }
}
-
}
\ No newline at end of file