01: package it.unimi.dsi.mg4j.search.score;
02:
03: /*
04: * MG4J: Managing Gigabytes for Java
05: *
06: * Copyright (C) 2004-2007 Paolo Boldi and 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 FITfNESS 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 java.io.IOException;
25:
26: import it.unimi.dsi.mg4j.index.Index;
27: import it.unimi.dsi.mg4j.search.DocumentIterator;
28:
29: /** An abstract subclass of {@link it.unimi.dsi.mg4j.search.score.AbstractScorer}.
30: * It provides additionally caching of the {@linkplain #currIndex indices used by the current iterator} for
31: * scorers that actually use multiple indices.
32: */
33: public abstract class AbstractIndexScorer extends AbstractScorer {
34: /** The current number of elements in {@link #currIndex}. */
35: protected int n;
36: /** An array containing the indices in {@link DocumentIterator#indices()} for {@link #documentIterator};
37: * it is set up by {@link #wrap(DocumentIterator)}. */
38: protected Index currIndex[];
39:
40: /** Wraps the given document iterator.
41: *
42: * <p>Besides the services provided by {@link AbstractScorer#wrap(DocumentIterator)},
43: * this method sets up {@link #currIndex} so that it refers to the indices
44: * actually used in <code>documentIterator</code>.
45: *
46: * @param documentIterator the document iterator that will be used in subsequent calls to
47: * {@link #score()} and {@link #score(Index)}.
48: */
49:
50: public void wrap(final DocumentIterator documentIterator)
51: throws IOException {
52: super .wrap(documentIterator);
53: n = documentIterator.indices().size();
54: currIndex = new Index[n];
55: int j = 0;
56: for (Index i : documentIterator.indices())
57: currIndex[j++] = i;
58: }
59: }
|