21 using Term = Lucene.Net.Index.Term;
25 using Scorer = Lucene.Net.Search.Scorer;
28 using Weight = Lucene.Net.Search.Weight;
32 using TermSpans = Lucene.Net.Search.Spans.TermSpans;
34 namespace Lucene.Net.Search.Payloads
53 private bool includeSpanScore;
61 this.
function =
function;
62 this.includeSpanScore = includeSpanScore;
67 return new PayloadTermWeight(
this,
this, searcher);
71 protected internal class PayloadTermWeight:
SpanWeight
75 this.enclosingInstance = enclosingInstance;
77 private PayloadTermQuery enclosingInstance;
78 public PayloadTermQuery Enclosing_Instance
82 return enclosingInstance;
87 public PayloadTermWeight(PayloadTermQuery enclosingInstance, PayloadTermQuery query,
Searcher searcher):base(query, searcher)
89 InitBlock(enclosingInstance);
94 return new PayloadTermSpanScorer(
this, (
TermSpans) internalQuery.GetSpans(reader),
this, similarity, reader.Norms(internalQuery.Field));
97 protected internal class PayloadTermSpanScorer:
SpanScorer
99 private void InitBlock(PayloadTermWeight enclosingInstance)
101 this.enclosingInstance = enclosingInstance;
103 private PayloadTermWeight enclosingInstance;
104 public PayloadTermWeight Enclosing_Instance
108 return enclosingInstance;
113 protected internal byte[] payload =
new byte[256];
115 protected internal float payloadScore;
116 protected internal int payloadsSeen;
118 public PayloadTermSpanScorer(PayloadTermWeight enclosingInstance,
TermSpans spans,
Weight weight,
Similarity similarity, byte[] norms):base(spans, weight, similarity, norms)
120 InitBlock(enclosingInstance);
121 positions = spans.Positions;
124 public override bool SetFreqCurrentDoc()
135 while (more && doc == spans.Doc())
137 int matchLength = spans.End() - spans.Start();
139 freq += similarity1.SloppyFreq(matchLength);
140 ProcessPayload(similarity1);
145 return more || (freq != 0);
148 protected internal virtual void ProcessPayload(
Similarity similarity)
150 if (positions.IsPayloadAvailable)
152 payload = positions.GetPayload(payload, 0);
153 payloadScore = Enclosing_Instance.Enclosing_Instance.function.CurrentScore(doc, Enclosing_Instance.Enclosing_Instance.internalTerm.Field, spans.Start(), spans.End(), payloadsSeen, payloadScore, similarity.ScorePayload(doc, Enclosing_Instance.Enclosing_Instance.internalTerm.Field, spans.Start(), spans.End(), payload, 0, positions.PayloadLength));
166 public override float Score()
169 return Enclosing_Instance.Enclosing_Instance.includeSpanScore?GetSpanScore() * GetPayloadScore():GetPayloadScore();
184 [System.Diagnostics.CodeAnalysis.SuppressMessage(
"Microsoft.Design",
"CA1024:UsePropertiesWhereAppropriate")]
185 protected internal virtual float GetSpanScore()
196 [System.Diagnostics.CodeAnalysis.SuppressMessage(
"Microsoft.Design",
"CA1024:UsePropertiesWhereAppropriate")]
197 protected internal virtual float GetPayloadScore()
199 return Enclosing_Instance.Enclosing_Instance.function.DocScore(doc, Enclosing_Instance.Enclosing_Instance.internalTerm.Field, payloadsSeen, payloadScore);
202 protected internal override Explanation Explain(
int doc)
206 result.AddDetail(nonPayloadExpl);
210 result.AddDetail(payloadBoost);
212 float payloadScore = GetPayloadScore();
213 payloadBoost.Value = payloadScore;
216 payloadBoost.Description =
"scorePayload(...)";
217 result.Value = nonPayloadExpl.Value * payloadScore;
218 result.Description =
"btq, product of:";
219 result.Match = nonPayloadExpl.Value == 0?
false:
true;
225 public override int GetHashCode()
228 int result = base.GetHashCode();
229 result = prime * result + ((
function == null)?0:
function.GetHashCode());
230 result = prime * result + (includeSpanScore?1231:1237);
234 public override bool Equals(System.Object obj)
238 if (!base.Equals(obj))
240 if (GetType() != obj.GetType())
243 if (
function == null)
245 if (other.function != null)
248 else if (!
function.Equals(other.function))
250 if (includeSpanScore != other.includeSpanScore)