Thumbnail file hits. Based on a patch from D Bera
[beagle.git] / beagled / Lucene.Net / Search / Spans / SpanFirstQuery.cs
blobc98d51324ff8c0d985b71734f1c153a619404cf0
1 /*
2 * Copyright 2004 The Apache Software Foundation
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
16 using System;
17 using IndexReader = Lucene.Net.Index.IndexReader;
18 namespace Lucene.Net.Search.Spans
21 /// <summary>Matches spans near the beginning of a Field. </summary>
22 [Serializable]
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)
33 this.reader = reader;
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
41 get
43 return enclosingInstance;
47 private Spans spans;
49 public virtual bool Next()
51 while (spans.Next())
53 // scan to next match
54 if (End() <= Enclosing_Instance.end)
55 return true;
57 return false;
60 public virtual bool SkipTo(int target)
62 if (!spans.SkipTo(target))
63 return false;
65 if (spans.End() <= Enclosing_Instance.end)
66 // there is a match
67 return true;
69 return Next(); // scan to next match
72 public virtual int Doc()
74 return spans.Doc();
76 public virtual int Start()
78 return spans.Start();
80 public virtual int End()
82 return spans.End();
85 public override System.String ToString()
87 return "spans(" + Enclosing_Instance.ToString() + ")";
90 private SpanQuery match;
91 private int end;
93 /// <summary>Construct a SpanFirstQuery matching spans in <code>match</code> whose end
94 /// position is less than or equal to <code>end</code>.
95 /// </summary>
96 public SpanFirstQuery(SpanQuery match, int end)
98 this.match = match;
99 this.end = end;
102 /// <summary>Return the SpanQuery whose matches are filtered. </summary>
103 public virtual SpanQuery GetMatch()
105 return match;
108 /// <summary>Return the maximum end position permitted in a match. </summary>
109 public virtual int GetEnd()
111 return end;
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));
129 buffer.Append(", ");
130 buffer.Append(end);
131 buffer.Append(")");
132 return buffer.ToString();
135 public override Spans GetSpans(IndexReader reader)
137 return new AnonymousClassSpans(reader, this);