01: /*
02: * Copyright 2001-2006 C:1 Financial Services GmbH
03: *
04: * This software is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License Version 2.1, as published by the Free Software Foundation.
07: *
08: * This software is distributed in the hope that it will be useful,
09: * but WITHOUT ANY WARRANTY; without even the implied warranty of
10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11: * Lesser General Public License for more details.
12: *
13: * You should have received a copy of the GNU Lesser General Public
14: * License along with this library; if not, write to the Free Software
15: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
16: */
17:
18: package de.finix.contelligent.search.engine;
19:
20: import java.io.IOException;
21: import java.util.Iterator;
22:
23: import org.apache.lucene.index.IndexReader;
24:
25: public class LuceneIndexIterator implements Iterator {
26:
27: private int current = 0;
28:
29: private int max;
30:
31: private IndexReader reader;
32:
33: public LuceneIndexIterator(IndexReader reader) {
34: this .reader = reader;
35: max = reader.numDocs();
36: }
37:
38: public boolean hasNext() {
39: return current < max;
40: }
41:
42: public Object next() {
43: try {
44: return reader.document(current++);
45: } catch (IOException e) {
46: throw new RuntimeException(e.getMessage());
47: }
48: }
49:
50: public void remove() {
51: throw new UnsupportedOperationException();
52: }
53:
54: public void close() throws IOException {
55: reader.close();
56: }
57: }
|