23 using Scorer = Lucene.Net.Search.Scorer;
26 using Weight = Lucene.Net.Search.Weight;
30 using SpanQuery = Lucene.Net.Search.Spans.SpanQuery;
34 namespace Lucene.Net.Search.Payloads
54 protected internal System.String fieldName;
63 fieldName = clauses[0].Field;
64 this.
function =
function;
72 public override System.Object Clone()
74 int sz = clauses.Count;
77 for (
int i = 0; i < sz; i++)
79 newClauses[i] = clauses[i];
82 boostingNearQuery.Boost = Boost;
83 return boostingNearQuery;
86 public override System.String ToString(System.String field)
88 System.Text.StringBuilder buffer =
new System.Text.StringBuilder();
89 buffer.Append(
"payloadNear([");
90 var i = clauses.GetEnumerator();
94 buffer.Append(clause.ToString(field));
100 buffer.Append(
"], ");
101 buffer.Append(internalSlop);
103 buffer.Append(inOrder);
110 public override int GetHashCode()
113 int result = base.GetHashCode();
114 result = prime * result + ((fieldName == null)?0:fieldName.GetHashCode());
115 result = prime * result + ((
function == null)?0:
function.GetHashCode());
120 public override bool Equals(System.Object obj)
124 if (!base.Equals(obj))
126 if (GetType() != obj.GetType())
129 if (fieldName == null)
131 if (other.fieldName != null)
134 else if (!fieldName.Equals(other.fieldName))
136 if (
function == null)
138 if (other.function != null)
141 else if (!
function.Equals(other.function))
151 this.enclosingInstance = enclosingInstance;
158 return enclosingInstance;
164 InitBlock(enclosingInstance);
169 return new PayloadNearSpanScorer(enclosingInstance, internalQuery.GetSpans(reader),
this, similarity, reader.Norms(internalQuery.Field));
177 this.enclosingInstance = enclosingInstance;
185 return enclosingInstance;
189 new internal Lucene.Net.Search.Spans.Spans spans;
191 protected internal float payloadScore;
192 private int payloadsSeen;
197 InitBlock(enclosingInstance);
202 public virtual void GetPayloads(Lucene.Net.Search.Spans.Spans[] subSpans)
204 for (
int i = 0; i < subSpans.Length; i++)
208 if (((NearSpansOrdered) subSpans[i]).IsPayloadAvailable())
210 ProcessPayloads(((NearSpansOrdered) subSpans[i]).GetPayload(), subSpans[i].Start(), subSpans[i].End());
212 GetPayloads(((NearSpansOrdered) subSpans[i]).GetSubSpans());
216 if (((NearSpansUnordered) subSpans[i]).IsPayloadAvailable())
218 ProcessPayloads(((NearSpansUnordered) subSpans[i]).GetPayload(), subSpans[i].Start(), subSpans[i].End());
220 GetPayloads(((NearSpansUnordered) subSpans[i]).GetSubSpans());
238 protected internal virtual void ProcessPayloads(System.Collections.Generic.ICollection<byte[]> payLoads,
int start,
int end)
240 foreach (byte[] thePayload
in payLoads)
242 payloadScore = Enclosing_Instance.function.CurrentScore(doc, Enclosing_Instance.fieldName, start, end, payloadsSeen, payloadScore, similarity.ScorePayload(doc, Enclosing_Instance.fieldName, spans.Start(), spans.End(), thePayload, 0, thePayload.Length));
248 public override bool SetFreqCurrentDoc()
254 Lucene.Net.Search.Spans.Spans[] spansArr =
new Lucene.Net.Search.Spans.Spans[1];
258 GetPayloads(spansArr);
259 return base.SetFreqCurrentDoc();
262 public override float Score()
265 return base.Score() * Enclosing_Instance.function.DocScore(doc, Enclosing_Instance.fieldName, payloadsSeen, payloadScore);
268 protected internal override Explanation Explain(
int doc)
275 float avgPayloadScore = (payloadsSeen > 0?(payloadScore / payloadsSeen):1);
276 payloadBoost.
Value = avgPayloadScore;
278 result.
Value = nonPayloadExpl.
Value * avgPayloadScore;