2 * Copyright 2004 The Apache Software Foundation
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 using IndexReader
= Lucene
.Net
.Index
.IndexReader
;
18 namespace Lucene
.Net
.Search
.Spans
21 /// <summary>Matches spans near the beginning of a Field. </summary>
23 public class SpanFirstQuery
:SpanQuery
25 private class AnonymousClassSpans
: Spans
27 public AnonymousClassSpans(Lucene
.Net
.Index
.IndexReader reader
, SpanFirstQuery enclosingInstance
)
29 InitBlock(reader
, enclosingInstance
);
31 private void InitBlock(Lucene
.Net
.Index
.IndexReader reader
, SpanFirstQuery enclosingInstance
)
34 this.enclosingInstance
= enclosingInstance
;
35 spans
= Enclosing_Instance
.match
.GetSpans(reader
);
37 private Lucene
.Net
.Index
.IndexReader reader
;
38 private SpanFirstQuery enclosingInstance
;
39 public SpanFirstQuery Enclosing_Instance
43 return enclosingInstance
;
49 public virtual bool Next()
54 if (End() <= Enclosing_Instance
.end
)
60 public virtual bool SkipTo(int target
)
62 if (!spans
.SkipTo(target
))
65 if (spans
.End() <= Enclosing_Instance
.end
)
69 return Next(); // scan to next match
72 public virtual int Doc()
76 public virtual int Start()
80 public virtual int End()
85 public override System
.String
ToString()
87 return "spans(" + Enclosing_Instance
.ToString() + ")";
90 private SpanQuery match
;
93 /// <summary>Construct a SpanFirstQuery matching spans in <code>match</code> whose end
94 /// position is less than or equal to <code>end</code>.
96 public SpanFirstQuery(SpanQuery match
, int end
)
102 /// <summary>Return the SpanQuery whose matches are filtered. </summary>
103 public virtual SpanQuery
GetMatch()
108 /// <summary>Return the maximum end position permitted in a match. </summary>
109 public virtual int GetEnd()
114 public override System
.String
GetField()
116 return match
.GetField();
119 public override System
.Collections
.ICollection
GetTerms()
121 return match
.GetTerms();
124 public override System
.String
ToString(System
.String field
)
126 System
.Text
.StringBuilder buffer
= new System
.Text
.StringBuilder();
127 buffer
.Append("spanFirst(");
128 buffer
.Append(match
.ToString(field
));
132 return buffer
.ToString();
135 public override Spans
GetSpans(IndexReader reader
)
137 return new AnonymousClassSpans(reader
, this);