org.teiid.internal.core.index
Class Index

java.lang.Object
  extended by org.teiid.internal.core.index.Index
All Implemented Interfaces:
IIndex

public class Index
extends java.lang.Object
implements IIndex

An Index is used to create an index on the disk, and to make queries. It uses a set of indexers and a mergeFactory. The index fills an inMemoryIndex up to it reaches a certain size, and then merges it with a main index on the disk.

The changes are only taken into account by the queries after a merge.


Field Summary
protected  InMemoryIndex addsIndex
          Index in memory, who is merged with mainIndex each times it reaches a certain size.
protected  IndexInput addsIndexInput
           
protected static int CAN_MERGE
           
protected  boolean doCache
           
static int MAX_FOOTPRINT
          Maximum size of the index in memory.
protected static int MERGED
           
protected  java.util.Map removedInAdds
          Files removed form the addsIndex.
protected  java.util.Map removedInOld
          Files removed form the oldIndex.
protected  int state
          State of the indexGenerator: addsIndex empty <=> MERGED, or addsIndex not empty <=> CAN_MERGE
 java.lang.String toString
          String representation of this index.
 
Constructor Summary
Index(org.jboss.virtual.VirtualFile f, boolean reuseExistingFile)
           
 
Method Summary
 void add(IDocument document, IIndexer indexer)
          Indexes the given document, using the appropriate indexer registered in the indexerRegistry.
protected  boolean canMerge()
          Returns true if the index in memory is not empty, so merge() can be called to fill the mainIndex with the files and words contained in the addsIndex.
 void close()
          Closes the index file if open
 void dispose()
          closes the index file then deletes it.
 void empty()
          Initialises the indexGenerator.
protected  BlocksIndexInput getBlocksIndexInput()
           
 BlocksIndexInput getCachedInput()
           
 org.jboss.virtual.VirtualFile getIndexFile()
          Returns the index file on the disk.
 int getNumDocuments()
          Returns the number of documents indexed.
 int getNumWords()
          Returns the number of unique words indexed.
 java.lang.String getPath(int documentNumber)
          Returns the path corresponding to a given document number
 java.lang.String getResourceFileName()
           
 boolean hasChanged()
          see IIndex.hasChanged
 void initialize(boolean reuseExistingFile)
          Initialises the indexGenerator.
protected  void merge()
          Merges the in memory index and the index on the disk, and saves the results on the disk.
 IQueryResult[] query(java.lang.String word)
          Returns the paths of the documents containing the given word.
 IEntryResult[] queryEntries(char[] prefix)
          Returns all entries for a given word.
 IEntryResult[] queryEntries(char[] prefix, boolean isCaseSensitive)
          Overloaded the method in Index to allow a user to specify if the query should be case sensitive.
 IEntryResult[] queryEntriesMatching(char[] prefix, boolean isCaseSensitive)
          Overloaded the method in Index to allow a user to specify if the query should be case sensitive.
 IQueryResult[] queryInDocumentNames(java.lang.String word)
          Returns the paths of the documents whose names contain the given word.
 IQueryResult[] queryPrefix(char[] prefix)
          Returns the paths of the documents containing the given word prefix.
protected  void remove(IndexedFile file, int index)
          Removes the given document from the given index (MergeFactory.ADDS_INDEX for the in memory index, MergeFactory.OLD_INDEX for the index on the disk).
 void remove(java.lang.String documentName)
          Removes the corresponding document from the index.
 void save()
          Saves the index on the disk.
 void setCachedInput(BlocksIndexInput theCachedInput)
           
 void setDoCache(boolean theDoCache)
          sets a boolean indicating the index file will be cached and should remain open and in-memory
protected  boolean timeToMerge()
          Returns true if the in memory index reaches a critical size, to merge it with the index on the disk.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MAX_FOOTPRINT

public static final int MAX_FOOTPRINT
Maximum size of the index in memory.

See Also:
Constant Field Values

addsIndex

protected InMemoryIndex addsIndex
Index in memory, who is merged with mainIndex each times it reaches a certain size.


addsIndexInput

protected IndexInput addsIndexInput

state

protected int state
State of the indexGenerator: addsIndex empty <=> MERGED, or addsIndex not empty <=> CAN_MERGE


removedInAdds

protected java.util.Map removedInAdds
Files removed form the addsIndex.


removedInOld

protected java.util.Map removedInOld
Files removed form the oldIndex.


CAN_MERGE

protected static final int CAN_MERGE
See Also:
Constant Field Values

MERGED

protected static final int MERGED
See Also:
Constant Field Values

doCache

protected boolean doCache

toString

public java.lang.String toString
String representation of this index.

Constructor Detail

Index

public Index(org.jboss.virtual.VirtualFile f,
             boolean reuseExistingFile)
      throws java.io.IOException
Throws:
java.io.IOException
Method Detail

add

public void add(IDocument document,
                IIndexer indexer)
         throws java.io.IOException
Indexes the given document, using the appropriate indexer registered in the indexerRegistry. If the document already exists in the index, it overrides the previous one. The changes will be taken into account after a merge.

Specified by:
add in interface IIndex
Throws:
java.io.IOException

canMerge

protected boolean canMerge()
Returns true if the index in memory is not empty, so merge() can be called to fill the mainIndex with the files and words contained in the addsIndex.


empty

public void empty()
           throws java.io.IOException
Initialises the indexGenerator.

Specified by:
empty in interface IIndex
Throws:
java.io.IOException

getIndexFile

public org.jboss.virtual.VirtualFile getIndexFile()
Description copied from interface: IIndex
Returns the index file on the disk.

Specified by:
getIndexFile in interface IIndex
See Also:
IIndex.getIndexFile()

getNumDocuments

public int getNumDocuments()
                    throws java.io.IOException
Description copied from interface: IIndex
Returns the number of documents indexed.

Specified by:
getNumDocuments in interface IIndex
Throws:
java.io.IOException
See Also:
IIndex.getNumDocuments()

getNumWords

public int getNumWords()
                throws java.io.IOException
Description copied from interface: IIndex
Returns the number of unique words indexed.

Specified by:
getNumWords in interface IIndex
Throws:
java.io.IOException
See Also:
IIndex.getNumWords()

getPath

public java.lang.String getPath(int documentNumber)
                         throws java.io.IOException
Returns the path corresponding to a given document number

Specified by:
getPath in interface IIndex
Throws:
java.io.IOException

hasChanged

public boolean hasChanged()
see IIndex.hasChanged

Specified by:
hasChanged in interface IIndex

initialize

public void initialize(boolean reuseExistingFile)
                throws java.io.IOException
Initialises the indexGenerator.

Throws:
java.io.IOException

merge

protected void merge()
              throws java.io.IOException
Merges the in memory index and the index on the disk, and saves the results on the disk.

Throws:
java.io.IOException

query

public IQueryResult[] query(java.lang.String word)
                     throws java.io.IOException
Description copied from interface: IIndex
Returns the paths of the documents containing the given word.

Specified by:
query in interface IIndex
Throws:
java.io.IOException
See Also:
IIndex.query(java.lang.String)

queryEntries

public IEntryResult[] queryEntries(char[] prefix)
                            throws java.io.IOException
Description copied from interface: IIndex
Returns all entries for a given word.

Specified by:
queryEntries in interface IIndex
Throws:
java.io.IOException

queryInDocumentNames

public IQueryResult[] queryInDocumentNames(java.lang.String word)
                                    throws java.io.IOException
Description copied from interface: IIndex
Returns the paths of the documents whose names contain the given word.

Specified by:
queryInDocumentNames in interface IIndex
Throws:
java.io.IOException
See Also:
IIndex.queryInDocumentNames(java.lang.String)

queryPrefix

public IQueryResult[] queryPrefix(char[] prefix)
                           throws java.io.IOException
Description copied from interface: IIndex
Returns the paths of the documents containing the given word prefix.

Specified by:
queryPrefix in interface IIndex
Throws:
java.io.IOException
See Also:
IIndex.queryPrefix(char[])

queryEntriesMatching

public IEntryResult[] queryEntriesMatching(char[] prefix,
                                           boolean isCaseSensitive)
                                    throws java.io.IOException
Overloaded the method in Index to allow a user to specify if the query should be case sensitive.

Throws:
java.io.IOException

queryEntries

public IEntryResult[] queryEntries(char[] prefix,
                                   boolean isCaseSensitive)
                            throws java.io.IOException
Overloaded the method in Index to allow a user to specify if the query should be case sensitive.

Throws:
java.io.IOException

remove

public void remove(java.lang.String documentName)
            throws java.io.IOException
Description copied from interface: IIndex
Removes the corresponding document from the index.

Specified by:
remove in interface IIndex
Throws:
java.io.IOException
See Also:
IIndex.remove(java.lang.String)

remove

protected void remove(IndexedFile file,
                      int index)
               throws java.io.IOException
Removes the given document from the given index (MergeFactory.ADDS_INDEX for the in memory index, MergeFactory.OLD_INDEX for the index on the disk).

Throws:
java.io.IOException

save

public void save()
          throws java.io.IOException
Description copied from interface: IIndex
Saves the index on the disk.

Specified by:
save in interface IIndex
Throws:
java.io.IOException
See Also:
IIndex.save()

getBlocksIndexInput

protected BlocksIndexInput getBlocksIndexInput()

close

public void close()
Description copied from interface: IIndex
Closes the index file if open

Specified by:
close in interface IIndex

dispose

public void dispose()
Description copied from interface: IIndex
closes the index file then deletes it.

Specified by:
dispose in interface IIndex

timeToMerge

protected boolean timeToMerge()
Returns true if the in memory index reaches a critical size, to merge it with the index on the disk.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

setDoCache

public void setDoCache(boolean theDoCache)
Description copied from interface: IIndex
sets a boolean indicating the index file will be cached and should remain open and in-memory

Specified by:
setDoCache in interface IIndex

getCachedInput

public BlocksIndexInput getCachedInput()

setCachedInput

public void setCachedInput(BlocksIndexInput theCachedInput)

getResourceFileName

public java.lang.String getResourceFileName()


Copyright © 2011. All Rights Reserved.