21 using Term = Lucene.Net.Index.Term;
26 namespace Lucene.Net.Search
38 private class TermWeight:
Weight
40 private void InitBlock(
TermQuery enclosingInstance)
42 this.enclosingInstance = enclosingInstance;
49 return enclosingInstance;
54 private float value_Renamed;
56 private float queryNorm;
57 private float queryWeight;
62 InitBlock(enclosingInstance);
63 this.similarity = Enclosing_Instance.GetSimilarity(searcher);
64 idfExp = similarity.IdfExplain(Enclosing_Instance.term, searcher);
68 public override System.String ToString()
70 return "weight(" + Enclosing_Instance +
")";
75 get {
return Enclosing_Instance; }
78 public override float Value
80 get {
return value_Renamed; }
83 public override float GetSumOfSquaredWeights()
85 queryWeight = idf*Enclosing_Instance.
Boost;
86 return queryWeight*queryWeight;
89 public override void Normalize(
float queryNorm)
91 this.queryNorm = queryNorm;
92 queryWeight *= queryNorm;
93 value_Renamed = queryWeight * idf;
98 TermDocs termDocs = reader.TermDocs(Enclosing_Instance.term);
100 if (termDocs == null)
103 return new TermScorer(
this, termDocs, similarity, reader.Norms(Enclosing_Instance.term.Field));
116 queryExpl.Description =
"queryWeight(" +
Query +
"), product of:";
119 if (Enclosing_Instance.Boost != 1.0f)
120 queryExpl.AddDetail(boostExpl);
121 queryExpl.AddDetail(expl);
124 queryExpl.AddDetail(queryNormExpl);
131 System.String field = Enclosing_Instance.term.Field;
133 fieldExpl.
Description =
"fieldWeight(" + Enclosing_Instance.term +
" in " + doc +
"), product of:";
137 TermDocs termDocs = reader.TermDocs(enclosingInstance.term);
138 if (termDocs != null)
142 if (termDocs.SkipTo(doc) && termDocs.Doc == doc)
151 tfExplanation.
Value = similarity.Tf(tf);
152 tfExplanation.
Description =
"tf(termFreq(" + enclosingInstance.term +
")=" + tf +
")";
156 tfExplanation.
Value = 0.0f;
163 byte[] fieldNorms = reader.Norms(field);
165 fieldNormExpl.
Value = fieldNorm;
166 fieldNormExpl.
Description =
"fieldNorm(field=" + field +
", doc=" + doc +
")";
173 System.Boolean? tempAux = fieldExpl.
Match;
174 result.
Match = tempAux;
177 result.
Value = queryExpl.Value * fieldExpl.
Value;
179 if (queryExpl.Value == 1.0f)
200 return new TermWeight(
this, searcher);
203 public override void ExtractTerms(System.Collections.Generic.ISet<
Term> terms)
209 public override System.String ToString(System.String field)
211 System.Text.StringBuilder buffer =
new System.Text.StringBuilder();
212 if (!term.Field.Equals(field))
214 buffer.Append(term.Field);
217 buffer.Append(term.Text);
219 return buffer.ToString();
223 public override bool Equals(System.Object o)
228 return (this.Boost == other.
Boost) && this.term.Equals(other.term);
232 public override int GetHashCode()
234 return BitConverter.ToInt32(BitConverter.GetBytes(Boost), 0) ^ term.GetHashCode();