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 PriorityQueue
= Lucene
.Net
.Util
.PriorityQueue
;
18 namespace Lucene
.Net
.Index
22 /// <summary> Describe class <code>MultipleTermPositions</code> here.
25 /// <author> Anders Nielsen
29 public class MultipleTermPositions
: TermPositions
31 private sealed class TermPositionsQueue
:PriorityQueue
33 internal TermPositionsQueue(System
.Collections
.IList termPositions
)
35 Initialize(termPositions
.Count
);
37 System
.Collections
.IEnumerator i
= termPositions
.GetEnumerator();
40 TermPositions tp
= (TermPositions
) i
.Current
;
46 internal TermPositions
Peek()
48 return (TermPositions
) Top();
51 public override bool LessThan(System
.Object a
, System
.Object b
)
53 return ((TermPositions
) a
).Doc() < ((TermPositions
) b
).Doc();
57 private sealed class IntQueue
63 private void InitBlock()
65 _array
= new int[_arraySize
];
67 private int _arraySize
= 16;
69 private int _index
= 0;
70 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
);
115 private TermPositionsQueue _termPositionsQueue
;
116 private IntQueue _posList
;
118 /// <summary> Creates a new <code>MultipleTermPositions</code> instance.
121 /// <param name="indexReader">an <code>IndexReader</code> value
123 /// <param name="terms">a <code>Term[]</code> value
125 /// <exception cref=""> IOException if an error occurs
127 public MultipleTermPositions(IndexReader indexReader
, Term
[] terms
)
129 System
.Collections
.IList termPositions
= new System
.Collections
.ArrayList();
131 for (int i
= 0; i
< terms
.Length
; i
++)
132 termPositions
.Add(indexReader
.TermPositions(terms
[i
]));
134 _termPositionsQueue
= new TermPositionsQueue(termPositions
);
135 _posList
= new IntQueue();
140 if (_termPositionsQueue
.Size() == 0)
144 _doc
= _termPositionsQueue
.Peek().Doc();
149 tp
= _termPositionsQueue
.Peek();
151 for (int i
= 0; i
< tp
.Freq(); i
++)
152 _posList
.Add(tp
.NextPosition());
155 _termPositionsQueue
.AdjustTop();
158 _termPositionsQueue
.Pop();
162 while (_termPositionsQueue
.Size() > 0 && _termPositionsQueue
.Peek().Doc() == _doc
);
165 _freq
= _posList
.Size();
170 public int NextPosition()
172 return _posList
.Next();
175 public bool SkipTo(int target
)
177 while (target
> _termPositionsQueue
.Peek().Doc())
179 TermPositions tp
= (TermPositions
) _termPositionsQueue
.Pop();
181 if (tp
.SkipTo(target
))
182 _termPositionsQueue
.Put(tp
);
202 while (_termPositionsQueue
.Size() > 0)
203 ((TermPositions
) _termPositionsQueue
.Pop()).Close();
206 /// <summary>Not implemented.</summary>
207 /// <throws> UnsupportedOperationException </throws>
208 public virtual void Seek(Term arg0
)
210 throw new System
.NotSupportedException();
213 /// <summary>Not implemented.</summary>
214 /// <throws> UnsupportedOperationException </throws>
215 public virtual void Seek(TermEnum termEnum
)
217 throw new System
.NotSupportedException();
220 /// <summary>Not implemented.</summary>
221 /// <throws> UnsupportedOperationException </throws>
222 public virtual int Read(int[] arg0
, int[] arg1
)
224 throw new System
.NotSupportedException();