01: package it.unimi.dsi.mg4j.index.cluster;
02:
03: /*
04: * MG4J: Managing Gigabytes for Java
05: *
06: * Copyright (C) 2006-2007 Sebastiano Vigna
07: *
08: * This library is free software; you can redistribute it and/or modify it
09: * under the terms of the GNU Lesser General Public License as published by the Free
10: * Software Foundation; either version 2.1 of the License, or (at your option)
11: * any later version.
12: *
13: * This library is distributed in the hope that it will be useful, but
14: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
16: * for more details.
17: *
18: * You should have received a copy of the GNU Lesser General Public License
19: * along with this program; if not, write to the Free Software
20: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21: *
22: */
23:
24: import it.unimi.dsi.mg4j.index.IndexIterator;
25:
26: import java.io.IOException;
27:
28: /** An index reader for a {@linkplain LexicalCluster lexical cluster}.
29: * It diverts a call for the documents of a given term or prefix to the suitable local index (or set of indices).
30: *
31: * @author Alessandro Arrabito
32: * @author Sebastiano Vigna
33: */
34:
35: public class LexicalClusterIndexReader extends
36: AbstractIndexClusterIndexReader {
37: /** The index this reader refers to. */
38: private final LexicalCluster index;
39:
40: public LexicalClusterIndexReader(final LexicalCluster index,
41: final int bufferSize) throws IOException {
42: super (index, bufferSize);
43: this .index = index;
44: }
45:
46: public IndexIterator documents(final int term) throws IOException {
47: if (index.partitioningStrategy != null)
48: return indexReader[index.partitioningStrategy
49: .localIndex(term)]
50: .documents(index.partitioningStrategy
51: .localNumber(term));
52: else
53: throw new UnsupportedOperationException();
54: }
55:
56: public IndexIterator documents(final CharSequence term)
57: throws IOException {
58: final int localIndex = index.strategy.localIndex(term);
59: if (localIndex == -1)
60: return index.emptyIndexIterator;
61: return indexReader[localIndex].documents(term);
62: }
63: }
|