maiolum.xml.index
Class BibleModuleIndexer

java.lang.Object
  extended bymaiolum.xml.index.BibleModuleIndexer
All Implemented Interfaces:
VerseDocumentObserver

public class BibleModuleIndexer
extends java.lang.Object
implements VerseDocumentObserver

Used to perform bible documents reindexing using Lucene. This class should be used to start reindexing single document (represented in the filesystem or by DOM) or all BibleModules located in ModuleManager.


Field Summary
private  java.lang.String baseIndexPath
          Base directory, where index is located
private  BibleContentHandler contentHandler
          Used to create Document objects from Bible XML documents.
private  Edition defaultEdition
          Default Edition for indexed modules.
private  org.apache.lucene.index.IndexWriter indexWriter
          IndexWriter to store Lucene Document objects, that were parsed from the bible XML file.
private static org.apache.log4j.Logger logger
           
private  org.xml.sax.XMLReader parser
          XML parser used to parse given XML document.
 
Constructor Summary
BibleModuleIndexer()
          Default constructor.
BibleModuleIndexer(java.lang.String baseIndexPath)
          Instantiates new BibleModuleIndexer using parameter for base location of index.
 
Method Summary
 java.lang.String getBaseIndexPath()
          Sets base directory, where the index will be located
 Edition getDefaultEdition()
          Get default Edition for the parsed XML bible document
 void mergeIndices(java.io.File indicesParentDir, java.io.File mainIndexDir)
          Merges all indices located in the subdirectories into one larger.
 void reindex(org.xml.sax.InputSource source, java.io.File indexDirectory)
          Reindexes bible document in the DOM InputSource representation to given directory.
 void reindex(ModuleManager m)
          Reindexes all BibleModules in the ModuleManager to base index directory.
 void reindex(java.lang.String systemID, java.io.File indexDirectory)
          Reindexes bible document identified by system ID to given directory.
 void reindex(XMLBibleModule module)
          Reindexes given XML BibleModule to base index directory.
 void retrieveVerse(org.apache.lucene.document.Document doc)
          Observer of the BibleContentHandler.
 void setBaseIndexPath(java.lang.String value)
          Returns base directory, where index is located
 void setDefaultEdition(Edition defaultEdition)
          Set default Edition for the parsed XML bible document
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

private static org.apache.log4j.Logger logger

baseIndexPath

private java.lang.String baseIndexPath
Base directory, where index is located


defaultEdition

private Edition defaultEdition
Default Edition for indexed modules.


contentHandler

private BibleContentHandler contentHandler
Used to create Document objects from Bible XML documents.


parser

private org.xml.sax.XMLReader parser
XML parser used to parse given XML document.


indexWriter

private org.apache.lucene.index.IndexWriter indexWriter
IndexWriter to store Lucene Document objects, that were parsed from the bible XML file.

Constructor Detail

BibleModuleIndexer

public BibleModuleIndexer()
Default constructor. Instantiates XML parser and associated BibleContentHandler.


BibleModuleIndexer

public BibleModuleIndexer(java.lang.String baseIndexPath)
Instantiates new BibleModuleIndexer using parameter for base location of index.

Method Detail

reindex

public void reindex(java.lang.String systemID,
                    java.io.File indexDirectory)
             throws java.io.IOException,
                    ParseException
Reindexes bible document identified by system ID to given directory.

Parameters:
systemID - specifies location (typically in the filesystem) of document to be indexed.
indexDirectory - fully qualified path to the directory, where will be the index created
Throws:
java.io.IOException - when I/O problem is encountered while creating index
ParseException - when source document cannot be properly parsed

reindex

public void reindex(org.xml.sax.InputSource source,
                    java.io.File indexDirectory)
             throws java.io.IOException,
                    ParseException
Reindexes bible document in the DOM InputSource representation to given directory.

Parameters:
source - represents document DOM representation
indexDirectory - fully qualified path to the directory, where will be the index created
Throws:
java.io.IOException - when I/O problem is encountered while creating index
ParseException - when source document cannot be properly parsed

reindex

public void reindex(ModuleManager m)
             throws java.io.IOException,
                    ParseException
Reindexes all BibleModules in the ModuleManager to base index directory. Use setBaseIndexPath(String) to set the target directory for index. Each module in the ModuleManager will be indexed into separate index, while this indexes are located in the subdirectories of the base index directory. Names of these subdirectories are set according to hash value of BibleModule URI (using Object.hashCode()).

You can merge multiple indices into one larger using mergeIndices(File, File) method.

Throws:
java.io.IOException
ParseException

reindex

public void reindex(XMLBibleModule module)
             throws java.io.IOException,
                    ParseException
Reindexes given XML BibleModule to base index directory. Use setBaseIndexPath(String) to set the target directory for index. The module will be indexed subdirectory of base directory, the name is set according to hash value of BibleModule URI (using Object.hashCode()).

You can merge multiple indices into one larger using mergeIndices(File, File) method.

Throws:
java.io.IOException
ParseException

mergeIndices

public void mergeIndices(java.io.File indicesParentDir,
                         java.io.File mainIndexDir)
                  throws java.io.IOException
Merges all indices located in the subdirectories into one larger.

Parameters:
indicesParentDir - is the directory, which contains multiple subdirectories -- each of these subdirectories should hold one index.
mainIndexDir - represents target directory into which will the partial indices be merged.
Throws:
java.io.IOException

retrieveVerse

public void retrieveVerse(org.apache.lucene.document.Document doc)
Observer of the BibleContentHandler. This method is called whenever a Lucene Document is parsed from XML Bible Document. The "parsed" Lucene document is written into current index.

Specified by:
retrieveVerse in interface VerseDocumentObserver

getBaseIndexPath

public java.lang.String getBaseIndexPath()
Sets base directory, where the index will be located


setBaseIndexPath

public void setBaseIndexPath(java.lang.String value)
Returns base directory, where index is located


getDefaultEdition

public Edition getDefaultEdition()
Get default Edition for the parsed XML bible document


setDefaultEdition

public void setDefaultEdition(Edition defaultEdition)
Set default Edition for the parsed XML bible document