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 using Term
= Lucene
.Net
.Index
.Term
;
19 using TermPositions
= Lucene
.Net
.Index
.TermPositions
;
20 namespace Lucene
.Net
.Search
.Spans
23 /// <summary>Matches spans containing a term. </summary>
25 public class SpanTermQuery
:SpanQuery
27 private class AnonymousClassSpans
: Spans
29 public AnonymousClassSpans(Lucene
.Net
.Index
.IndexReader reader
, SpanTermQuery enclosingInstance
)
31 InitBlock(reader
, enclosingInstance
);
33 private void InitBlock(Lucene
.Net
.Index
.IndexReader reader
, SpanTermQuery enclosingInstance
)
36 this.enclosingInstance
= enclosingInstance
;
37 positions
= reader
.TermPositions(Enclosing_Instance
.term
);
39 private Lucene
.Net
.Index
.IndexReader reader
;
40 private SpanTermQuery enclosingInstance
;
41 public SpanTermQuery Enclosing_Instance
45 return enclosingInstance
;
49 private TermPositions positions
;
51 private int doc
= - 1;
56 public virtual bool Next()
60 if (!positions
.Next())
62 doc
= System
.Int32
.MaxValue
;
65 doc
= positions
.Doc();
66 freq
= positions
.Freq();
69 position
= positions
.NextPosition();
74 public virtual bool SkipTo(int target
)
76 if (!positions
.SkipTo(target
))
78 doc
= System
.Int32
.MaxValue
;
82 doc
= positions
.Doc();
83 freq
= positions
.Freq();
86 position
= positions
.NextPosition();
92 public virtual int Doc()
96 public virtual int Start()
100 public virtual int End()
105 public override System
.String
ToString()
107 return "spans(" + Enclosing_Instance
.ToString() + ")@" + (doc
== - 1?"START":((doc
== System
.Int32
.MaxValue
)?"END":doc
+ "-" + position
));
112 /// <summary>Construct a SpanTermQuery matching the named term's spans. </summary>
113 public SpanTermQuery(Term term
)
118 /// <summary>Return the term whose spans are matched. </summary>
119 public virtual Term
GetTerm()
124 public override System
.String
GetField()
129 public override System
.Collections
.ICollection
GetTerms()
131 System
.Collections
.ArrayList terms
= new System
.Collections
.ArrayList();
136 public override System
.String
ToString(System
.String field
)
138 if (term
.Field().Equals(field
))
142 return term
.ToString();
146 public override Spans
GetSpans(IndexReader reader
)
148 return new AnonymousClassSpans(reader
, this);