You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by ni...@apache.org on 2020/06/03 19:46:45 UTC
[lucenenet] 01/02: Lucene.Net.Queries.Function: Created anonymous
classes for ValueSourceScorer and ValueFiller,
and factored out hand-coded anonymous classes
This is an automated email from the ASF dual-hosted git repository.
nightowl888 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucenenet.git
commit ce47503de25f48364f7357e2b57660229954cbc6
Author: Shad Storhaug <sh...@shadstorhaug.com>
AuthorDate: Wed Jun 3 00:57:29 2020 +0700
Lucene.Net.Queries.Function: Created anonymous classes for ValueSourceScorer and ValueFiller, and factored out hand-coded anonymous classes
---
.../Function/DocValues/BoolDocValues.cs | 31 +---
.../Function/DocValues/DocTermsIndexDocValues.cs | 66 ++-------
.../Function/DocValues/DoubleDocValues.cs | 144 +++---------------
.../Function/DocValues/FloatDocValues.cs | 31 +---
.../Function/DocValues/IntDocValues.cs | 55 +------
.../Function/DocValues/LongDocValues.cs | 55 +------
.../Function/DocValues/StrDocValues.cs | 29 +---
src/Lucene.Net.Queries/Function/FunctionValues.cs | 165 ++++++---------------
.../Function/ValueSourceScorer.cs | 39 +++--
.../Function/ValueSources/DoubleFieldSource.cs | 31 +---
.../Function/ValueSources/EnumFieldSource.cs | 55 +------
.../Function/ValueSources/FloatFieldSource.cs | 31 +---
.../Function/ValueSources/IntFieldSource.cs | 31 +---
.../Function/ValueSources/LongFieldSource.cs | 31 +---
.../Function/ValueSources/OrdFieldSource.cs | 31 +---
.../Function/ValueSources/QueryValueSource.cs | 63 +++-----
16 files changed, 178 insertions(+), 710 deletions(-)
diff --git a/src/Lucene.Net.Queries/Function/DocValues/BoolDocValues.cs b/src/Lucene.Net.Queries/Function/DocValues/BoolDocValues.cs
index 233d55e..182d460 100644
--- a/src/Lucene.Net.Queries/Function/DocValues/BoolDocValues.cs
+++ b/src/Lucene.Net.Queries/Function/DocValues/BoolDocValues.cs
@@ -94,34 +94,11 @@ namespace Lucene.Net.Queries.Function.DocValues
public override ValueFiller GetValueFiller()
{
- return new ValueFillerAnonymousInnerClassHelper(this);
- }
-
- private class ValueFillerAnonymousInnerClassHelper : ValueFiller
- {
- private readonly BoolDocValues outerInstance;
-
- public ValueFillerAnonymousInnerClassHelper(BoolDocValues outerInstance)
- {
- this.outerInstance = outerInstance;
- mval = new MutableValueBool();
- }
-
- private readonly MutableValueBool mval;
-
- public override MutableValue Value
- {
- get
- {
- return mval;
- }
- }
-
- public override void FillValue(int doc)
+ return new ValueFiller.AnonymousValueFiller<MutableValueBool>(new MutableValueBool(), fillValue: (doc, mutableValue) =>
{
- mval.Value = outerInstance.BoolVal(doc);
- mval.Exists = outerInstance.Exists(doc);
- }
+ mutableValue.Value = BoolVal(doc);
+ mutableValue.Exists = Exists(doc);
+ });
}
}
}
\ No newline at end of file
diff --git a/src/Lucene.Net.Queries/Function/DocValues/DocTermsIndexDocValues.cs b/src/Lucene.Net.Queries/Function/DocValues/DocTermsIndexDocValues.cs
index 6fbcc1c..dc8020f 100644
--- a/src/Lucene.Net.Queries/Function/DocValues/DocTermsIndexDocValues.cs
+++ b/src/Lucene.Net.Queries/Function/DocValues/DocTermsIndexDocValues.cs
@@ -128,30 +128,11 @@ namespace Lucene.Net.Queries.Function.DocValues
int ll = lower;
int uu = upper;
- return new ValueSourceScorerAnonymousInnerClassHelper(this, reader, this, ll, uu);
- }
-
- private class ValueSourceScorerAnonymousInnerClassHelper : ValueSourceScorer
- {
- private readonly DocTermsIndexDocValues outerInstance;
-
- private int ll;
- private int uu;
-
- public ValueSourceScorerAnonymousInnerClassHelper(DocTermsIndexDocValues outerInstance, IndexReader reader,
- DocTermsIndexDocValues @this, int ll, int uu)
- : base(reader, @this)
- {
- this.outerInstance = outerInstance;
- this.ll = ll;
- this.uu = uu;
- }
-
- public override bool MatchesValue(int doc)
+ return new ValueSourceScorer.AnonymousValueSourceScorer(reader, this, matchesValue: (doc) =>
{
- int ord = outerInstance.m_termsIndex.GetOrd(doc);
+ int ord = m_termsIndex.GetOrd(doc);
return ord >= ll && ord <= uu;
- }
+ });
}
public override string ToString(int doc)
@@ -161,45 +142,22 @@ namespace Lucene.Net.Queries.Function.DocValues
public override ValueFiller GetValueFiller()
{
- return new ValueFillerAnonymousInnerClassHelper(this);
- }
-
- private class ValueFillerAnonymousInnerClassHelper : ValueFiller
- {
- private readonly DocTermsIndexDocValues outerInstance;
-
- public ValueFillerAnonymousInnerClassHelper(DocTermsIndexDocValues outerInstance)
- {
- this.outerInstance = outerInstance;
- mval = new MutableValueStr();
- }
-
- private readonly MutableValueStr mval;
-
- public override MutableValue Value
+ return new ValueFiller.AnonymousValueFiller<MutableValueStr>(new MutableValueStr(), fillValue: (doc, mutableValue) =>
{
- get
- {
- return mval;
- }
- }
-
- public override void FillValue(int doc)
- {
- int ord = outerInstance.m_termsIndex.GetOrd(doc);
+ int ord = m_termsIndex.GetOrd(doc);
if (ord == -1)
{
- mval.Value.Bytes = BytesRef.EMPTY_BYTES;
- mval.Value.Offset = 0;
- mval.Value.Length = 0;
- mval.Exists = false;
+ mutableValue.Value.Bytes = BytesRef.EMPTY_BYTES;
+ mutableValue.Value.Offset = 0;
+ mutableValue.Value.Length = 0;
+ mutableValue.Exists = false;
}
else
{
- outerInstance.m_termsIndex.LookupOrd(ord, mval.Value);
- mval.Exists = true;
+ m_termsIndex.LookupOrd(ord, mutableValue.Value);
+ mutableValue.Exists = true;
}
- }
+ });
}
/// <summary>
diff --git a/src/Lucene.Net.Queries/Function/DocValues/DoubleDocValues.cs b/src/Lucene.Net.Queries/Function/DocValues/DoubleDocValues.cs
index 3d8cc18..3ff681a 100644
--- a/src/Lucene.Net.Queries/Function/DocValues/DoubleDocValues.cs
+++ b/src/Lucene.Net.Queries/Function/DocValues/DoubleDocValues.cs
@@ -120,141 +120,45 @@ namespace Lucene.Net.Queries.Function.DocValues
double u = upper;
if (includeLower && includeUpper)
{
- return new ValueSourceScorerAnonymousInnerClassHelper(this, reader, this, l, u);
+ return new ValueSourceScorer.AnonymousValueSourceScorer(reader, this, matchesValue: (doc) =>
+ {
+ double docVal = DoubleVal(doc);
+ return docVal >= l && docVal <= u;
+ });
}
else if (includeLower && !includeUpper)
{
- return new ValueSourceScorerAnonymousInnerClassHelper2(this, reader, this, l, u);
+ return new ValueSourceScorer.AnonymousValueSourceScorer(reader, this, matchesValue: (doc) =>
+ {
+ double docVal = DoubleVal(doc);
+ return docVal >= l && docVal < u;
+ });
}
else if (!includeLower && includeUpper)
{
- return new ValueSourceScorerAnonymousInnerClassHelper3(this, reader, this, l, u);
+ return new ValueSourceScorer.AnonymousValueSourceScorer(reader, this, matchesValue: (doc) =>
+ {
+ double docVal = DoubleVal(doc);
+ return docVal > l && docVal <= u;
+ });
}
else
{
- return new ValueSourceScorerAnonymousInnerClassHelper4(this, reader, this, l, u);
- }
- }
-
- private class ValueSourceScorerAnonymousInnerClassHelper : ValueSourceScorer
- {
- private readonly DoubleDocValues outerInstance;
-
- private double l;
- private double u;
-
- public ValueSourceScorerAnonymousInnerClassHelper(DoubleDocValues outerInstance, IndexReader reader, DoubleDocValues @this, double l, double u)
- : base(reader, @this)
- {
- this.outerInstance = outerInstance;
- this.l = l;
- this.u = u;
- }
-
- public override bool MatchesValue(int doc)
- {
- double docVal = outerInstance.DoubleVal(doc);
- return docVal >= l && docVal <= u;
- }
- }
-
- private class ValueSourceScorerAnonymousInnerClassHelper2 : ValueSourceScorer
- {
- private readonly DoubleDocValues outerInstance;
-
- private double l;
- private double u;
-
- public ValueSourceScorerAnonymousInnerClassHelper2(DoubleDocValues outerInstance, IndexReader reader, DoubleDocValues @this, double l, double u)
- : base(reader, @this)
- {
- this.outerInstance = outerInstance;
- this.l = l;
- this.u = u;
- }
-
- public override bool MatchesValue(int doc)
- {
- double docVal = outerInstance.DoubleVal(doc);
- return docVal >= l && docVal < u;
- }
- }
-
- private class ValueSourceScorerAnonymousInnerClassHelper3 : ValueSourceScorer
- {
- private readonly DoubleDocValues outerInstance;
-
- private double l;
- private double u;
-
- public ValueSourceScorerAnonymousInnerClassHelper3(DoubleDocValues outerInstance, IndexReader reader, DoubleDocValues @this, double l, double u)
- : base(reader, @this)
- {
- this.outerInstance = outerInstance;
- this.l = l;
- this.u = u;
- }
-
- public override bool MatchesValue(int doc)
- {
- double docVal = outerInstance.DoubleVal(doc);
- return docVal > l && docVal <= u;
- }
- }
-
- private class ValueSourceScorerAnonymousInnerClassHelper4 : ValueSourceScorer
- {
- private readonly DoubleDocValues outerInstance;
-
- private double l;
- private double u;
-
- public ValueSourceScorerAnonymousInnerClassHelper4(DoubleDocValues outerInstance, IndexReader reader,
- DoubleDocValues @this, double l, double u)
- : base(reader, @this)
- {
- this.outerInstance = outerInstance;
- this.l = l;
- this.u = u;
- }
-
- public override bool MatchesValue(int doc)
- {
- double docVal = outerInstance.DoubleVal(doc);
- return docVal > l && docVal < u;
+ return new ValueSourceScorer.AnonymousValueSourceScorer(reader, this, matchesValue: (doc) =>
+ {
+ double docVal = DoubleVal(doc);
+ return docVal > l && docVal < u;
+ });
}
}
public override ValueFiller GetValueFiller()
{
- return new ValueFillerAnonymousInnerClassHelper(this);
- }
-
- private class ValueFillerAnonymousInnerClassHelper : ValueFiller
- {
- private readonly DoubleDocValues outerInstance;
-
- public ValueFillerAnonymousInnerClassHelper(DoubleDocValues outerInstance)
- {
- this.outerInstance = outerInstance;
- mval = new MutableValueDouble();
- }
-
- private readonly MutableValueDouble mval;
-
- public override MutableValue Value
+ return new ValueFiller.AnonymousValueFiller<MutableValueDouble>(new MutableValueDouble(), fillValue: (doc, mutableValue) =>
{
- get
- {
- return mval;
- }
- }
-
- public override void FillValue(int doc)
- {
- mval.Value = outerInstance.DoubleVal(doc);
- mval.Exists = outerInstance.Exists(doc);
- }
+ mutableValue.Value = DoubleVal(doc);
+ mutableValue.Exists = Exists(doc);
+ });
}
}
}
\ No newline at end of file
diff --git a/src/Lucene.Net.Queries/Function/DocValues/FloatDocValues.cs b/src/Lucene.Net.Queries/Function/DocValues/FloatDocValues.cs
index 85f562b..8f41e3c 100644
--- a/src/Lucene.Net.Queries/Function/DocValues/FloatDocValues.cs
+++ b/src/Lucene.Net.Queries/Function/DocValues/FloatDocValues.cs
@@ -91,34 +91,11 @@ namespace Lucene.Net.Queries.Function.DocValues
public override ValueFiller GetValueFiller()
{
- return new ValueFillerAnonymousInnerClassHelper(this);
- }
-
- private class ValueFillerAnonymousInnerClassHelper : ValueFiller
- {
- private readonly SingleDocValues outerInstance;
-
- public ValueFillerAnonymousInnerClassHelper(SingleDocValues outerInstance)
- {
- this.outerInstance = outerInstance;
- mval = new MutableValueSingle();
- }
-
- private readonly MutableValueSingle mval;
-
- public override MutableValue Value
- {
- get
- {
- return mval;
- }
- }
-
- public override void FillValue(int doc)
+ return new ValueFiller.AnonymousValueFiller<MutableValueSingle>(new MutableValueSingle(), fillValue: (doc, mutableValue) =>
{
- mval.Value = outerInstance.SingleVal(doc);
- mval.Exists = outerInstance.Exists(doc);
- }
+ mutableValue.Value = SingleVal(doc);
+ mutableValue.Exists = Exists(doc);
+ });
}
}
}
\ No newline at end of file
diff --git a/src/Lucene.Net.Queries/Function/DocValues/IntDocValues.cs b/src/Lucene.Net.Queries/Function/DocValues/IntDocValues.cs
index 6d16209..7daf3ac 100644
--- a/src/Lucene.Net.Queries/Function/DocValues/IntDocValues.cs
+++ b/src/Lucene.Net.Queries/Function/DocValues/IntDocValues.cs
@@ -125,63 +125,22 @@ namespace Lucene.Net.Queries.Function.DocValues
int ll = lower;
int uu = upper;
- return new ValueSourceScorerAnonymousInnerClassHelper(this, reader, this, ll, uu);
- }
-
- private class ValueSourceScorerAnonymousInnerClassHelper : ValueSourceScorer
- {
- private readonly Int32DocValues outerInstance;
-
- private int ll;
- private int uu;
-
- public ValueSourceScorerAnonymousInnerClassHelper(Int32DocValues outerInstance, IndexReader reader, Int32DocValues @this, int ll, int uu)
- : base(reader, @this)
- {
- this.outerInstance = outerInstance;
- this.ll = ll;
- this.uu = uu;
- }
-
- public override bool MatchesValue(int doc)
+ return new ValueSourceScorer.AnonymousValueSourceScorer(reader, this, matchesValue: (doc) =>
{
- int val = outerInstance.Int32Val(doc);
+ int val = Int32Val(doc);
// only check for deleted if it's the default value
// if (val==0 && reader.isDeleted(doc)) return false;
return val >= ll && val <= uu;
- }
+ });
}
public override ValueFiller GetValueFiller()
{
- return new ValueFillerAnonymousInnerClassHelper(this);
- }
-
- private class ValueFillerAnonymousInnerClassHelper : ValueFiller
- {
- private readonly Int32DocValues outerInstance;
-
- public ValueFillerAnonymousInnerClassHelper(Int32DocValues outerInstance)
- {
- this.outerInstance = outerInstance;
- mval = new MutableValueInt32();
- }
-
- private readonly MutableValueInt32 mval;
-
- public override MutableValue Value
+ return new ValueFiller.AnonymousValueFiller<MutableValueInt32>(new MutableValueInt32(), fillValue: (doc, mutableValue) =>
{
- get
- {
- return mval;
- }
- }
-
- public override void FillValue(int doc)
- {
- mval.Value = outerInstance.Int32Val(doc);
- mval.Exists = outerInstance.Exists(doc);
- }
+ mutableValue.Value = Int32Val(doc);
+ mutableValue.Exists = Exists(doc);
+ });
}
}
}
\ No newline at end of file
diff --git a/src/Lucene.Net.Queries/Function/DocValues/LongDocValues.cs b/src/Lucene.Net.Queries/Function/DocValues/LongDocValues.cs
index 7b68cdf..49f0a73 100644
--- a/src/Lucene.Net.Queries/Function/DocValues/LongDocValues.cs
+++ b/src/Lucene.Net.Queries/Function/DocValues/LongDocValues.cs
@@ -135,63 +135,22 @@ namespace Lucene.Net.Queries.Function.DocValues
long ll = lower;
long uu = upper;
- return new ValueSourceScorerAnonymousInnerClassHelper(this, reader, this, ll, uu);
- }
-
- private class ValueSourceScorerAnonymousInnerClassHelper : ValueSourceScorer
- {
- private readonly Int64DocValues outerInstance;
-
- private readonly long ll;
- private readonly long uu;
-
- public ValueSourceScorerAnonymousInnerClassHelper(Int64DocValues outerInstance, IndexReader reader, Int64DocValues @this, long ll, long uu)
- : base(reader, @this)
- {
- this.outerInstance = outerInstance;
- this.ll = ll;
- this.uu = uu;
- }
-
- public override bool MatchesValue(int doc)
+ return new ValueSourceScorer.AnonymousValueSourceScorer(reader, this, matchesValue: (doc) =>
{
- long val = outerInstance.Int64Val(doc);
+ long val = Int64Val(doc);
// only check for deleted if it's the default value
// if (val==0 && reader.isDeleted(doc)) return false;
return val >= ll && val <= uu;
- }
+ });
}
public override ValueFiller GetValueFiller()
{
- return new ValueFillerAnonymousInnerClassHelper(this);
- }
-
- private class ValueFillerAnonymousInnerClassHelper : ValueFiller
- {
- private readonly Int64DocValues outerInstance;
-
- public ValueFillerAnonymousInnerClassHelper(Int64DocValues outerInstance)
- {
- this.outerInstance = outerInstance;
- mval = new MutableValueInt64();
- }
-
- private readonly MutableValueInt64 mval;
-
- public override MutableValue Value
+ return new ValueFiller.AnonymousValueFiller<MutableValueInt64>(new MutableValueInt64(), fillValue: (doc, mutableValue) =>
{
- get
- {
- return mval;
- }
- }
-
- public override void FillValue(int doc)
- {
- mval.Value = outerInstance.Int64Val(doc);
- mval.Exists = outerInstance.Exists(doc);
- }
+ mutableValue.Value = Int64Val(doc);
+ mutableValue.Exists = Exists(doc);
+ });
}
}
}
\ No newline at end of file
diff --git a/src/Lucene.Net.Queries/Function/DocValues/StrDocValues.cs b/src/Lucene.Net.Queries/Function/DocValues/StrDocValues.cs
index e8a52b1..84b4e64 100644
--- a/src/Lucene.Net.Queries/Function/DocValues/StrDocValues.cs
+++ b/src/Lucene.Net.Queries/Function/DocValues/StrDocValues.cs
@@ -51,33 +51,10 @@ namespace Lucene.Net.Queries.Function.DocValues
public override ValueFiller GetValueFiller()
{
- return new ValueFillerAnonymousInnerClassHelper(this);
- }
-
- private class ValueFillerAnonymousInnerClassHelper : ValueFiller
- {
- private readonly StrDocValues outerInstance;
-
- public ValueFillerAnonymousInnerClassHelper(StrDocValues outerInstance)
- {
- this.outerInstance = outerInstance;
- mval = new MutableValueStr();
- }
-
- private readonly MutableValueStr mval;
-
- public override MutableValue Value
- {
- get
- {
- return mval;
- }
- }
-
- public override void FillValue(int doc)
+ return new ValueFiller.AnonymousValueFiller<MutableValueStr>(new MutableValueStr(), fillValue: (doc, mutableValue) =>
{
- mval.Exists = outerInstance.BytesVal(doc, mval.Value);
- }
+ mutableValue.Exists = BytesVal(doc, mutableValue.Value);
+ });
}
}
}
\ No newline at end of file
diff --git a/src/Lucene.Net.Queries/Function/FunctionValues.cs b/src/Lucene.Net.Queries/Function/FunctionValues.cs
index 76273b5..bbcc976 100644
--- a/src/Lucene.Net.Queries/Function/FunctionValues.cs
+++ b/src/Lucene.Net.Queries/Function/FunctionValues.cs
@@ -151,36 +151,39 @@ namespace Lucene.Net.Queries.Function
/// <summary>
/// <see cref="MutableValue"/> will be reused across calls. Returns <c>true</c> if the value exists. </summary>
public abstract void FillValue(int doc);
- }
-
- /// <summary>
- /// @lucene.experimental </summary>
- public virtual ValueFiller GetValueFiller()
- {
- return new ValueFillerAnonymousInnerClassHelper(this);
- }
- private class ValueFillerAnonymousInnerClassHelper : ValueFiller
- {
- private readonly FunctionValues outerInstance;
-
- public ValueFillerAnonymousInnerClassHelper(FunctionValues outerInstance)
+ /// <summary>
+ /// This class may be used to create <see cref="ValueFiller"/> instances anonymously.
+ /// </summary>
+ // LUCENENET specific - used to mimick the inline class behavior in Java.
+ internal class AnonymousValueFiller<T> : ValueFiller where T : MutableValue
{
- this.outerInstance = outerInstance;
- mval = new MutableValueSingle();
- }
+ private readonly T mutableValue;
+ private readonly Action<int, T> fillValue;
- private readonly MutableValueSingle mval;
+ public AnonymousValueFiller(T mutableValue, Action<int, T> fillValue)
+ {
+ this.mutableValue = mutableValue ?? throw new ArgumentNullException(nameof(mutableValue));
+ this.fillValue = fillValue ?? throw new ArgumentNullException(nameof(fillValue));
+ }
- public override MutableValue Value
- {
- get { return mval; }
+ public override MutableValue Value => mutableValue;
+
+ public override void FillValue(int doc)
+ {
+ fillValue(doc, mutableValue);
+ }
}
+ }
- public override void FillValue(int doc)
+ /// <summary>
+ /// @lucene.experimental </summary>
+ public virtual ValueFiller GetValueFiller()
+ {
+ return new ValueFiller.AnonymousValueFiller<MutableValueSingle>(new MutableValueSingle(), fillValue: (doc, mutableValue) =>
{
- mval.Value = outerInstance.SingleVal(doc);
- }
+ mutableValue.Value = SingleVal(doc);
+ });
}
//For Functions that can work with multiple values from the same document. This does not apply to all functions
@@ -274,111 +277,35 @@ namespace Lucene.Net.Queries.Function
if (includeLower && includeUpper)
{
- return new ValueSourceScorerAnonymousInnerClassHelper(this, reader, this, l, u);
+ return new ValueSourceScorer.AnonymousValueSourceScorer(reader, this, matchesValue: (doc) =>
+ {
+ float docVal = SingleVal(doc);
+ return docVal >= l && docVal <= u;
+ });
}
else if (includeLower && !includeUpper)
{
- return new ValueSourceScorerAnonymousInnerClassHelper2(this, reader, this, l, u);
+ return new ValueSourceScorer.AnonymousValueSourceScorer(reader, this, matchesValue: (doc) =>
+ {
+ float docVal = SingleVal(doc);
+ return docVal >= l && docVal < u;
+ });
}
else if (!includeLower && includeUpper)
{
- return new ValueSourceScorerAnonymousInnerClassHelper3(this, reader, this, l, u);
+ return new ValueSourceScorer.AnonymousValueSourceScorer(reader, this, matchesValue: (doc) =>
+ {
+ float docVal = SingleVal(doc);
+ return docVal > l && docVal <= u;
+ });
}
else
{
- return new ValueSourceScorerAnonymousInnerClassHelper4(this, reader, this, l, u);
- }
- }
-
- private class ValueSourceScorerAnonymousInnerClassHelper : ValueSourceScorer
- {
- private readonly FunctionValues outerInstance;
-
- private readonly float l;
- private readonly 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.SingleVal(doc);
- return docVal >= l && docVal <= u;
- }
- }
-
- private class ValueSourceScorerAnonymousInnerClassHelper2 : ValueSourceScorer
- {
- private readonly FunctionValues outerInstance;
-
- private readonly float l;
- private readonly 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.SingleVal(doc);
- return docVal >= l && docVal < u;
- }
- }
-
- private class ValueSourceScorerAnonymousInnerClassHelper3 : ValueSourceScorer
- {
- private readonly FunctionValues outerInstance;
-
- private readonly float l;
- private readonly 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.SingleVal(doc);
- return docVal > l && docVal <= u;
- }
- }
-
- private class ValueSourceScorerAnonymousInnerClassHelper4 : ValueSourceScorer
- {
- private readonly FunctionValues outerInstance;
-
- private readonly float l;
- private readonly 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.SingleVal(doc);
- return docVal > l && docVal < u;
+ return new ValueSourceScorer.AnonymousValueSourceScorer(reader, this, matchesValue: (doc) =>
+ {
+ float docVal = SingleVal(doc);
+ return docVal > l && docVal < u;
+ });
}
}
}
diff --git a/src/Lucene.Net.Queries/Function/ValueSourceScorer.cs b/src/Lucene.Net.Queries/Function/ValueSourceScorer.cs
index 1702ecf..24cdbba 100644
--- a/src/Lucene.Net.Queries/Function/ValueSourceScorer.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSourceScorer.cs
@@ -1,6 +1,7 @@
using Lucene.Net.Index;
using Lucene.Net.Search;
using Lucene.Net.Util;
+using System;
namespace Lucene.Net.Queries.Function
{
@@ -44,13 +45,7 @@ namespace Lucene.Net.Queries.Function
this.liveDocs = MultiFields.GetLiveDocs(reader);
}
- public virtual IndexReader Reader
- {
- get
- {
- return m_reader;
- }
- }
+ public virtual IndexReader Reader => m_reader;
public virtual void SetCheckDeletes(bool checkDeletes)
{
@@ -67,10 +62,7 @@ namespace Lucene.Net.Queries.Function
return true;
}
- public override int DocID
- {
- get { return doc; }
- }
+ public override int DocID => doc;
public override int NextDoc()
{
@@ -100,14 +92,31 @@ namespace Lucene.Net.Queries.Function
return m_values.SingleVal(doc);
}
- public override int Freq
- {
- get { return 1; }
- }
+ public override int Freq => 1;
public override long GetCost()
{
return m_maxDoc;
}
+
+ /// <summary>
+ /// This class may be used to create <see cref="ValueSourceScorer"/> instances anonymously.
+ /// </summary>
+ // LUCENENET specific - used to mimick the inline class behavior in Java.
+ internal class AnonymousValueSourceScorer : ValueSourceScorer
+ {
+ private readonly Func<int, bool> matchesValue;
+
+ public AnonymousValueSourceScorer(IndexReader reader, FunctionValues functionValues, Func<int, bool> matchesValue)
+ : base(reader, functionValues)
+ {
+ this.matchesValue = matchesValue ?? throw new ArgumentNullException(nameof(matchesValue));
+ }
+
+ public override bool MatchesValue(int doc)
+ {
+ return matchesValue == null ? base.MatchesValue(doc) : matchesValue(doc);
+ }
+ }
}
}
\ No newline at end of file
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/DoubleFieldSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/DoubleFieldSource.cs
index 3534f1f..d2aab2a 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/DoubleFieldSource.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/DoubleFieldSource.cs
@@ -79,34 +79,11 @@ namespace Lucene.Net.Queries.Function.ValueSources
public override ValueFiller GetValueFiller()
{
- return new ValueFillerAnonymousInnerClassHelper(this);
- }
-
- private class ValueFillerAnonymousInnerClassHelper : ValueFiller
- {
- private readonly DoubleDocValuesAnonymousInnerClassHelper outerInstance;
-
- public ValueFillerAnonymousInnerClassHelper(DoubleDocValuesAnonymousInnerClassHelper outerInstance)
- {
- this.outerInstance = outerInstance;
- mval = new MutableValueDouble();
- }
-
- private readonly MutableValueDouble mval;
-
- public override MutableValue Value
- {
- get
- {
- return mval;
- }
- }
-
- public override void FillValue(int doc)
+ return new ValueFiller.AnonymousValueFiller<MutableValueDouble>(new MutableValueDouble(), fillValue: (doc, mutableValue) =>
{
- mval.Value = outerInstance.arr.Get(doc);
- mval.Exists = mval.Value != 0 || outerInstance.valid.Get(doc);
- }
+ mutableValue.Value = arr.Get(doc);
+ mutableValue.Exists = mutableValue.Value != 0 || valid.Get(doc);
+ });
}
}
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/EnumFieldSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/EnumFieldSource.cs
index 140e458..34ef599 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/EnumFieldSource.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/EnumFieldSource.cs
@@ -226,63 +226,22 @@ namespace Lucene.Net.Queries.Function.ValueSources
int ll = lower.Value;
int uu = upper.Value;
- return new ValueSourceScorerAnonymousInnerClassHelper(this, reader, outerInstance, ll, uu);
- }
-
- private class ValueSourceScorerAnonymousInnerClassHelper : ValueSourceScorer
- {
- private readonly Int32DocValuesAnonymousInnerClassHelper outerInstance;
-
- private readonly int ll;
- private readonly int uu;
-
- public ValueSourceScorerAnonymousInnerClassHelper(Int32DocValuesAnonymousInnerClassHelper outerInstance, IndexReader reader, EnumFieldSource @this, int ll, int uu)
- : base(reader, outerInstance)
- {
- this.outerInstance = outerInstance;
- this.ll = ll;
- this.uu = uu;
- }
-
- public override bool MatchesValue(int doc)
+ return new ValueSourceScorer.AnonymousValueSourceScorer(reader, this, matchesValue: (doc) =>
{
- int val = outerInstance.arr.Get(doc);
+ int val = arr.Get(doc);
// only check for deleted if it's the default value
// if (val==0 && reader.isDeleted(doc)) return false;
return val >= ll && val <= uu;
- }
+ });
}
public override ValueFiller GetValueFiller()
{
- return new ValueFillerAnonymousInnerClassHelper(this);
- }
-
- private class ValueFillerAnonymousInnerClassHelper : ValueFiller
- {
- private readonly Int32DocValuesAnonymousInnerClassHelper outerInstance;
-
- public ValueFillerAnonymousInnerClassHelper(Int32DocValuesAnonymousInnerClassHelper outerInstance)
- {
- this.outerInstance = outerInstance;
- mval = new MutableValueInt32();
- }
-
- private readonly MutableValueInt32 mval;
-
- public override MutableValue Value
+ return new ValueFiller.AnonymousValueFiller<MutableValueInt32>(new MutableValueInt32(), fillValue: (doc, mutableValue) =>
{
- get
- {
- return mval;
- }
- }
-
- public override void FillValue(int doc)
- {
- mval.Value = outerInstance.arr.Get(doc);
- mval.Exists = outerInstance.valid.Get(doc);
- }
+ mutableValue.Value = arr.Get(doc);
+ mutableValue.Exists = valid.Get(doc);
+ });
}
}
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/FloatFieldSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/FloatFieldSource.cs
index 6f90cf6..9b38337 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/FloatFieldSource.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/FloatFieldSource.cs
@@ -89,34 +89,11 @@ namespace Lucene.Net.Queries.Function.ValueSources
public override ValueFiller GetValueFiller()
{
- return new ValueFillerAnonymousInnerClassHelper(this);
- }
-
- private class ValueFillerAnonymousInnerClassHelper : ValueFiller
- {
- private readonly SingleDocValuesAnonymousInnerClassHelper outerInstance;
-
- public ValueFillerAnonymousInnerClassHelper(SingleDocValuesAnonymousInnerClassHelper outerInstance)
- {
- this.outerInstance = outerInstance;
- mval = new MutableValueSingle();
- }
-
- private readonly MutableValueSingle mval;
-
- public override MutableValue Value
- {
- get
- {
- return mval;
- }
- }
-
- public override void FillValue(int doc)
+ return new ValueFiller.AnonymousValueFiller<MutableValueSingle>(new MutableValueSingle(), fillValue: (doc, mutableValue) =>
{
- mval.Value = outerInstance.arr.Get(doc);
- mval.Exists = mval.Value != 0 || outerInstance.valid.Get(doc);
- }
+ mutableValue.Value = arr.Get(doc);
+ mutableValue.Exists = mutableValue.Value != 0 || valid.Get(doc);
+ });
}
}
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/IntFieldSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/IntFieldSource.cs
index 8eddd02..3771852 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/IntFieldSource.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/IntFieldSource.cs
@@ -128,34 +128,11 @@ namespace Lucene.Net.Queries.Function.ValueSources
public override ValueFiller GetValueFiller()
{
- return new ValueFillerAnonymousInnerClassHelper(this);
- }
-
- private class ValueFillerAnonymousInnerClassHelper : ValueFiller
- {
- private readonly Int32DocValuesAnonymousInnerClassHelper outerInstance;
-
- public ValueFillerAnonymousInnerClassHelper(Int32DocValuesAnonymousInnerClassHelper outerInstance)
- {
- this.outerInstance = outerInstance;
- mval = new MutableValueInt32();
- }
-
- private readonly MutableValueInt32 mval;
-
- public override MutableValue Value
- {
- get
- {
- return mval;
- }
- }
-
- public override void FillValue(int doc)
+ return new ValueFiller.AnonymousValueFiller<MutableValueInt32>(new MutableValueInt32(), fillValue: (doc, mutableValue) =>
{
- mval.Value = outerInstance.arr.Get(doc);
- mval.Exists = mval.Value != 0 || outerInstance.valid.Get(doc);
- }
+ mutableValue.Value = arr.Get(doc);
+ mutableValue.Exists = mutableValue.Value != 0 || valid.Get(doc);
+ });
}
}
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/LongFieldSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/LongFieldSource.cs
index 4d7cbe9..bb93595 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/LongFieldSource.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/LongFieldSource.cs
@@ -130,34 +130,11 @@ namespace Lucene.Net.Queries.Function.ValueSources
public override ValueFiller GetValueFiller()
{
- return new ValueFillerAnonymousInnerClassHelper(this);
- }
-
- private class ValueFillerAnonymousInnerClassHelper : ValueFiller
- {
- private readonly Int64DocValuesAnonymousInnerClassHelper outerInstance;
-
- public ValueFillerAnonymousInnerClassHelper(Int64DocValuesAnonymousInnerClassHelper outerInstance)
- {
- this.outerInstance = outerInstance;
- mval = outerInstance.outerInstance.NewMutableValueInt64();
- }
-
- private readonly MutableValueInt64 mval;
-
- public override MutableValue Value
- {
- get
- {
- return mval;
- }
- }
-
- public override void FillValue(int doc)
+ return new ValueFiller.AnonymousValueFiller<MutableValueInt64>(outerInstance.NewMutableValueInt64(), fillValue: (doc, mutableValue) =>
{
- mval.Value = outerInstance.arr.Get(doc);
- mval.Exists = mval.Value != 0 || outerInstance.valid.Get(doc);
- }
+ mutableValue.Value = arr.Get(doc);
+ mutableValue.Exists = mutableValue.Value != 0 || valid.Get(doc);
+ });
}
}
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/OrdFieldSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/OrdFieldSource.cs
index c8a0c09..43d3ba8 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/OrdFieldSource.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/OrdFieldSource.cs
@@ -112,34 +112,11 @@ namespace Lucene.Net.Queries.Function.ValueSources
public override ValueFiller GetValueFiller()
{
- return new ValueFillerAnonymousInnerClassHelper(this);
- }
-
- private class ValueFillerAnonymousInnerClassHelper : ValueFiller
- {
- private readonly Int32DocValuesAnonymousInnerClassHelper outerInstance;
-
- public ValueFillerAnonymousInnerClassHelper(Int32DocValuesAnonymousInnerClassHelper outerInstance)
- {
- this.outerInstance = outerInstance;
- mval = new MutableValueInt32();
- }
-
- private readonly MutableValueInt32 mval;
-
- public override MutableValue Value
- {
- get
- {
- return mval;
- }
- }
-
- public override void FillValue(int doc)
+ return new ValueFiller.AnonymousValueFiller<MutableValueInt32>(new MutableValueInt32(), fillValue: (doc, mutableValue) =>
{
- mval.Value = outerInstance.sindex.GetOrd(doc);
- mval.Exists = mval.Value != 0;
- }
+ mutableValue.Value = sindex.GetOrd(doc);
+ mutableValue.Exists = mutableValue.Value != 0;
+ });
}
}
diff --git a/src/Lucene.Net.Queries/Function/ValueSources/QueryValueSource.cs b/src/Lucene.Net.Queries/Function/ValueSources/QueryValueSource.cs
index c321dc2..0eb0364 100644
--- a/src/Lucene.Net.Queries/Function/ValueSources/QueryValueSource.cs
+++ b/src/Lucene.Net.Queries/Function/ValueSources/QueryValueSource.cs
@@ -243,73 +243,50 @@ namespace Lucene.Net.Queries.Function.ValueSources
// the FunctionValues, then members like "scorer" should be per ValueFiller instance.
// Or we can say that the user should just instantiate multiple FunctionValues.
//
- return new ValueFillerAnonymousInnerClassHelper(this);
- }
-
- private class ValueFillerAnonymousInnerClassHelper : ValueFiller
- {
- private readonly QueryDocValues outerInstance;
-
- public ValueFillerAnonymousInnerClassHelper(QueryDocValues outerInstance)
- {
- this.outerInstance = outerInstance;
- mval = new MutableValueSingle();
- }
-
- private readonly MutableValueSingle mval;
-
- public override MutableValue Value
- {
- get
- {
- return mval;
- }
- }
-
- public override void FillValue(int doc)
+ return new ValueFiller.AnonymousValueFiller<MutableValueSingle>(new MutableValueSingle(), fillValue: (doc, mutableValue) =>
{
try
{
- if (outerInstance.noMatches)
+ if (noMatches)
{
- mval.Value = outerInstance.defVal;
- mval.Exists = false;
+ mutableValue.Value = defVal;
+ mutableValue.Exists = false;
return;
}
- outerInstance.scorer = outerInstance.weight.GetScorer(outerInstance.readerContext, outerInstance.acceptDocs);
- outerInstance.scorerDoc = -1;
- if (outerInstance.scorer == null)
+ scorer = weight.GetScorer(readerContext, acceptDocs);
+ scorerDoc = -1;
+ if (scorer == null)
{
- outerInstance.noMatches = true;
- mval.Value = outerInstance.defVal;
- mval.Exists = false;
+ noMatches = true;
+ mutableValue.Value = defVal;
+ mutableValue.Exists = false;
return;
}
- outerInstance.lastDocRequested = doc;
+ lastDocRequested = doc;
- if (outerInstance.scorerDoc < doc)
+ if (scorerDoc < doc)
{
- outerInstance.scorerDoc = outerInstance.scorer.Advance(doc);
+ scorerDoc = scorer.Advance(doc);
}
- if (outerInstance.scorerDoc > doc)
+ if (scorerDoc > doc)
{
// query doesn't match this document... either because we hit the
// end, or because the next doc is after this doc.
- mval.Value = outerInstance.defVal;
- mval.Exists = false;
+ mutableValue.Value = defVal;
+ mutableValue.Exists = false;
return;
}
// a match!
- mval.Value = outerInstance.scorer.GetScore();
- mval.Exists = true;
+ mutableValue.Value = scorer.GetScore();
+ mutableValue.Exists = true;
}
catch (IOException e)
{
- throw new Exception("caught exception in QueryDocVals(" + outerInstance.q + ") doc=" + doc, e);
+ throw new Exception("caught exception in QueryDocVals(" + q + ") doc=" + doc, e);
}
- }
+ });
}
public override string ToString(int doc)