19 using System.Collections.Generic;
20 using Lucene.Net.Index;
21 using Lucene.Net.Support;
22 using Lucene.Net.Util;
25 using Query = Lucene.Net.Search.Query;
27 namespace Lucene.Net.Search.Spans
34 private class AnonymousClassSpans :
Spans
36 public AnonymousClassSpans(Lucene.Net.Index.IndexReader reader,
SpanOrQuery enclosingInstance)
38 InitBlock(reader, enclosingInstance);
40 private void InitBlock(Lucene.Net.Index.IndexReader reader,
SpanOrQuery enclosingInstance)
43 this.enclosingInstance = enclosingInstance;
45 private Lucene.Net.Index.IndexReader reader;
51 return enclosingInstance;
55 private SpanQueue queue = null;
57 private bool InitSpanQueue(
int target)
59 queue =
new SpanQueue(enclosingInstance, Enclosing_Instance.clauses.Count);
60 System.Collections.Generic.IEnumerator<
SpanQuery> i = Enclosing_Instance.clauses.GetEnumerator();
64 if (((target == - 1) && spans.
Next()) || ((target != - 1) && spans.
SkipTo(target)))
69 return queue.Size() != 0;
72 public override bool Next()
76 return InitSpanQueue(- 1);
79 if (queue.Size() == 0)
93 return queue.Size() != 0;
101 public override bool SkipTo(
int target)
105 return InitSpanQueue(target);
108 bool skipCalled =
false;
109 while (queue.Size() != 0 && Top().Doc() < target)
111 if (Top().SkipTo(target))
124 return queue.Size() != 0;
129 public override int Doc()
133 public override int Start()
135 return Top().Start();
137 public override int End()
142 public override ICollection<byte[]> GetPayload()
144 System.Collections.Generic.ICollection<byte[]> result = null;
145 Spans theTop = Top();
153 public override bool IsPayloadAvailable()
159 public override System.String ToString()
161 return "spans(" + Enclosing_Instance +
")@" + ((queue == null)?
"START":(queue.Size() > 0?(Doc() +
":" + Start() +
"-" + End()):
"END"));
165 private EquatableList<SpanQuery> clauses;
166 private System.String field;
173 this.clauses =
new EquatableList<SpanQuery>(clauses.Length);
174 for (
int i = 0; i < clauses.Length; i++)
180 field = clause.
Field;
182 else if (!clause.
Field.Equals(field))
184 throw new System.ArgumentException(
"Clauses must have same field.");
186 this.clauses.Add(clause);
193 return clauses.ToArray();
196 public override string Field
198 get {
return field; }
201 public override void ExtractTerms(System.Collections.Generic.ISet<
Term> terms)
209 public override System.Object Clone()
211 int sz = clauses.Count;
214 for (
int i = 0; i < sz; i++)
216 newClauses[i] = (
SpanQuery) clauses[i].Clone();
226 for (
int i = 0; i < clauses.Count; i++)
235 clone.clauses[i] = query;
248 public override System.String ToString(System.String field)
250 System.Text.StringBuilder buffer =
new System.Text.StringBuilder();
251 buffer.Append(
"spanOr([");
252 System.Collections.Generic.IEnumerator<
SpanQuery> i = clauses.GetEnumerator();
258 buffer.Append(clause.
ToString(field));
259 if (j < clauses.Count)
269 public override bool Equals(System.Object o)
273 if (o == null || GetType() != o.GetType())
278 if (!clauses.Equals(that.clauses))
280 if (!(clauses.Count == 0) && !field.Equals(that.field))
283 return Boost == that.
Boost;
286 public override int GetHashCode()
288 int h = clauses.GetHashCode();
290 h ^= System.Convert.ToInt32(Boost);
297 private void InitBlock(
SpanOrQuery enclosingInstance)
299 this.enclosingInstance = enclosingInstance;
306 return enclosingInstance;
310 public SpanQueue(
SpanOrQuery enclosingInstance,
int size)
312 InitBlock(enclosingInstance);
316 public override bool LessThan(Spans spans1, Spans spans2)
318 if (spans1.Doc() == spans2.Doc())
320 if (spans1.Start() == spans2.Start())
322 return spans1.End() < spans2.End();
326 return spans1.Start() < spans2.Start();
331 return spans1.Doc() < spans2.Doc();
338 if (clauses.Count == 1)
340 return (clauses[0]).GetSpans(reader);
342 return new AnonymousClassSpans(reader,
this);