19 using System.Collections.Generic;
20 using Lucene.Net.Index;
21 using Lucene.Net.Support;
24 using Query = Lucene.Net.Search.Query;
26 namespace Lucene.Net.Search.Spans
33 private class AnonymousClassSpans :
Spans
35 public AnonymousClassSpans(Lucene.Net.Index.IndexReader reader,
SpanNotQuery enclosingInstance)
37 InitBlock(reader, enclosingInstance);
39 private void InitBlock(Lucene.Net.Index.IndexReader reader,
SpanNotQuery enclosingInstance)
42 this.enclosingInstance = enclosingInstance;
43 includeSpans = Enclosing_Instance.include.
GetSpans(reader);
44 excludeSpans = Enclosing_Instance.exclude.GetSpans(reader);
45 moreExclude = excludeSpans.
Next();
47 private Lucene.Net.Index.IndexReader reader;
53 return enclosingInstance;
57 private Spans includeSpans;
58 private bool moreInclude =
true;
60 private Spans excludeSpans;
61 private bool moreExclude;
63 public override bool Next()
67 moreInclude = includeSpans.
Next();
69 while (moreInclude && moreExclude)
72 if (includeSpans.Doc() > excludeSpans.Doc())
74 moreExclude = excludeSpans.SkipTo(includeSpans.Doc());
76 while (moreExclude && includeSpans.Doc() == excludeSpans.Doc() && excludeSpans.End() <= includeSpans.Start())
78 moreExclude = excludeSpans.Next();
81 if (!moreExclude || includeSpans.Doc() != excludeSpans.Doc() || includeSpans.End() <= excludeSpans.Start())
84 moreInclude = includeSpans.Next();
89 public override bool SkipTo(
int target)
93 moreInclude = includeSpans.SkipTo(target);
98 if (moreExclude && includeSpans.Doc() > excludeSpans.Doc())
99 moreExclude = excludeSpans.SkipTo(includeSpans.Doc());
101 while (moreExclude && includeSpans.Doc() == excludeSpans.Doc() && excludeSpans.End() <= includeSpans.Start())
103 moreExclude = excludeSpans.Next();
106 if (!moreExclude || includeSpans.Doc() != excludeSpans.Doc() || includeSpans.End() <= excludeSpans.Start())
112 public override int Doc()
114 return includeSpans.Doc();
116 public override int Start()
118 return includeSpans.Start();
120 public override int End()
122 return includeSpans.End();
127 public override ICollection<byte[]> GetPayload()
129 System.Collections.Generic.ICollection<byte[]> result = null;
130 if (includeSpans.IsPayloadAvailable())
132 result = includeSpans.GetPayload();
139 public override bool IsPayloadAvailable()
141 return includeSpans.IsPayloadAvailable();
144 public override System.String ToString()
146 return "spans(" + Enclosing_Instance.ToString() +
")";
157 this.include = include;
158 this.exclude = exclude;
161 throw new System.ArgumentException(
"Clauses must have same field.");
167 get {
return include; }
173 get {
return exclude; }
176 public override string Field
178 get {
return include.
Field; }
181 public override void ExtractTerms(System.Collections.Generic.ISet<
Term> terms)
183 include.ExtractTerms(terms);
186 public override System.String ToString(System.String field)
188 System.Text.StringBuilder buffer =
new System.Text.StringBuilder();
189 buffer.Append(
"spanNot(");
190 buffer.Append(include.ToString(field));
192 buffer.Append(exclude.ToString(field));
195 return buffer.ToString();
198 public override System.Object Clone()
201 spanNotQuery.
Boost = Boost;
207 return new AnonymousClassSpans(reader,
this);
215 if (rewrittenInclude != include)
218 clone.include = rewrittenInclude;
221 if (rewrittenExclude != exclude)
225 clone.exclude = rewrittenExclude;
239 public override bool Equals(System.Object o)
246 SpanNotQuery other = (SpanNotQuery) o;
247 return this.include.
Equals(other.include) && this.exclude.Equals(other.exclude) && this.Boost == other.
Boost;
250 public override int GetHashCode()
252 int h = include.GetHashCode();
254 h ^= exclude.GetHashCode();
256 h ^= System.Convert.ToInt32(Boost);