iglu.ir
Class InvertedIndex

java.lang.Object
  |
  +--iglu.ir.InvertedIndex

public class InvertedIndex
extends java.lang.Object

Computes and stores an inverted index, which can be used by a search engine.

Author:
Ryan Scherle

Field Summary
private  boolean dataChanged
           
private  java.util.HashMap forwardVectors
           
private  java.util.HashMap invertedVectors
           
private  java.io.File storedIn
           
 
Constructor Summary
InvertedIndex(java.io.File storedIn)
          Creates a new index, or opens an existing index.
 
Method Summary
 void close()
          Closes the index.
 boolean containsKey(java.io.Serializable docId)
          Indicates whether a document is contained in the index.
 void flush()
          Forces the index to be written to file.
 ValueSortedMap getDocuments(java.lang.String term)
          Returns all documents containing term.
 TermVector getVector(java.lang.Object docId)
          Returns the term vector assocated with a document ID.
private  void initializeFromFile()
          Initializes the index from a saved file.
 java.util.Set keySet()
          Returns a set of all document ID's contained in the index.
static void main(java.lang.String[] args)
          Runs some tests on this class.
 void put(java.io.Serializable docId, TermVector docVector)
          Adds a document to the index.
 int size()
          Returns the number of documents in this index.
static void test()
          Runs some tests on this class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

invertedVectors

private java.util.HashMap invertedVectors

forwardVectors

private java.util.HashMap forwardVectors

storedIn

private java.io.File storedIn

dataChanged

private boolean dataChanged
Constructor Detail

InvertedIndex

public InvertedIndex(java.io.File storedIn)
Creates a new index, or opens an existing index. The index will be saved in the single file storedIn. If storedIn is a directory, the index will be stored in a file named "invertedIndex.dat" in this directory.

Method Detail

initializeFromFile

private void initializeFromFile()
Initializes the index from a saved file.


put

public void put(java.io.Serializable docId,
                TermVector docVector)
Adds a document to the index.


getVector

public TermVector getVector(java.lang.Object docId)
Returns the term vector assocated with a document ID.


getDocuments

public ValueSortedMap getDocuments(java.lang.String term)
Returns all documents containing term.

Returns:
a ValueSortedMap that maps each document to its score for the term.

containsKey

public boolean containsKey(java.io.Serializable docId)
Indicates whether a document is contained in the index.


keySet

public java.util.Set keySet()
Returns a set of all document ID's contained in the index.


size

public int size()
Returns the number of documents in this index.


flush

public void flush()
Forces the index to be written to file.


close

public void close()
Closes the index.


test

public static void test()
Runs some tests on this class.


main

public static void main(java.lang.String[] args)
Runs some tests on this class.