19 using Lucene.Net.Index;
23 using Lucene.Net.Search;
25 namespace Lucene.Net.Search.Function
63 public override void ExtractTerms(System.Collections.Generic.ISet<
Term> terms)
69 internal class ValueSourceWeight:
Weight
73 this.enclosingInstance = enclosingInstance;
75 private ValueSourceQuery enclosingInstance;
76 public ValueSourceQuery Enclosing_Instance
80 return enclosingInstance;
85 internal float queryNorm;
86 internal float queryWeight;
88 public ValueSourceWeight(ValueSourceQuery enclosingInstance,
Searcher searcher)
90 InitBlock(enclosingInstance);
91 this.similarity = Enclosing_Instance.GetSimilarity(searcher);
98 get {
return Enclosing_Instance; }
103 public override float Value
105 get {
return queryWeight; }
110 public override float GetSumOfSquaredWeights()
112 queryWeight = Enclosing_Instance.
Boost;
113 return queryWeight*queryWeight;
117 public override void Normalize(
float norm)
119 this.queryNorm = norm;
120 queryWeight *= this.queryNorm;
125 return new ValueSourceScorer(enclosingInstance, similarity, reader,
this);
131 DocValues vals = enclosingInstance.valSrc.GetValues(reader);
132 float sc = queryWeight*vals.FloatVal(doc);
148 private class ValueSourceScorer :
Scorer
150 private void InitBlock(ValueSourceQuery enclosingInstance)
152 this.enclosingInstance = enclosingInstance;
154 private ValueSourceQuery enclosingInstance;
155 public ValueSourceQuery Enclosing_Instance
159 return enclosingInstance;
163 private ValueSourceWeight weight;
164 private float qWeight;
165 private DocValues vals;
167 private int doc = -1;
170 internal ValueSourceScorer(ValueSourceQuery enclosingInstance,
Similarity similarity,
IndexReader reader, ValueSourceWeight w)
173 InitBlock(enclosingInstance);
175 this.qWeight = w.Value;
177 vals = Enclosing_Instance.valSrc.GetValues(reader);
181 public override int NextDoc()
183 return doc = termDocs.
Next() ? termDocs.Doc : NO_MORE_DOCS;
186 public override int DocID()
191 public override int Advance(
int target)
193 return doc = termDocs.SkipTo(target) ? termDocs.Doc : NO_MORE_DOCS;
197 public override float Score()
199 return qWeight * vals.FloatVal(termDocs.Doc);
208 public override System.String ToString(System.String field)
214 public override bool Equals(System.Object o)
216 if (GetType() != o.GetType())
221 return this.Boost == other.
Boost && this.valSrc.Equals(other.valSrc);
225 public override int GetHashCode()
227 return (GetType().GetHashCode() + valSrc.GetHashCode()) ^ BitConverter.ToInt32(BitConverter.GetBytes(Boost), 0);
230 override public System.Object Clone()
232 return this.MemberwiseClone();