19 using System.Collections.Generic;
22 using Lucene.Net.Documents;
23 using Lucene.Net.Search;
24 using Lucene.Net.Index;
26 using TermInfo = Lucene.Net.Search.Vectorhighlight.FieldTermStack.TermInfo;
27 using QueryPhraseMap = Lucene.Net.Search.Vectorhighlight.FieldQuery.QueryPhraseMap;
29 namespace Lucene.Net.Search.Vectorhighlight
37 public LinkedList<WeightedPhraseInfo> phraseList =
new LinkedList<WeightedPhraseInfo>();
59 LinkedList<TermInfo> phraseCandidate =
new LinkedList<TermInfo>();
62 while (!fieldTermStack.
IsEmpty() && (phraseList.Count < phraseLimit) )
65 phraseCandidate.Clear();
71 if (currMap == null)
continue;
74 phraseCandidate.AddLast(ti);
77 ti = fieldTermStack.
Pop();
80 nextMap = currMap.GetTermMap(ti.Text);
81 if (ti == null || nextMap == null)
84 fieldTermStack.
Push(ti);
85 if (currMap.IsValidTermOrPhrase(
new List<TermInfo>(phraseCandidate)))
87 AddIfNoOverlap(
new WeightedPhraseInfo(phraseCandidate, currMap.Boost, currMap.TermOrPhraseNumber));
91 while (phraseCandidate.Count > 1)
93 TermInfo last = phraseCandidate.Last.Value;
94 phraseCandidate.RemoveLast();
95 fieldTermStack.
Push(last);
96 currMap = fieldQuery.
SearchPhrase(field,
new List<TermInfo>(phraseCandidate));
99 AddIfNoOverlap(
new WeightedPhraseInfo(phraseCandidate, currMap.Boost, currMap.TermOrPhraseNumber));
108 phraseCandidate.AddLast(ti);
119 if (existWpi.IsOffsetOverlap(wpi))
return;
121 phraseList.AddLast(wpi);
127 internal String text;
128 internal List<Toffs> termsOffsets;
130 internal float boost;
140 this.seqnum = number;
141 termsOffsets =
new List<Toffs>(terms.Count);
143 termsOffsets.Add(
new Toffs(ti.StartOffset, ti.EndOffset));
144 if (terms.Count == 1)
149 StringBuilder sb =
new StringBuilder();
151 int pos = ti.Position;
157 if (dummy) { dummy =
false;
continue; }
161 if (ti.Position - pos == 1)
163 Toffs to = termsOffsets[termsOffsets.Count - 1];
164 to.SetEndOffset(ti.EndOffset);
168 termsOffsets.Add(
new Toffs(ti.StartOffset, ti.EndOffset));
172 text = sb.ToString();
175 public int StartOffset
177 get {
return termsOffsets[0].startOffset; }
182 get {
return termsOffsets[termsOffsets.Count - 1].endOffset; }
187 int so = StartOffset;
191 if (so <= oso && oso < eo)
return true;
192 if (so < oeo && oeo <= eo)
return true;
193 if (oso <= so && so < oeo)
return true;
194 if (oso < eo && eo <= oeo)
return true;
198 public override string ToString()
200 StringBuilder sb =
new StringBuilder();
202 sb.Append(text).Append(
'(').Append(boost.ToString(
".0").Replace(System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator,
".")).Append(
")(");
203 foreach (
Toffs to
in termsOffsets)
208 return sb.ToString();
213 internal int startOffset;
214 internal int endOffset;
215 public Toffs(
int startOffset,
int endOffset)
217 this.startOffset = startOffset;
218 this.endOffset = endOffset;
220 internal void SetEndOffset(
int endOffset)
222 this.endOffset = endOffset;
224 public override string ToString()
226 StringBuilder sb =
new StringBuilder();
227 sb.Append(
'(').Append(startOffset).Append(
',').Append(endOffset).Append(
')');
228 return sb.ToString();