You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by sy...@apache.org on 2014/09/19 16:19:50 UTC
[17/21] More work on Lucene.Net.Queries
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ba0f3c7d/src/Lucene.Net.Queries/Function/FunctionValues.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/FunctionValues.cs b/src/Lucene.Net.Queries/Function/FunctionValues.cs
index 862d0ba..b9443dd 100644
--- a/src/Lucene.Net.Queries/Function/FunctionValues.cs
+++ b/src/Lucene.Net.Queries/Function/FunctionValues.cs
@@ -1,362 +1,365 @@
using System;
+using Lucene.Net.Index;
+using Lucene.Net.Search;
+using Lucene.Net.Util;
+using Lucene.Net.Util.Mutable;
-namespace org.apache.lucene.queries.function
+namespace Lucene.Net.Queries.Function
{
- /*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
- using org.apache.lucene.search;
- using IndexReader = org.apache.lucene.index.IndexReader;
- using BytesRef = org.apache.lucene.util.BytesRef;
- using MutableValue = org.apache.lucene.util.mutable.MutableValue;
- using MutableValueFloat = org.apache.lucene.util.mutable.MutableValueFloat;
-
- /// <summary>
- /// Represents field values as different types.
- /// Normally created via a <seealso cref="ValueSource"/> for a particular field and reader.
- ///
- ///
- /// </summary>
-
- // FunctionValues is distinct from ValueSource because
- // there needs to be an object created at query evaluation time that
- // is not referenced by the query itself because:
- // - Query objects should be MT safe
- // - For caching, Query objects are often used as keys... you don't
- // want the Query carrying around big objects
- public abstract class FunctionValues
- {
-
- public virtual sbyte byteVal(int doc)
- {
- throw new System.NotSupportedException();
- }
- public virtual short shortVal(int doc)
- {
- throw new System.NotSupportedException();
- }
-
- public virtual float floatVal(int doc)
- {
- throw new System.NotSupportedException();
- }
- public virtual int intVal(int doc)
- {
- throw new System.NotSupportedException();
- }
- public virtual long longVal(int doc)
- {
- throw new System.NotSupportedException();
- }
- public virtual double doubleVal(int doc)
- {
- throw new System.NotSupportedException();
- }
- // TODO: should we make a termVal, returns BytesRef?
- public virtual string strVal(int doc)
- {
- throw new System.NotSupportedException();
- }
-
- public virtual bool boolVal(int doc)
- {
- return intVal(doc) != 0;
- }
-
- /// <summary>
- /// returns the bytes representation of the string val - TODO: should this return the indexed raw bytes not? </summary>
- public virtual bool bytesVal(int doc, BytesRef target)
- {
- string s = strVal(doc);
- if (s == null)
- {
- target.length = 0;
- return false;
- }
- target.copyChars(s);
- return true;
- }
-
- /// <summary>
- /// Native Java Object representation of the value </summary>
- public virtual object objectVal(int doc)
- {
- // most FunctionValues are functions, so by default return a Float()
- return floatVal(doc);
- }
-
- /// <summary>
- /// Returns true if there is a value for this document </summary>
- public virtual bool exists(int doc)
- {
- return true;
- }
-
- /// <param name="doc"> The doc to retrieve to sort ordinal for </param>
- /// <returns> the sort ordinal for the specified doc
- /// TODO: Maybe we can just use intVal for this... </returns>
- public virtual int ordVal(int doc)
- {
- throw new System.NotSupportedException();
- }
-
- /// <returns> the number of unique sort ordinals this instance has </returns>
- public virtual int numOrd()
- {
- throw new System.NotSupportedException();
- }
- public abstract string ToString(int doc);
-
- /// <summary>
- /// Abstraction of the logic required to fill the value of a specified doc into
- /// a reusable <seealso cref="MutableValue"/>. Implementations of <seealso cref="FunctionValues"/>
- /// are encouraged to define their own implementations of ValueFiller if their
- /// value is not a float.
- ///
- /// @lucene.experimental
- /// </summary>
- public abstract class ValueFiller
- {
- /// <summary>
- /// MutableValue will be reused across calls </summary>
- public abstract MutableValue Value {get;}
-
- /// <summary>
- /// MutableValue will be reused across calls. Returns true if the value exists. </summary>
- public abstract void fillValue(int doc);
- }
-
- /// <summary>
- /// @lucene.experimental </summary>
- public virtual ValueFiller ValueFiller
- {
- get
- {
- return new ValueFillerAnonymousInnerClassHelper(this);
- }
- }
-
- private class ValueFillerAnonymousInnerClassHelper : ValueFiller
- {
- private readonly FunctionValues outerInstance;
-
- public ValueFillerAnonymousInnerClassHelper(FunctionValues outerInstance)
- {
- this.outerInstance = outerInstance;
- mval = new MutableValueFloat();
- }
-
- private readonly MutableValueFloat mval;
-
- public override MutableValue Value
- {
- get
- {
- return mval;
- }
- }
-
- public override void fillValue(int doc)
- {
- mval.value = outerInstance.floatVal(doc);
- }
- }
-
- //For Functions that can work with multiple values from the same document. This does not apply to all functions
- public virtual void byteVal(int doc, sbyte[] vals)
- {
- throw new System.NotSupportedException();
- }
- public virtual void shortVal(int doc, short[] vals)
- {
- throw new System.NotSupportedException();
- }
-
- public virtual void floatVal(int doc, float[] vals)
- {
- throw new System.NotSupportedException();
- }
- public virtual void intVal(int doc, int[] vals)
- {
- throw new System.NotSupportedException();
- }
- public virtual void longVal(int doc, long[] vals)
- {
- throw new System.NotSupportedException();
- }
- public virtual void doubleVal(int doc, double[] vals)
- {
- throw new System.NotSupportedException();
- }
-
- // TODO: should we make a termVal, fills BytesRef[]?
- public virtual void strVal(int doc, string[] vals)
- {
- throw new System.NotSupportedException();
- }
-
- public virtual Explanation explain(int doc)
- {
- return new Explanation(floatVal(doc), ToString(doc));
- }
-
- public virtual ValueSourceScorer getScorer(IndexReader reader)
- {
- return new ValueSourceScorer(reader, this);
- }
-
- // A RangeValueSource can't easily be a ValueSource that takes another ValueSource
- // because it needs different behavior depending on the type of fields. There is also
- // a setup cost - parsing and normalizing params, and doing a binary search on the StringIndex.
- // TODO: change "reader" to AtomicReaderContext
- public virtual ValueSourceScorer getRangeScorer(IndexReader reader, string lowerVal, string upperVal, bool includeLower, bool includeUpper)
- {
- float lower;
- float upper;
-
- if (lowerVal == null)
- {
- lower = float.NegativeInfinity;
- }
- else
- {
- lower = Convert.ToSingle(lowerVal);
- }
- if (upperVal == null)
- {
- upper = float.PositiveInfinity;
- }
- else
- {
- upper = Convert.ToSingle(upperVal);
- }
-
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final float l = lower;
- float l = lower;
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final float u = upper;
- float u = upper;
-
- if (includeLower && includeUpper)
- {
- return new ValueSourceScorerAnonymousInnerClassHelper(this, reader, this, l, u);
- }
- else if (includeLower && !includeUpper)
- {
- return new ValueSourceScorerAnonymousInnerClassHelper2(this, reader, this, l, u);
- }
- else if (!includeLower && includeUpper)
- {
- return new ValueSourceScorerAnonymousInnerClassHelper3(this, reader, this, l, u);
- }
- else
- {
- return new ValueSourceScorerAnonymousInnerClassHelper4(this, reader, this, l, u);
- }
- }
-
- private class ValueSourceScorerAnonymousInnerClassHelper : ValueSourceScorer
- {
- private readonly FunctionValues outerInstance;
-
- private float l;
- private float u;
-
- public ValueSourceScorerAnonymousInnerClassHelper(FunctionValues outerInstance, IndexReader reader, org.apache.lucene.queries.function.FunctionValues this, float l, float u) : base(reader, this)
- {
- this.outerInstance = outerInstance;
- this.l = l;
- this.u = u;
- }
-
- public override bool matchesValue(int doc)
- {
- float docVal = outerInstance.floatVal(doc);
- return docVal >= l && docVal <= u;
- }
- }
-
- private class ValueSourceScorerAnonymousInnerClassHelper2 : ValueSourceScorer
- {
- private readonly FunctionValues outerInstance;
-
- private float l;
- private float u;
-
- public ValueSourceScorerAnonymousInnerClassHelper2(FunctionValues outerInstance, IndexReader reader, org.apache.lucene.queries.function.FunctionValues this, float l, float u) : base(reader, this)
- {
- this.outerInstance = outerInstance;
- this.l = l;
- this.u = u;
- }
-
- public override bool matchesValue(int doc)
- {
- float docVal = outerInstance.floatVal(doc);
- return docVal >= l && docVal < u;
- }
- }
-
- private class ValueSourceScorerAnonymousInnerClassHelper3 : ValueSourceScorer
- {
- private readonly FunctionValues outerInstance;
-
- private float l;
- private float u;
-
- public ValueSourceScorerAnonymousInnerClassHelper3(FunctionValues outerInstance, IndexReader reader, org.apache.lucene.queries.function.FunctionValues this, float l, float u) : base(reader, this)
- {
- this.outerInstance = outerInstance;
- this.l = l;
- this.u = u;
- }
-
- public override bool matchesValue(int doc)
- {
- float docVal = outerInstance.floatVal(doc);
- return docVal > l && docVal <= u;
- }
- }
-
- private class ValueSourceScorerAnonymousInnerClassHelper4 : ValueSourceScorer
- {
- private readonly FunctionValues outerInstance;
-
- private float l;
- private float u;
-
- public ValueSourceScorerAnonymousInnerClassHelper4(FunctionValues outerInstance, IndexReader reader, org.apache.lucene.queries.function.FunctionValues this, float l, float u) : base(reader, this)
- {
- this.outerInstance = outerInstance;
- this.l = l;
- this.u = u;
- }
-
- public override bool matchesValue(int doc)
- {
- float docVal = outerInstance.floatVal(doc);
- return docVal > l && docVal < u;
- }
- }
- }
-
-
-
-
+ /*
+ * 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>
+ /// Represents field values as different types.
+ /// Normally created via a <seealso cref="ValueSource"/> for a particular field and reader.
+ ///
+ ///
+ /// </summary>
+
+ // FunctionValues is distinct from ValueSource because
+ // there needs to be an object created at query evaluation time that
+ // is not referenced by the query itself because:
+ // - Query objects should be MT safe
+ // - For caching, Query objects are often used as keys... you don't
+ // want the Query carrying around big objects
+ public abstract class FunctionValues
+ {
+
+ public virtual sbyte ByteVal(int doc)
+ {
+ throw new System.NotSupportedException();
+ }
+
+ public virtual short ShortVal(int doc)
+ {
+ throw new System.NotSupportedException();
+ }
+
+ public virtual float FloatVal(int doc)
+ {
+ throw new System.NotSupportedException();
+ }
+
+ public virtual int IntVal(int doc)
+ {
+ throw new System.NotSupportedException();
+ }
+
+ public virtual long LongVal(int doc)
+ {
+ throw new System.NotSupportedException();
+ }
+
+ public virtual double DoubleVal(int doc)
+ {
+ throw new System.NotSupportedException();
+ }
+
+ // TODO: should we make a termVal, returns BytesRef?
+ public virtual string StrVal(int doc)
+ {
+ throw new System.NotSupportedException();
+ }
+
+ public virtual bool BoolVal(int doc)
+ {
+ return IntVal(doc) != 0;
+ }
+
+ /// <summary>
+ /// returns the bytes representation of the string val - TODO: should this return the indexed raw bytes not? </summary>
+ public virtual bool BytesVal(int doc, BytesRef target)
+ {
+ string s = StrVal(doc);
+ if (s == null)
+ {
+ target.Length = 0;
+ return false;
+ }
+ target.CopyChars(s);
+ return true;
+ }
+
+ /// <summary>
+ /// Native Java Object representation of the value </summary>
+ public virtual object ObjectVal(int doc)
+ {
+ // most FunctionValues are functions, so by default return a Float()
+ return FloatVal(doc);
+ }
+
+ /// <summary>
+ /// Returns true if there is a value for this document </summary>
+ public virtual bool Exists(int doc)
+ {
+ return true;
+ }
+
+ /// <param name="doc"> The doc to retrieve to sort ordinal for </param>
+ /// <returns> the sort ordinal for the specified doc
+ /// TODO: Maybe we can just use intVal for this... </returns>
+ public virtual int OrdVal(int doc)
+ {
+ throw new System.NotSupportedException();
+ }
+
+ /// <returns> the number of unique sort ordinals this instance has </returns>
+ public virtual int NumOrd()
+ {
+ throw new System.NotSupportedException();
+ }
+
+ public abstract string ToString(int doc);
+
+ /// <summary>
+ /// Abstraction of the logic required to fill the value of a specified doc into
+ /// a reusable <seealso cref="MutableValue"/>. Implementations of <seealso cref="FunctionValues"/>
+ /// are encouraged to define their own implementations of ValueFiller if their
+ /// value is not a float.
+ ///
+ /// @lucene.experimental
+ /// </summary>
+ public abstract class AbstractValueFiller
+ {
+ /// <summary>
+ /// MutableValue will be reused across calls </summary>
+ public abstract MutableValue Value { get; }
+
+ /// <summary>
+ /// MutableValue will be reused across calls. Returns true if the value exists. </summary>
+ public abstract void FillValue(int doc);
+ }
+
+ /// <summary>
+ /// @lucene.experimental </summary>
+ public virtual AbstractValueFiller ValueFiller
+ {
+ get { return new ValueFillerAnonymousInnerClassHelper(this); }
+ }
+
+ private class ValueFillerAnonymousInnerClassHelper : AbstractValueFiller
+ {
+ private readonly FunctionValues outerInstance;
+
+ public ValueFillerAnonymousInnerClassHelper(FunctionValues outerInstance)
+ {
+ this.outerInstance = outerInstance;
+ mval = new MutableValueFloat();
+ }
+
+ private readonly MutableValueFloat mval;
+
+ public override MutableValue Value
+ {
+ get { return mval; }
+ }
+
+ public override void FillValue(int doc)
+ {
+ mval.Value = outerInstance.FloatVal(doc);
+ }
+ }
+
+ //For Functions that can work with multiple values from the same document. This does not apply to all functions
+ public virtual void ByteVal(int doc, sbyte[] vals)
+ {
+ throw new System.NotSupportedException();
+ }
+
+ public virtual void ShortVal(int doc, short[] vals)
+ {
+ throw new System.NotSupportedException();
+ }
+
+ public virtual void FloatVal(int doc, float[] vals)
+ {
+ throw new System.NotSupportedException();
+ }
+
+ public virtual void IntVal(int doc, int[] vals)
+ {
+ throw new System.NotSupportedException();
+ }
+
+ public virtual void LongVal(int doc, long[] vals)
+ {
+ throw new System.NotSupportedException();
+ }
+
+ public virtual void DoubleVal(int doc, double[] vals)
+ {
+ throw new System.NotSupportedException();
+ }
+
+ // TODO: should we make a termVal, fills BytesRef[]?
+ public virtual void StrVal(int doc, string[] vals)
+ {
+ throw new System.NotSupportedException();
+ }
+
+ public virtual Explanation Explain(int doc)
+ {
+ return new Explanation(FloatVal(doc), ToString(doc));
+ }
+
+ public virtual ValueSourceScorer GetScorer(IndexReader reader)
+ {
+ return new ValueSourceScorer(reader, this);
+ }
+
+ // A RangeValueSource can't easily be a ValueSource that takes another ValueSource
+ // because it needs different behavior depending on the type of fields. There is also
+ // a setup cost - parsing and normalizing params, and doing a binary search on the StringIndex.
+ // TODO: change "reader" to AtomicReaderContext
+ public virtual ValueSourceScorer GetRangeScorer(IndexReader reader, string lowerVal, string upperVal,
+ bool includeLower, bool includeUpper)
+ {
+ float lower;
+ float upper;
+
+ if (lowerVal == null)
+ {
+ lower = float.NegativeInfinity;
+ }
+ else
+ {
+ lower = Convert.ToSingle(lowerVal);
+ }
+ if (upperVal == null)
+ {
+ upper = float.PositiveInfinity;
+ }
+ else
+ {
+ upper = Convert.ToSingle(upperVal);
+ }
+
+ float l = lower;
+ float u = upper;
+
+ if (includeLower && includeUpper)
+ {
+ return new ValueSourceScorerAnonymousInnerClassHelper(this, reader, this, l, u);
+ }
+ else if (includeLower && !includeUpper)
+ {
+ return new ValueSourceScorerAnonymousInnerClassHelper2(this, reader, this, l, u);
+ }
+ else if (!includeLower && includeUpper)
+ {
+ return new ValueSourceScorerAnonymousInnerClassHelper3(this, reader, this, l, u);
+ }
+ else
+ {
+ return new ValueSourceScorerAnonymousInnerClassHelper4(this, reader, this, l, u);
+ }
+ }
+
+ private class ValueSourceScorerAnonymousInnerClassHelper : ValueSourceScorer
+ {
+ private readonly FunctionValues outerInstance;
+
+ private float l;
+ private float u;
+
+ public ValueSourceScorerAnonymousInnerClassHelper(FunctionValues outerInstance, IndexReader reader,
+ FunctionValues @this, float l, float u)
+ : base(reader, @this)
+ {
+ this.outerInstance = outerInstance;
+ this.l = l;
+ this.u = u;
+ }
+
+ public override bool MatchesValue(int doc)
+ {
+ float docVal = outerInstance.FloatVal(doc);
+ return docVal >= l && docVal <= u;
+ }
+ }
+
+ private class ValueSourceScorerAnonymousInnerClassHelper2 : ValueSourceScorer
+ {
+ private readonly FunctionValues outerInstance;
+
+ private float l;
+ private float u;
+
+ public ValueSourceScorerAnonymousInnerClassHelper2(FunctionValues outerInstance, IndexReader reader,
+ FunctionValues @this, float l, float u)
+ : base(reader, @this)
+ {
+ this.outerInstance = outerInstance;
+ this.l = l;
+ this.u = u;
+ }
+
+ public override bool MatchesValue(int doc)
+ {
+ float docVal = outerInstance.FloatVal(doc);
+ return docVal >= l && docVal < u;
+ }
+ }
+
+ private class ValueSourceScorerAnonymousInnerClassHelper3 : ValueSourceScorer
+ {
+ private readonly FunctionValues outerInstance;
+
+ private float l;
+ private float u;
+
+ public ValueSourceScorerAnonymousInnerClassHelper3(FunctionValues outerInstance, IndexReader reader,
+ FunctionValues @this, float l, float u)
+ : base(reader, @this)
+ {
+ this.outerInstance = outerInstance;
+ this.l = l;
+ this.u = u;
+ }
+
+ public override bool MatchesValue(int doc)
+ {
+ float docVal = outerInstance.FloatVal(doc);
+ return docVal > l && docVal <= u;
+ }
+ }
+
+ private class ValueSourceScorerAnonymousInnerClassHelper4 : ValueSourceScorer
+ {
+ private readonly FunctionValues outerInstance;
+
+ private float l;
+ private float u;
+
+ public ValueSourceScorerAnonymousInnerClassHelper4(FunctionValues outerInstance, IndexReader reader,
+ FunctionValues @this, float l, float u)
+ : base(reader, @this)
+ {
+ this.outerInstance = outerInstance;
+ this.l = l;
+ this.u = u;
+ }
+
+ public override bool MatchesValue(int doc)
+ {
+ float docVal = outerInstance.FloatVal(doc);
+ return docVal > l && docVal < u;
+ }
+ }
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ba0f3c7d/src/Lucene.Net.Queries/Function/ValueSource.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSource.cs b/src/Lucene.Net.Queries/Function/ValueSource.cs
index bb131af..2e29a02 100644
--- a/src/Lucene.Net.Queries/Function/ValueSource.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSource.cs
@@ -1,223 +1,202 @@
using System.Collections;
+using Lucene.Net.Index;
+using Lucene.Net.Search;
+using Lucene.Net.Support;
-namespace org.apache.lucene.queries.function
+namespace Lucene.Net.Queries.Function
{
- /*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
- using AtomicReaderContext = org.apache.lucene.index.AtomicReaderContext;
- using FieldComparator = org.apache.lucene.search.FieldComparator;
- using FieldComparatorSource = org.apache.lucene.search.FieldComparatorSource;
- using IndexSearcher = org.apache.lucene.search.IndexSearcher;
- using SortField = org.apache.lucene.search.SortField;
-
-
- /// <summary>
- /// Instantiates <seealso cref="FunctionValues"/> for a particular reader.
- /// <br>
- /// Often used when creating a <seealso cref="FunctionQuery"/>.
- ///
- ///
- /// </summary>
- public abstract class ValueSource
- {
-
- /// <summary>
- /// Gets the values for this reader and the context that was previously
- /// passed to createWeight()
- /// </summary>
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: public abstract FunctionValues getValues(java.util.Map context, org.apache.lucene.index.AtomicReaderContext readerContext) throws java.io.IOException;
- public abstract FunctionValues getValues(IDictionary context, AtomicReaderContext readerContext);
-
- public override abstract bool Equals(object o);
-
- public override abstract int GetHashCode();
-
- /// <summary>
- /// description of field, used in explain()
- /// </summary>
- public abstract string description();
-
- public override string ToString()
- {
- return description();
- }
-
-
- /// <summary>
- /// Implementations should propagate createWeight to sub-ValueSources which can optionally store
- /// weight info in the context. The context object will be passed to getValues()
- /// where this info can be retrieved.
- /// </summary>
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: public void createWeight(java.util.Map context, org.apache.lucene.search.IndexSearcher searcher) throws java.io.IOException
- public virtual void createWeight(IDictionary context, IndexSearcher searcher)
- {
- }
-
- /// <summary>
- /// Returns a new non-threadsafe context map.
- /// </summary>
- public static IDictionary newContext(IndexSearcher searcher)
- {
- IDictionary context = new IdentityHashMap();
- context["searcher"] = searcher;
- return context;
- }
-
-
- //
- // Sorting by function
- //
-
- /// <summary>
- /// EXPERIMENTAL: This method is subject to change.
- /// <para>
- /// Get the SortField for this ValueSource. Uses the <seealso cref="#getValues(java.util.Map, AtomicReaderContext)"/>
- /// to populate the SortField.
- ///
- /// </para>
- /// </summary>
- /// <param name="reverse"> true if this is a reverse sort. </param>
- /// <returns> The <seealso cref="org.apache.lucene.search.SortField"/> for the ValueSource </returns>
- public virtual SortField getSortField(bool reverse)
- {
- return new ValueSourceSortField(this, reverse);
- }
-
- internal class ValueSourceSortField : SortField
- {
- private readonly ValueSource outerInstance;
-
- public ValueSourceSortField(ValueSource outerInstance, bool reverse) : base(outerInstance.description(), SortField.Type.REWRITEABLE, reverse)
- {
- this.outerInstance = outerInstance;
- }
-
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: @Override public org.apache.lucene.search.SortField rewrite(org.apache.lucene.search.IndexSearcher searcher) throws java.io.IOException
- public override SortField rewrite(IndexSearcher searcher)
- {
- IDictionary context = newContext(searcher);
- outerInstance.createWeight(context, searcher);
- return new SortField(Field, new ValueSourceComparatorSource(outerInstance, context), Reverse);
- }
- }
-
- internal class ValueSourceComparatorSource : FieldComparatorSource
- {
- private readonly ValueSource outerInstance;
-
- internal readonly IDictionary context;
-
- public ValueSourceComparatorSource(ValueSource outerInstance, IDictionary context)
- {
- this.outerInstance = outerInstance;
- this.context = context;
- }
-
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: @Override public org.apache.lucene.search.FieldComparator<Double> newComparator(String fieldname, int numHits, int sortPos, boolean reversed) throws java.io.IOException
- public override FieldComparator<double?> newComparator(string fieldname, int numHits, int sortPos, bool reversed)
- {
- return new ValueSourceComparator(outerInstance, context, numHits);
- }
- }
-
- /// <summary>
- /// Implement a <seealso cref="org.apache.lucene.search.FieldComparator"/> that works
- /// off of the <seealso cref="FunctionValues"/> for a ValueSource
- /// instead of the normal Lucene FieldComparator that works off of a FieldCache.
- /// </summary>
- internal class ValueSourceComparator : FieldComparator<double?>
- {
- private readonly ValueSource outerInstance;
-
- internal readonly double[] values;
- internal FunctionValues docVals;
- internal double bottom;
- internal readonly IDictionary fcontext;
- internal double topValue;
-
- internal ValueSourceComparator(ValueSource outerInstance, IDictionary fcontext, int numHits)
- {
- this.outerInstance = outerInstance;
- this.fcontext = fcontext;
- values = new double[numHits];
- }
-
- public override int compare(int slot1, int slot2)
- {
- return values[slot1].CompareTo(values[slot2]);
- }
-
- public override int compareBottom(int doc)
- {
- return bottom.CompareTo(docVals.doubleVal(doc));
- }
-
- public override void copy(int slot, int doc)
- {
- values[slot] = docVals.doubleVal(doc);
- }
-
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: @Override public org.apache.lucene.search.FieldComparator setNextReader(org.apache.lucene.index.AtomicReaderContext context) throws java.io.IOException
- public override FieldComparator setNextReader(AtomicReaderContext context)
- {
- docVals = outerInstance.getValues(fcontext, context);
- return this;
- }
-
-//JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET:
-//ORIGINAL LINE: @Override public void setBottom(final int bottom)
- public override int Bottom
- {
- set
- {
- this.bottom = values[value];
- }
- }
-
-//JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET:
-//ORIGINAL LINE: @Override public void setTopValue(final Double value)
- public override double? TopValue
- {
- set
- {
- this.topValue = (double)value;
- }
- }
-
- public override double? value(int slot)
- {
- return values[slot];
- }
-
- public override int compareTop(int doc)
- {
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final double docValue = docVals.doubleVal(doc);
- double docValue = docVals.doubleVal(doc);
- return topValue.CompareTo(docValue);
- }
- }
- }
-
+ /*
+ * 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>
+ /// Instantiates <seealso cref="FunctionValues"/> for a particular reader.
+ /// <br>
+ /// Often used when creating a <seealso cref="FunctionQuery"/>.
+ ///
+ ///
+ /// </summary>
+ public abstract class ValueSource
+ {
+
+ /// <summary>
+ /// Gets the values for this reader and the context that was previously
+ /// passed to CreateWeight()
+ /// </summary>
+ public abstract FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext);
+
+ public override abstract bool Equals(object o);
+
+ public override abstract int GetHashCode();
+
+ /// <summary>
+ /// description of field, used in explain()
+ /// </summary>
+ public abstract string Description { get; }
+
+ public override string ToString()
+ {
+ return Description;
+ }
+
+
+ /// <summary>
+ /// Implementations should propagate CreateWeight to sub-ValueSources which can optionally store
+ /// weight info in the context. The context object will be passed to GetValues()
+ /// where this info can be retrieved.
+ /// </summary>
+ public virtual void CreateWeight(IDictionary context, IndexSearcher searcher)
+ {
+ }
+
+ /// <summary>
+ /// Returns a new non-threadsafe context map.
+ /// </summary>
+ public static IDictionary NewContext(IndexSearcher searcher)
+ {
+ IDictionary context = new IdentityHashMap<,>();
+ context["searcher"] = searcher;
+ return context;
+ }
+
+
+ //
+ // Sorting by function
+ //
+
+ /// <summary>
+ /// EXPERIMENTAL: This method is subject to change.
+ /// <para>
+ /// Get the SortField for this ValueSource. Uses the <seealso cref="#GetValues(java.util.Map, AtomicReaderContext)"/>
+ /// to populate the SortField.
+ ///
+ /// </para>
+ /// </summary>
+ /// <param name="reverse"> true if this is a reverse sort. </param>
+ /// <returns> The <seealso cref="org.apache.lucene.search.SortField"/> for the ValueSource </returns>
+ public virtual SortField GetSortField(bool reverse)
+ {
+ return new ValueSourceSortField(this, reverse);
+ }
+
+ internal class ValueSourceSortField : SortField
+ {
+ private readonly ValueSource outerInstance;
+
+ public ValueSourceSortField(ValueSource outerInstance, bool reverse)
+ : base(outerInstance.Description, SortField.Type.REWRITEABLE, reverse)
+ {
+ this.outerInstance = outerInstance;
+ }
+
+ public override SortField Rewrite(IndexSearcher searcher)
+ {
+ IDictionary context = NewContext(searcher);
+ outerInstance.CreateWeight(context, searcher);
+ return new SortField(Field, new ValueSourceComparatorSource(outerInstance, context), Reverse);
+ }
+ }
+
+ internal class ValueSourceComparatorSource : FieldComparatorSource
+ {
+ private readonly ValueSource outerInstance;
+
+ internal readonly IDictionary context;
+
+ public ValueSourceComparatorSource(ValueSource outerInstance, IDictionary context)
+ {
+ this.outerInstance = outerInstance;
+ this.context = context;
+ }
+
+ public override FieldComparator<double?> NewComparator(string fieldname, int numHits, int sortPos, bool reversed)
+ {
+ return new ValueSourceComparator(outerInstance, context, numHits);
+ }
+ }
+
+ /// <summary>
+ /// Implement a <seealso cref="org.apache.lucene.search.FieldComparator"/> that works
+ /// off of the <seealso cref="FunctionValues"/> for a ValueSource
+ /// instead of the normal Lucene FieldComparator that works off of a FieldCache.
+ /// </summary>
+ internal class ValueSourceComparator : FieldComparator<double?>
+ {
+ private readonly ValueSource outerInstance;
+
+ internal readonly double[] values;
+ internal FunctionValues docVals;
+ internal double bottom;
+ internal readonly IDictionary fcontext;
+ internal double topValue;
+
+ internal ValueSourceComparator(ValueSource outerInstance, IDictionary fcontext, int numHits)
+ {
+ this.outerInstance = outerInstance;
+ this.fcontext = fcontext;
+ values = new double[numHits];
+ }
+
+ public override int Compare(int slot1, int slot2)
+ {
+ return values[slot1].CompareTo(values[slot2]);
+ }
+
+ public override int CompareBottom(int doc)
+ {
+ return bottom.CompareTo(docVals.DoubleVal(doc));
+ }
+
+ public override void Copy(int slot, int doc)
+ {
+ values[slot] = docVals.DoubleVal(doc);
+ }
+
+ public override FieldComparator SetNextReader(AtomicReaderContext context)
+ {
+ docVals = outerInstance.GetValues(fcontext, context);
+ return this;
+ }
+
+ public override int Bottom
+ {
+ set
+ {
+ this.bottom = values[value];
+ }
+ }
+
+ public override double? TopValue
+ {
+ set
+ {
+ this.topValue = (double)value;
+ }
+ }
+
+ public override double? Value(int slot)
+ {
+ return values[slot];
+ }
+
+ public override int CompareTop(int doc)
+ {
+ double docValue = docVals.DoubleVal(doc);
+ return topValue.CompareTo(docValue);
+ }
+ }
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ba0f3c7d/src/Lucene.Net.Queries/Function/ValueSourceScorer.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSourceScorer.cs b/src/Lucene.Net.Queries/Function/ValueSourceScorer.cs
index fa79903..a313b66 100644
--- a/src/Lucene.Net.Queries/Function/ValueSourceScorer.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSourceScorer.cs
@@ -1,126 +1,116 @@
-namespace org.apache.lucene.queries.function
-{
-
- /*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
+using Lucene.Net.Index;
+using Lucene.Net.Search;
+using Lucene.Net.Util;
- using IndexReader = org.apache.lucene.index.IndexReader;
- using MultiFields = org.apache.lucene.index.MultiFields;
- using Scorer = org.apache.lucene.search.Scorer;
- using Bits = org.apache.lucene.util.Bits;
-
- /// <summary>
- /// <seealso cref="Scorer"/> which returns the result of <seealso cref="FunctionValues#floatVal(int)"/> as
- /// the score for a document.
- /// </summary>
- public class ValueSourceScorer : Scorer
- {
- protected internal readonly IndexReader reader;
- private int doc = -1;
- protected internal readonly int maxDoc;
- protected internal readonly FunctionValues values;
- protected internal bool checkDeletes;
- private readonly Bits liveDocs;
+namespace Lucene.Net.Queries.Function
+{
- protected internal ValueSourceScorer(IndexReader reader, FunctionValues values) : base(null)
- {
- this.reader = reader;
- this.maxDoc = reader.maxDoc();
- this.values = values;
- CheckDeletes = true;
- this.liveDocs = MultiFields.getLiveDocs(reader);
- }
+ /*
+ * 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>
+ /// <seealso cref="Scorer"/> which returns the result of <seealso cref="FunctionValues#FloatVal(int)"/> as
+ /// the score for a document.
+ /// </summary>
+ public class ValueSourceScorer : Scorer
+ {
+ protected internal readonly IndexReader reader;
+ private int doc = -1;
+ protected internal readonly int maxDoc;
+ protected internal readonly FunctionValues values;
+ protected internal bool checkDeletes;
+ private readonly Bits liveDocs;
- public virtual IndexReader Reader
- {
- get
- {
- return reader;
- }
- }
+ protected internal ValueSourceScorer(IndexReader reader, FunctionValues values)
+ : base(null)
+ {
+ this.reader = reader;
+ this.maxDoc = reader.MaxDoc;
+ this.values = values;
+ CheckDeletes = true;
+ this.liveDocs = MultiFields.GetLiveDocs(reader);
+ }
- public virtual bool CheckDeletes
- {
- set
- {
- this.checkDeletes = value && reader.hasDeletions();
- }
- }
+ public virtual IndexReader Reader
+ {
+ get
+ {
+ return reader;
+ }
+ }
- public virtual bool matches(int doc)
- {
- return (!checkDeletes || liveDocs.get(doc)) && matchesValue(doc);
- }
+ public virtual bool CheckDeletes
+ {
+ set
+ {
+ this.checkDeletes = value && reader.HasDeletions;
+ }
+ }
- public virtual bool matchesValue(int doc)
- {
- return true;
- }
+ public virtual bool Matches(int doc)
+ {
+ return (!checkDeletes || liveDocs.Get(doc)) && MatchesValue(doc);
+ }
- public override int docID()
- {
- return doc;
- }
+ public virtual bool MatchesValue(int doc)
+ {
+ return true;
+ }
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: @Override public int nextDoc() throws java.io.IOException
- public override int nextDoc()
- {
- for (; ;)
- {
- doc++;
- if (doc >= maxDoc)
- {
- return doc = NO_MORE_DOCS;
- }
- if (matches(doc))
- {
- return doc;
- }
- }
- }
+ public override int DocID()
+ {
+ return doc;
+ }
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: @Override public int advance(int target) throws java.io.IOException
- public override int advance(int target)
- {
- // also works fine when target==NO_MORE_DOCS
- doc = target - 1;
- return nextDoc();
- }
+ public override int NextDoc()
+ {
+ for (; ; )
+ {
+ doc++;
+ if (doc >= maxDoc)
+ {
+ return doc = NO_MORE_DOCS;
+ }
+ if (Matches(doc))
+ {
+ return doc;
+ }
+ }
+ }
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: @Override public float score() throws java.io.IOException
- public override float score()
- {
- return values.floatVal(doc);
- }
+ public override int Advance(int target)
+ {
+ // also works fine when target==NO_MORE_DOCS
+ doc = target - 1;
+ return NextDoc();
+ }
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: @Override public int freq() throws java.io.IOException
- public override int freq()
- {
- return 1;
- }
+ public override float Score()
+ {
+ return values.FloatVal(doc);
+ }
- public override long cost()
- {
- return maxDoc;
- }
- }
+ public override int Freq()
+ {
+ return 1;
+ }
+ public override long Cost()
+ {
+ return maxDoc;
+ }
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ba0f3c7d/src/Lucene.Net.Queries/Function/ValueSources/BoolFunction.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/BoolFunction.cs b/src/Lucene.Net.Queries/Function/ValueSources/BoolFunction.cs
index 9a2fab7..d166b6c 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/BoolFunction.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/BoolFunction.cs
@@ -17,14 +17,12 @@
namespace Lucene.Net.Queries.Function.ValueSources
{
-
- /// <summary>
- /// Abstract parent class for those <seealso cref="ValueSource"/> implementations which
- /// apply boolean logic to their values
- /// </summary>
- public abstract class BoolFunction : ValueSource
- {
- // TODO: placeholder to return type, among other common future functionality
- }
-
+ /// <summary>
+ /// Abstract parent class for those <seealso cref="ValueSource"/> implementations which
+ /// apply boolean logic to their values
+ /// </summary>
+ public abstract class BoolFunction : ValueSource
+ {
+ // TODO: placeholder to return type, among other common future functionality
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ba0f3c7d/src/Lucene.Net.Queries/Function/ValueSources/ByteFieldSource.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/ByteFieldSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/ByteFieldSource.cs
index b0ad08a..2b8bc7e 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/ByteFieldSource.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/ByteFieldSource.cs
@@ -1,138 +1,136 @@
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 int field values from the <seealso cref="org.apache.lucene.search.FieldCache"/>
- /// using <code>getInts()</code>
- /// and makes those values available as other numeric types, casting as needed. *
- ///
- ///
- /// </summary>
- [Obsolete]
- public class ByteFieldSource : FieldCacheSource
- {
-
- private readonly FieldCache.ByteParser parser;
-
- public ByteFieldSource(string field) : this(field, null)
- {
- }
-
- public ByteFieldSource(string field, FieldCache.ByteParser parser) : base(field)
- {
- this.parser = parser;
- }
-
- public override string description()
- {
- return "byte(" + 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.Bytes arr = cache.getBytes(readerContext.reader(), field, parser, false);
- FieldCache.Bytes arr = cache.getBytes(readerContext.reader(), field, parser, false);
-
- return new FunctionValuesAnonymousInnerClassHelper(this, arr);
- }
-
- private class FunctionValuesAnonymousInnerClassHelper : FunctionValues
- {
- private readonly ByteFieldSource outerInstance;
-
- private FieldCache.Bytes arr;
-
- public FunctionValuesAnonymousInnerClassHelper(ByteFieldSource outerInstance, FieldCache.Bytes arr)
- {
- this.outerInstance = outerInstance;
- this.arr = arr;
- }
-
- public override sbyte byteVal(int doc)
- {
- return arr.get(doc);
- }
-
- public override short shortVal(int doc)
- {
- return (short) 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() + '=' + byteVal(doc);
- }
-
- public override object objectVal(int doc)
- {
- return arr.get(doc); // TODO: valid?
- }
-
- }
-
- public override bool Equals(object o)
- {
- if (o.GetType() != typeof(ByteFieldSource))
- {
- return false;
- }
- ByteFieldSource other = (ByteFieldSource) 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(sbyte?).GetHashCode() : parser.GetType().GetHashCode();
- h += base.GetHashCode();
- return h;
- }
- }
+ /// Obtains int field values from the <seealso cref="org.apache.lucene.search.FieldCache"/>
+ /// using <code>getInts()</code>
+ /// and makes those values available as other numeric types, casting as needed. *
+ ///
+ ///
+ /// </summary>
+ [Obsolete]
+ public class ByteFieldSource : FieldCacheSource
+ {
+
+ private readonly FieldCache_Fields.IByteParser parser;
+
+ public ByteFieldSource(string field)
+ : this(field, null)
+ {
+ }
+
+ public ByteFieldSource(string field, FieldCache_Fields.IByteParser parser)
+ : base(field)
+ {
+ this.parser = parser;
+ }
+
+ public override string Description
+ {
+ get { return "byte(" + field + ')'; }
+ }
+
+ public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext)
+ {
+ FieldCache_Fields.Bytes arr = cache.GetBytes(readerContext.AtomicReader, field, parser, false);
+
+ return new FunctionValuesAnonymousInnerClassHelper(this, arr);
+ }
+
+ private class FunctionValuesAnonymousInnerClassHelper : FunctionValues
+ {
+ private readonly ByteFieldSource outerInstance;
+ private readonly FieldCache_Fields.Bytes arr;
+
+ public FunctionValuesAnonymousInnerClassHelper(ByteFieldSource outerInstance, FieldCache_Fields.Bytes arr)
+ {
+ this.outerInstance = outerInstance;
+ this.arr = arr;
+ }
+
+ public override sbyte ByteVal(int doc)
+ {
+ return arr.Get(doc);
+ }
+
+ public override short ShortVal(int doc)
+ {
+ return (short)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 + '=' + ByteVal(doc);
+ }
+
+ public override object ObjectVal(int doc)
+ {
+ return arr.Get(doc); // TODO: valid?
+ }
+
+ }
+
+ public override bool Equals(object o)
+ {
+ if (o.GetType() != typeof(ByteFieldSource))
+ {
+ return false;
+ }
+ ByteFieldSource other = (ByteFieldSource)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(sbyte?).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/ba0f3c7d/src/Lucene.Net.Queries/Function/ValueSources/BytesRefFieldSource.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/BytesRefFieldSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/BytesRefFieldSource.cs
index 625ac5b..0ed87a8 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/BytesRefFieldSource.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/BytesRefFieldSource.cs
@@ -1,131 +1,125 @@
using System.Collections;
+using Lucene.Net.Index;
using Lucene.Net.Queries.Function.DocValues;
-using org.apache.lucene.queries.function;
+using Lucene.Net.Search;
+using Lucene.Net.Util;
namespace Lucene.Net.Queries.Function.ValueSources
{
- /*
- * 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>
- /// An implementation for retrieving <seealso cref="FunctionValues"/> instances for string based fields.
- /// </summary>
- public class BytesRefFieldSource : FieldCacheSource
- {
-
- public BytesRefFieldSource(string field) : base(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.index.FieldInfo fieldInfo = readerContext.reader().getFieldInfos().fieldInfo(field);
- FieldInfo fieldInfo = readerContext.reader().FieldInfos.fieldInfo(field);
- // To be sorted or not to be sorted, that is the question
- // TODO: do it cleaner?
- if (fieldInfo != null && fieldInfo.DocValuesType == FieldInfo.DocValuesType.BINARY)
- {
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final org.apache.lucene.index.BinaryDocValues binaryValues = org.apache.lucene.search.FieldCache.DEFAULT.getTerms(readerContext.reader(), field, true);
- BinaryDocValues binaryValues = FieldCache.DEFAULT.getTerms(readerContext.reader(), field, true);
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final org.apache.lucene.util.Bits docsWithField = org.apache.lucene.search.FieldCache.DEFAULT.getDocsWithField(readerContext.reader(), field);
- Bits docsWithField = FieldCache.DEFAULT.getDocsWithField(readerContext.reader(), field);
- return new FunctionValuesAnonymousInnerClassHelper(this, binaryValues, docsWithField);
- }
- else
- {
- return new DocTermsIndexDocValuesAnonymousInnerClassHelper(this, this, readerContext, field);
- }
- }
-
- private class FunctionValuesAnonymousInnerClassHelper : FunctionValues
- {
- private readonly BytesRefFieldSource outerInstance;
-
- private BinaryDocValues binaryValues;
- private Bits docsWithField;
-
- public FunctionValuesAnonymousInnerClassHelper(BytesRefFieldSource outerInstance, BinaryDocValues binaryValues, Bits docsWithField)
- {
- this.outerInstance = outerInstance;
- this.binaryValues = binaryValues;
- this.docsWithField = docsWithField;
- }
-
-
- public override bool exists(int doc)
- {
- return docsWithField.get(doc);
- }
-
- public override bool bytesVal(int doc, BytesRef target)
- {
- binaryValues.get(doc, target);
- return target.length > 0;
- }
-
- public override string strVal(int doc)
- {
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final org.apache.lucene.util.BytesRef bytes = new org.apache.lucene.util.BytesRef();
- BytesRef bytes = new BytesRef();
- return bytesVal(doc, bytes) ? bytes.utf8ToString() : null;
- }
-
- public override object objectVal(int doc)
- {
- return strVal(doc);
- }
-
- public override string ToString(int doc)
- {
- return outerInstance.description() + '=' + strVal(doc);
- }
- }
-
- private class DocTermsIndexDocValuesAnonymousInnerClassHelper : DocTermsIndexDocValues
- {
- private readonly BytesRefFieldSource outerInstance;
-
- public DocTermsIndexDocValuesAnonymousInnerClassHelper(BytesRefFieldSource outerInstance, BytesRefFieldSource this, AtomicReaderContext readerContext, string field) : base(this, readerContext, field)
- {
- this.outerInstance = outerInstance;
- }
-
-
- protected internal override string toTerm(string readableValue)
- {
- return readableValue;
- }
-
- public override object objectVal(int doc)
- {
- return strVal(doc);
- }
-
- public override string ToString(int doc)
- {
- return outerInstance.description() + '=' + strVal(doc);
- }
- }
- }
+ /// An implementation for retrieving <seealso cref="FunctionValues"/> instances for string based fields.
+ /// </summary>
+ public class BytesRefFieldSource : FieldCacheSource
+ {
+
+ public BytesRefFieldSource(string field)
+ : base(field)
+ {
+ }
+
+ public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext)
+ {
+ FieldInfo fieldInfo = readerContext.AtomicReader.FieldInfos.FieldInfo(field);
+ // To be sorted or not to be sorted, that is the question
+ // TODO: do it cleaner?
+ if (fieldInfo != null && fieldInfo.DocValuesType == FieldInfo.DocValuesType_e.BINARY)
+ {
+ BinaryDocValues binaryValues = FieldCache_Fields.DEFAULT.GetTerms(readerContext.AtomicReader, field, true);
+ Bits docsWithField = FieldCache_Fields.DEFAULT.GetDocsWithField(readerContext.AtomicReader, field);
+ return new FunctionValuesAnonymousInnerClassHelper(this, binaryValues, docsWithField);
+ }
+ else
+ {
+ return new DocTermsIndexDocValuesAnonymousInnerClassHelper(this, this, readerContext, field);
+ }
+ }
+
+ private class FunctionValuesAnonymousInnerClassHelper : FunctionValues
+ {
+ private readonly BytesRefFieldSource outerInstance;
+
+ private BinaryDocValues binaryValues;
+ private Bits docsWithField;
+
+ public FunctionValuesAnonymousInnerClassHelper(BytesRefFieldSource outerInstance, BinaryDocValues binaryValues, Bits docsWithField)
+ {
+ this.outerInstance = outerInstance;
+ this.binaryValues = binaryValues;
+ this.docsWithField = docsWithField;
+ }
+
+
+ public override bool Exists(int doc)
+ {
+ return docsWithField.Get(doc);
+ }
+
+ public override bool BytesVal(int doc, BytesRef target)
+ {
+ binaryValues.Get(doc, target);
+ return target.Length > 0;
+ }
+
+ public override string StrVal(int doc)
+ {
+ var bytes = new BytesRef();
+ return BytesVal(doc, bytes) ? bytes.Utf8ToString() : null;
+ }
+
+ public override object ObjectVal(int doc)
+ {
+ return StrVal(doc);
+ }
+
+ public override string ToString(int doc)
+ {
+ return outerInstance.Description + '=' + StrVal(doc);
+ }
+ }
+
+ private class DocTermsIndexDocValuesAnonymousInnerClassHelper : DocTermsIndexDocValues
+ {
+ private readonly BytesRefFieldSource outerInstance;
+
+ public DocTermsIndexDocValuesAnonymousInnerClassHelper(BytesRefFieldSource outerInstance, BytesRefFieldSource @this, AtomicReaderContext readerContext, string field)
+ : base(@this, readerContext, field)
+ {
+ this.outerInstance = outerInstance;
+ }
+
+
+ protected internal override string toTerm(string readableValue)
+ {
+ return readableValue;
+ }
+
+ public override object ObjectVal(int doc)
+ {
+ return StrVal(doc);
+ }
+
+ public override string ToString(int doc)
+ {
+ return outerInstance.Description + '=' + StrVal(doc);
+ }
+ }
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ba0f3c7d/src/Lucene.Net.Queries/Function/ValueSources/ConstNumberSource.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/ConstNumberSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/ConstNumberSource.cs
index cadbbce..d179c4d 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/ConstNumberSource.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/ConstNumberSource.cs
@@ -15,20 +15,22 @@
* limitations under the License.
*/
+using Lucene.Net.Support;
+
namespace Lucene.Net.Queries.Function.ValueSources
{
- /// <summary>
- /// <code>ConstNumberSource</code> is the base class for all constant numbers
- /// </summary>
- public abstract class ConstNumberSource : ValueSource
- {
- public abstract int Int {get;}
- public abstract long Long {get;}
- public abstract float Float {get;}
- public abstract double Double {get;}
- public abstract Number Number {get;}
- public abstract bool Bool {get;}
- }
+ /// <summary>
+ /// <code>ConstNumberSource</code> is the base class for all constant numbers
+ /// </summary>
+ public abstract class ConstNumberSource : ValueSource
+ {
+ public abstract int Int { get; }
+ public abstract long Long { get; }
+ public abstract float Float { get; }
+ public abstract double Double { get; }
+ public abstract Number Number { get; }
+ public abstract bool Bool { get; }
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ba0f3c7d/src/Lucene.Net.Queries/Function/ValueSources/ConstValueSource.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/ConstValueSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/ConstValueSource.cs
index 79a751c..36ab51e 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/ConstValueSource.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/ConstValueSource.cs
@@ -15,8 +15,8 @@
* limitations under the License.
*/
using System.Collections;
+using Lucene.Net.Queries.Function.DocValues;
using org.apache.lucene.queries.function;
-using org.apache.lucene.queries.function.docvalues;
namespace Lucene.Net.Queries.Function.ValueSources
{
@@ -40,8 +40,8 @@ namespace Lucene.Net.Queries.Function.ValueSources
}
//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)
+//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 FloatDocValuesAnonymousInnerClassHelper(this, this);
}
@@ -55,7 +55,7 @@ namespace Lucene.Net.Queries.Function.ValueSources
this.outerInstance = outerInstance;
}
- public override float floatVal(int doc)
+ public override float FloatVal(int doc)
{
return outerInstance.constant;
}
@@ -63,11 +63,11 @@ namespace Lucene.Net.Queries.Function.ValueSources
{
return (int)outerInstance.constant;
}
- public override long longVal(int doc)
+ public override long LongVal(int doc)
{
return (long)outerInstance.constant;
}
- public override double doubleVal(int doc)
+ public override double DoubleVal(int doc)
{
return outerInstance.dv;
}
@@ -87,7 +87,7 @@ namespace Lucene.Net.Queries.Function.ValueSources
public override int GetHashCode()
{
- return float.floatToIntBits(constant) * 31;
+ return Number.FloatToIntBits(constant) * 31;
}
public override bool Equals(object o)
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ba0f3c7d/src/Lucene.Net.Queries/Function/ValueSources/DefFunction.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/DefFunction.cs b/src/Lucene.Net.Queries/Function/ValueSources/DefFunction.cs
index 05910e5..bbdbe2e 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/DefFunction.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/DefFunction.cs
@@ -1,6 +1,7 @@
using System.Collections;
using System.Collections.Generic;
-using org.apache.lucene.queries.function;
+using Lucene.Net.Index;
+using Lucene.Net.Util;
namespace Lucene.Net.Queries.Function.ValueSources
{
@@ -37,13 +38,8 @@ namespace Lucene.Net.Queries.Function.ValueSources
return "def";
}
-
-//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)
+ public override FunctionValues GetValues(IDictionary fcontext, AtomicReaderContext readerContext)
{
-
-
return new ValuesAnonymousInnerClassHelper(this, valsArr(sources, fcontext, readerContext));
}
@@ -59,12 +55,12 @@ namespace Lucene.Net.Queries.Function.ValueSources
internal readonly int upto;
- private FunctionValues get(int doc)
+ private FunctionValues Get(int doc)
{
for (int i = 0; i < upto; i++)
{
FunctionValues vals = valsArr[i];
- if (vals.exists(doc))
+ if (vals.Exists(doc))
{
return vals;
}
@@ -72,77 +68,68 @@ namespace Lucene.Net.Queries.Function.ValueSources
return valsArr[upto];
}
- public override sbyte byteVal(int doc)
+ public override sbyte ByteVal(int doc)
{
- return get(doc).byteVal(doc);
+ return Get(doc).ByteVal(doc);
}
- public override short shortVal(int doc)
+ public override short ShortVal(int doc)
{
- return get(doc).shortVal(doc);
+ return Get(doc).ShortVal(doc);
}
- public override float floatVal(int doc)
+ public override float FloatVal(int doc)
{
- return get(doc).floatVal(doc);
+ return Get(doc).FloatVal(doc);
}
- public override int intVal(int doc)
+ public override int IntVal(int doc)
{
- return get(doc).intVal(doc);
+ return Get(doc).IntVal(doc);
}
- public override long longVal(int doc)
+ public override long LongVal(int doc)
{
- return get(doc).longVal(doc);
+ return Get(doc).LongVal(doc);
}
- public override double doubleVal(int doc)
+ public override double DoubleVal(int doc)
{
- return get(doc).doubleVal(doc);
+ return Get(doc).DoubleVal(doc);
}
- public override string strVal(int doc)
+ public override string StrVal(int doc)
{
- return get(doc).strVal(doc);
+ return Get(doc).StrVal(doc);
}
- public override bool boolVal(int doc)
+ public override bool BoolVal(int doc)
{
- return get(doc).boolVal(doc);
+ return Get(doc).BoolVal(doc);
}
- public override bool bytesVal(int doc, BytesRef target)
+ public override bool BytesVal(int doc, BytesRef target)
{
- return get(doc).bytesVal(doc, target);
+ return Get(doc).BytesVal(doc, target);
}
- public override object objectVal(int doc)
+ public override object ObjectVal(int doc)
{
- return get(doc).objectVal(doc);
+ return Get(doc).ObjectVal(doc);
}
- public override bool exists(int doc)
+ public override bool Exists(int doc)
{
// return true if any source is exists?
foreach (FunctionValues vals in valsArr)
{
- if (vals.exists(doc))
+ if (vals.Exists(doc))
{
return true;
}
}
return false;
}
-
- public override ValueFiller ValueFiller
- {
- get
- {
- // TODO: need ValueSource.type() to determine correct type
- return base.ValueFiller;
- }
- }
}
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ba0f3c7d/src/Lucene.Net.Queries/Function/ValueSources/DivFloatFunction.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/DivFloatFunction.cs b/src/Lucene.Net.Queries/Function/ValueSources/DivFloatFunction.cs
index ff1b0b3..9510bc2 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/DivFloatFunction.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/DivFloatFunction.cs
@@ -15,32 +15,30 @@
* limitations under the License.
*/
-using org.apache.lucene.queries.function;
-
namespace Lucene.Net.Queries.Function.ValueSources
{
- /// <summary>
- /// Function to divide "a" by "b"
- /// </summary>
- public class DivFloatFunction : DualFloatFunction
- {
- /// <param name="a"> the numerator. </param>
- /// <param name="b"> the denominator. </param>
- public DivFloatFunction(ValueSource a, ValueSource b) : base(a,b)
- {
- }
-
- protected internal override string name()
- {
- return "div";
- }
+ /// <summary>
+ /// Function to divide "a" by "b"
+ /// </summary>
+ public class DivFloatFunction : DualFloatFunction
+ {
+ /// <param name="a"> the numerator. </param>
+ /// <param name="b"> the denominator. </param>
+ public DivFloatFunction(ValueSource a, ValueSource b)
+ : base(a, b)
+ {
+ }
- protected internal override float func(int doc, FunctionValues aVals, FunctionValues bVals)
- {
- return aVals.floatVal(doc) / bVals.floatVal(doc);
- }
- }
+ protected override string Name
+ {
+ get { return "div"; }
+ }
+ protected override float Func(int doc, FunctionValues aVals, FunctionValues bVals)
+ {
+ return aVals.FloatVal(doc) / bVals.FloatVal(doc);
+ }
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ba0f3c7d/src/Lucene.Net.Queries/Function/ValueSources/DocFreqValueSource.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/DocFreqValueSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/DocFreqValueSource.cs
index c9b467a..238a392 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/DocFreqValueSource.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/DocFreqValueSource.cs
@@ -16,162 +16,160 @@
*/
using System;
using System.Collections;
-using org.apache.lucene.queries.function;
-using org.apache.lucene.queries.function.docvalues;
+using Lucene.Net.Index;
+using Lucene.Net.Queries.Function.DocValues;
+using Lucene.Net.Search;
+using Lucene.Net.Util;
namespace Lucene.Net.Queries.Function.ValueSources
{
internal class ConstIntDocValues : IntDocValues
- {
- internal readonly int ival;
- internal readonly float fval;
- internal readonly double dval;
- internal readonly long lval;
- internal readonly string sval;
- internal readonly ValueSource parent;
-
- internal ConstIntDocValues(int val, ValueSource parent) : base(parent)
- {
- ival = val;
- fval = val;
- dval = val;
- lval = val;
- sval = Convert.ToString(val);
- this.parent = parent;
- }
-
- public override float floatVal(int doc)
- {
- return fval;
- }
- public override int intVal(int doc)
- {
- return ival;
- }
- public override long longVal(int doc)
- {
- return lval;
- }
- public override double doubleVal(int doc)
- {
- return dval;
- }
- public override string strVal(int doc)
- {
- return sval;
- }
- public override string ToString(int doc)
- {
- return parent.description() + '=' + sval;
- }
- }
-
- internal class ConstDoubleDocValues : DoubleDocValues
- {
- internal readonly int ival;
- internal readonly float fval;
- internal readonly double dval;
- internal readonly long lval;
- internal readonly string sval;
- internal readonly ValueSource parent;
-
- internal ConstDoubleDocValues(double val, ValueSource parent) : base(parent)
- {
- ival = (int)val;
- fval = (float)val;
- dval = val;
- lval = (long)val;
- sval = Convert.ToString(val);
- this.parent = parent;
- }
-
- public override float floatVal(int doc)
- {
- return fval;
- }
- public override int intVal(int doc)
- {
- return ival;
- }
- public override long longVal(int doc)
- {
- return lval;
- }
- public override double doubleVal(int doc)
- {
- return dval;
- }
- public override string strVal(int doc)
- {
- return sval;
- }
- public override string ToString(int doc)
- {
- return parent.description() + '=' + sval;
- }
- }
-
-
- /// <summary>
- /// <code>DocFreqValueSource</code> returns the number of documents containing the term.
- /// @lucene.internal
- /// </summary>
- public class DocFreqValueSource : ValueSource
- {
- protected internal readonly string field;
- protected internal readonly string indexedField;
- protected internal readonly string val;
- protected internal readonly BytesRef indexedBytes;
-
- public DocFreqValueSource(string field, string val, string indexedField, BytesRef indexedBytes)
- {
- this.field = field;
- this.val = val;
- this.indexedField = indexedField;
- this.indexedBytes = indexedBytes;
- }
-
- public virtual string name()
- {
- return "docfreq";
- }
-
- public override string description()
- {
- return name() + '(' + field + ',' + val + ')';
- }
-
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: @Override public org.apache.lucene.queries.function.FunctionValues getValues(java.util.Map context, org.apache.lucene.index.AtomicReaderContext readerContext) throws java.io.IOException
- public override FunctionValues getValues(IDictionary context, AtomicReaderContext readerContext)
- {
- IndexSearcher searcher = (IndexSearcher)context["searcher"];
- int docfreq = searcher.IndexReader.docFreq(new Term(indexedField, indexedBytes));
- return new ConstIntDocValues(docfreq, this);
- }
-
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: @Override public void createWeight(java.util.Map context, org.apache.lucene.search.IndexSearcher searcher) throws java.io.IOException
- public override void createWeight(IDictionary context, IndexSearcher searcher)
- {
- context["searcher"] = searcher;
- }
-
- public override int GetHashCode()
- {
- return this.GetType().GetHashCode() + indexedField.GetHashCode() * 29 + indexedBytes.GetHashCode();
- }
-
- public override bool Equals(object o)
- {
- if (this.GetType() != o.GetType())
- {
- return false;
- }
- DocFreqValueSource other = (DocFreqValueSource)o;
- return this.indexedField.Equals(other.indexedField) && this.indexedBytes.Equals(other.indexedBytes);
- }
- }
-
-
+ {
+ internal readonly int ival;
+ internal readonly float fval;
+ internal readonly double dval;
+ internal readonly long lval;
+ internal readonly string sval;
+ internal readonly ValueSource parent;
+
+ internal ConstIntDocValues(int val, ValueSource parent)
+ : base(parent)
+ {
+ ival = val;
+ fval = val;
+ dval = val;
+ lval = val;
+ sval = Convert.ToString(val);
+ this.parent = parent;
+ }
+
+ public override float FloatVal(int doc)
+ {
+ return fval;
+ }
+ public override int IntVal(int doc)
+ {
+ return ival;
+ }
+ public override long LongVal(int doc)
+ {
+ return lval;
+ }
+ public override double DoubleVal(int doc)
+ {
+ return dval;
+ }
+ public override string StrVal(int doc)
+ {
+ return sval;
+ }
+ public override string ToString(int doc)
+ {
+ return parent.Description + '=' + sval;
+ }
+ }
+
+ internal class ConstDoubleDocValues : DoubleDocValues
+ {
+ internal readonly int ival;
+ internal readonly float fval;
+ internal readonly double dval;
+ internal readonly long lval;
+ internal readonly string sval;
+ internal readonly ValueSource parent;
+
+ internal ConstDoubleDocValues(double val, ValueSource parent)
+ : base(parent)
+ {
+ ival = (int)val;
+ fval = (float)val;
+ dval = val;
+ lval = (long)val;
+ sval = Convert.ToString(val);
+ this.parent = parent;
+ }
+
+ public override float FloatVal(int doc)
+ {
+ return fval;
+ }
+ public override int IntVal(int doc)
+ {
+ return ival;
+ }
+ public override long LongVal(int doc)
+ {
+ return lval;
+ }
+ public override double DoubleVal(int doc)
+ {
+ return dval;
+ }
+ public override string StrVal(int doc)
+ {
+ return sval;
+ }
+ public override string ToString(int doc)
+ {
+ return parent.Description + '=' + sval;
+ }
+ }
+
+
+ /// <summary>
+ /// <code>DocFreqValueSource</code> returns the number of documents containing the term.
+ /// @lucene.internal
+ /// </summary>
+ public class DocFreqValueSource : ValueSource
+ {
+ protected internal readonly string field;
+ protected internal readonly string indexedField;
+ protected internal readonly string val;
+ protected internal readonly BytesRef indexedBytes;
+
+ public DocFreqValueSource(string field, string val, string indexedField, BytesRef indexedBytes)
+ {
+ this.field = field;
+ this.val = val;
+ this.indexedField = indexedField;
+ this.indexedBytes = indexedBytes;
+ }
+
+ public virtual string Name
+ {
+ get { return "docfreq"; }
+ }
+
+ public override string Description
+ {
+ get { return Name + '(' + field + ',' + val + ')'; }
+ }
+
+ public override FunctionValues GetValues(IDictionary context, AtomicReaderContext readerContext)
+ {
+ var searcher = (IndexSearcher)context["searcher"];
+ int docfreq = searcher.IndexReader.DocFreq(new Term(indexedField, indexedBytes));
+ return new ConstIntDocValues(docfreq, this);
+ }
+
+ public override void CreateWeight(IDictionary context, IndexSearcher searcher)
+ {
+ context["searcher"] = searcher;
+ }
+
+ public override int GetHashCode()
+ {
+ return this.GetType().GetHashCode() + indexedField.GetHashCode() * 29 + indexedBytes.GetHashCode();
+ }
+
+ public override bool Equals(object o)
+ {
+ if (this.GetType() != o.GetType())
+ {
+ return false;
+ }
+ var other = (DocFreqValueSource)o;
+ return this.indexedField.Equals(other.indexedField) && this.indexedBytes.Equals(other.indexedBytes);
+ }
+ }
}
\ No newline at end of file