Lucene.Net  3.0.3
Lucene.Net is a .NET port of the Java Lucene Indexing Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties
TermSpans.cs
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 using System;
19 using System.Collections.Generic;
20 using Term = Lucene.Net.Index.Term;
21 using TermPositions = Lucene.Net.Index.TermPositions;
22 
23 namespace Lucene.Net.Search.Spans
24 {
25 
29  public class TermSpans:Spans
30  {
31  protected internal TermPositions internalPositions;
32  protected internal Term term;
33  protected internal int internalDoc;
34  protected internal int freq;
35  protected internal int count;
36  protected internal int position;
37 
38 
39  public TermSpans(TermPositions positions, Term term)
40  {
41 
42  this.internalPositions = positions;
43  this.term = term;
44  internalDoc = - 1;
45  }
46 
47  public override bool Next()
48  {
49  if (count == freq)
50  {
51  if (!internalPositions.Next())
52  {
53  internalDoc = int.MaxValue;
54  return false;
55  }
56  internalDoc = internalPositions.Doc;
57  freq = internalPositions.Freq;
58  count = 0;
59  }
60  position = internalPositions.NextPosition();
61  count++;
62  return true;
63  }
64 
65  public override bool SkipTo(int target)
66  {
67  if (!internalPositions.SkipTo(target))
68  {
69  internalDoc = int.MaxValue;
70  return false;
71  }
72 
73  internalDoc = internalPositions.Doc;
74  freq = internalPositions.Freq;
75  count = 0;
76 
77  position = internalPositions.NextPosition();
78  count++;
79 
80  return true;
81  }
82 
83  public override int Doc()
84  {
85  return internalDoc;
86  }
87 
88  public override int Start()
89  {
90  return position;
91  }
92 
93  public override int End()
94  {
95  return position + 1;
96  }
97 
98  // TODO: Remove warning after API has been finalized
99 
100  public override ICollection<byte[]> GetPayload()
101  {
102  byte[] bytes = new byte[internalPositions.PayloadLength];
103  bytes = internalPositions.GetPayload(bytes, 0);
104  var val = new System.Collections.Generic.List<byte[]>();
105  val.Add(bytes);
106  return val;
107  }
108 
109  // TODO: Remove warning after API has been finalized
110 
111  public override bool IsPayloadAvailable()
112  {
113  return internalPositions.IsPayloadAvailable;
114  }
115 
116  public override System.String ToString()
117  {
118  return "spans(" + term.ToString() + ")@" + (internalDoc == - 1?"START":((internalDoc == System.Int32.MaxValue)?"END":internalDoc + "-" + position));
119  }
120 
121  public virtual TermPositions Positions
122  {
123  get { return internalPositions; }
124  }
125  }
126 }