19 using System.Collections.Generic;
21 using Lucene.Net.Util;
24 namespace Lucene.Net.Search.Spans
36 private System.Collections.Generic.IList<SpansCell> ordered =
new System.Collections.Generic.List<SpansCell>();
37 private Spans[] subSpans;
40 private SpansCell first;
41 private SpansCell last;
43 private int totalLength;
45 private CellQueue queue;
46 private SpansCell max;
48 private bool more =
true;
49 private bool firstTime =
true;
55 this.enclosingInstance = enclosingInstance;
62 return enclosingInstance;
68 InitBlock(enclosingInstance);
72 public override bool LessThan(SpansCell spans1, SpansCell spans2)
74 if (spans1.Doc() == spans2.Doc())
80 return spans1.Doc() < spans2.Doc();
87 private class SpansCell:
Spans
91 this.enclosingInstance = enclosingInstance;
98 return enclosingInstance;
102 internal Spans spans;
103 internal SpansCell next;
104 private int length = - 1;
109 InitBlock(enclosingInstance);
114 public override bool Next()
116 return Adjust(spans.
Next());
119 public override bool SkipTo(
int target)
121 return Adjust(spans.
SkipTo(target));
124 private bool Adjust(
bool condition)
128 Enclosing_Instance.totalLength -= length;
132 length = End() - Start();
133 Enclosing_Instance.totalLength += length;
135 if (Enclosing_Instance.max == null || Doc() > Enclosing_Instance.max.Doc() || (Doc() == Enclosing_Instance.max.Doc()) && (End() > Enclosing_Instance.max.End()))
137 Enclosing_Instance.max =
this;
140 Enclosing_Instance.more = condition;
144 public override int Doc()
148 public override int Start()
150 return spans.
Start();
152 public override int End()
158 public override ICollection<byte[]> GetPayload()
165 public override bool IsPayloadAvailable()
170 public override System.String ToString()
172 return spans.ToString() +
"#" + index;
180 this.slop = query.
Slop;
183 queue =
new CellQueue(
this, clauses.Length);
184 subSpans =
new Spans[clauses.Length];
185 for (
int i = 0; i < clauses.Length; i++)
187 SpansCell cell =
new SpansCell(
this, clauses[i].GetSpans(reader), i);
189 subSpans[i] = cell.spans;
192 public virtual Spans[] GetSubSpans()
196 public override bool Next()
220 bool queueStale =
false;
222 if (Min().Doc() != max.Doc())
231 while (more && first.Doc() < last.Doc())
233 more = first.SkipTo(last.Doc());
264 public override bool SkipTo(
int target)
270 for (SpansCell cell = first; more && cell != null; cell = cell.next)
272 more = cell.SkipTo(target);
283 while (more && Min().Doc() < target)
286 if (Min().SkipTo(target))
296 return more && (AtMatch() || Next());
299 private SpansCell Min()
304 public override int Doc()
308 public override int Start()
310 return Min().Start();
312 public override int End()
322 public override ICollection<byte[]> GetPayload()
324 System.Collections.Generic.ISet<byte[]> matchPayload = Lucene.Net.Support.Compatibility.SetFactory.CreateHashSet<byte[]>();
325 for (SpansCell cell = first; cell != null; cell = cell.next)
327 if (cell.IsPayloadAvailable())
329 matchPayload.UnionWith(cell.GetPayload());
337 public override bool IsPayloadAvailable()
339 SpansCell pointer = Min();
340 while (pointer != null)
342 if (pointer.IsPayloadAvailable())
346 pointer = pointer.next;
352 public override System.String ToString()
354 return GetType().FullName +
"(" + query.ToString() +
")@" + (firstTime?
"START":(more?(Doc() +
":" + Start() +
"-" + End()):
"END"));
357 private void InitList(
bool next)
359 for (
int i = 0; more && i < ordered.Count; i++)
361 SpansCell cell = ordered[i];
371 private void AddToList(SpansCell cell)
384 private void FirstToLast()
392 private void QueueToList()
395 while (queue.Top() != null)
397 AddToList(queue.Pop());
401 private void ListToQueue()
404 for (SpansCell cell = first; cell != null; cell = cell.next)
410 private bool AtMatch()
412 return (Min().Doc() == max.Doc()) && ((max.End() - Min().Start() - totalLength) <= slop);