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.
18 using PriorityQueue
= Lucene
.Net
.Util
.PriorityQueue
;
20 namespace Lucene
.Net
.Index
23 /// <summary> Describe class <code>MultipleTermPositions</code> here.
26 /// <author> Anders Nielsen
30 public class MultipleTermPositions
: TermPositions
33 private sealed class TermPositionsQueue
:PriorityQueue
35 internal TermPositionsQueue(System
.Collections
.IList termPositions
)
37 Initialize(termPositions
.Count
);
39 System
.Collections
.IEnumerator i
= termPositions
.GetEnumerator();
42 TermPositions tp
= (TermPositions
) i
.Current
;
48 internal TermPositions
Peek()
50 return (TermPositions
) Top();
53 public override bool LessThan(System
.Object a
, System
.Object b
)
55 return ((TermPositions
) a
).Doc() < ((TermPositions
) b
).Doc();
59 private sealed class IntQueue
65 private void InitBlock()
67 _array
= new int[_arraySize
];
69 private int _arraySize
= 16;
70 private int _index
= 0;
71 private int _lastIndex
= 0;
74 internal void Add(int i
)
76 if (_lastIndex
== _arraySize
)
79 _array
[_lastIndex
++] = i
;
84 return _array
[_index
++];
89 System
.Array
.Sort(_array
, _index
, _lastIndex
- _index
);
100 return (_lastIndex
- _index
);
103 private void GrowArray()
105 int[] newArray
= new int[_arraySize
* 2];
106 Array
.Copy(_array
, 0, newArray
, 0, _arraySize
);
114 private TermPositionsQueue _termPositionsQueue
;
115 private IntQueue _posList
;
117 /// <summary> Creates a new <code>MultipleTermPositions</code> instance.
120 /// <exception cref="IOException">
122 public MultipleTermPositions(IndexReader indexReader
, Term
[] terms
)
124 System
.Collections
.IList termPositions
= new System
.Collections
.ArrayList();
126 for (int i
= 0; i
< terms
.Length
; i
++)
127 termPositions
.Add(indexReader
.TermPositions(terms
[i
]));
129 _termPositionsQueue
= new TermPositionsQueue(termPositions
);
130 _posList
= new IntQueue();
135 if (_termPositionsQueue
.Size() == 0)
139 _doc
= _termPositionsQueue
.Peek().Doc();
144 tp
= _termPositionsQueue
.Peek();
146 for (int i
= 0; i
< tp
.Freq(); i
++)
147 _posList
.Add(tp
.NextPosition());
150 _termPositionsQueue
.AdjustTop();
153 _termPositionsQueue
.Pop();
157 while (_termPositionsQueue
.Size() > 0 && _termPositionsQueue
.Peek().Doc() == _doc
);
160 _freq
= _posList
.Size();
165 public int NextPosition()
167 return _posList
.Next();
170 public bool SkipTo(int target
)
172 while (_termPositionsQueue
.Peek() != null && target
> _termPositionsQueue
.Peek().Doc())
174 TermPositions tp
= (TermPositions
) _termPositionsQueue
.Pop();
175 if (tp
.SkipTo(target
))
176 _termPositionsQueue
.Put(tp
);
195 while (_termPositionsQueue
.Size() > 0)
196 ((TermPositions
) _termPositionsQueue
.Pop()).Close();
199 /// <summary> Not implemented.</summary>
200 /// <throws> UnsupportedOperationException </throws>
201 public virtual void Seek(Term arg0
)
203 throw new System
.NotSupportedException();
206 /// <summary> Not implemented.</summary>
207 /// <throws> UnsupportedOperationException </throws>
208 public virtual void Seek(TermEnum termEnum
)
210 throw new System
.NotSupportedException();
213 /// <summary> Not implemented.</summary>
214 /// <throws> UnsupportedOperationException </throws>
215 public virtual int Read(int[] arg0
, int[] arg1
)
217 throw new System
.NotSupportedException();