001: package it.unimi.dsi.mg4j.index;
002:
003: /*
004: * MG4J: Managing Gigabytes for Java
005: *
006: * Copyright (C) 2007 Sebastiano Vigna
007: *
008: * This library is free software; you can redistribute it and/or modify it
009: * under the terms of the GNU Lesser General Public License as published by the Free
010: * Software Foundation; either version 2.1 of the License, or (at your option)
011: * any later version.
012: *
013: * This library is distributed in the hope that it will be useful, but
014: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
015: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
016: * for more details.
017: *
018: * You should have received a copy of the GNU Lesser General Public License
019: * along with this program; if not, write to the Free Software
020: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
021: *
022: */
023:
024: import it.unimi.dsi.fastutil.ints.IntList;
025: import it.unimi.dsi.fastutil.longs.LongList;
026: import it.unimi.dsi.mg4j.index.CompressionFlags.Coding;
027: import it.unimi.dsi.mg4j.index.payload.Payload;
028: import it.unimi.dsi.io.InputBitStream;
029: import it.unimi.dsi.util.Properties;
030: import it.unimi.dsi.util.StringMap;
031: import it.unimi.dsi.util.PrefixMap;
032:
033: import java.io.File;
034: import java.io.FileInputStream;
035: import java.io.FileNotFoundException;
036: import java.io.IOException;
037: import java.io.InputStream;
038:
039: /** A file-based high-performance index.
040: *
041: * <P>An instance of this class stores additional index data for indices
042: * based on files: for instance, basename, compression flags, etc.
043: *
044: * @author Paolo Boldi
045: * @author Sebastiano Vigna
046: * @since 0.9
047: */
048:
049: public class FileHPIndex extends BitStreamHPIndex {
050: private static final long serialVersionUID = 0;
051:
052: /** The basename of this index. All file names will be stemmed from the basename. It may
053: * be <code>null</code>. */
054: public final String basename;
055: /** The file containing the index. It may be <code>null</code>. */
056: public final File indexFile;
057: /** The file containing the positions. It may be <code>null</code>. // TODO: Why ? */
058: public final File positionsFile;
059:
060: public FileHPIndex(final String basename,
061: final int numberOfDocuments, final int numberOfTerms,
062: final long numberOfPostings,
063: final long numberOfOccurrences, final int maxCount,
064: final Payload payload, final Coding frequencyCoding,
065: final Coding pointerCoding, final Coding countCoding,
066: final Coding positionCoding, final int quantum,
067: final int height, final int bufferSize,
068: final TermProcessor termProcessor, final String field,
069: final Properties properties,
070: final StringMap<? extends CharSequence> termMap,
071: final PrefixMap<? extends CharSequence> prefixMap,
072: final IntList sizes, final LongList offsets) {
073: super (numberOfDocuments, numberOfTerms, numberOfPostings,
074: numberOfOccurrences, maxCount, payload,
075: frequencyCoding, pointerCoding, countCoding,
076: positionCoding, quantum, height, bufferSize,
077: termProcessor, field, properties, termMap, prefixMap,
078: sizes, offsets);
079: this .basename = basename;
080: this .indexFile = new File(basename
081: + DiskBasedIndex.INDEX_EXTENSION);
082: this .positionsFile = new File(basename
083: + DiskBasedIndex.POSITIONS_EXTENSION);
084: }
085:
086: public String toString() {
087: return this .getClass().getSimpleName() + "(" + basename + ")";
088: }
089:
090: @Override
091: public FileInputStream getInputStream()
092: throws FileNotFoundException {
093: return new FileInputStream(indexFile);
094: }
095:
096: @Override
097: public InputBitStream getInputBitStream(final int bufferSize)
098: throws FileNotFoundException {
099: return new InputBitStream(indexFile, bufferSize);
100: }
101:
102: @Override
103: public InputStream getPositionsInputStream() throws IOException {
104: return new FileInputStream(positionsFile);
105: }
106:
107: @Override
108: public InputBitStream getPositionsInputBitStream(int bufferSize)
109: throws IOException {
110: return new InputBitStream(positionsFile, bufferSize);
111: }
112: }
|