dk.kb.dup.xsltIndexer
Class IndexLoader

java.lang.Object
  extended by dk.kb.dup.xsltIndexer.IndexLoader

public class IndexLoader
extends java.lang.Object

This class is the glue between the Xalan XSLT processor and Lucene. The various methods of the class are used as function inside the XSLT script which makes the actual job.

Version:
Last $Revision$ $Date$ by $Author$. Current checkout was made as build $Name$
Author:
Sigfrid Lundberg (slu@kb.dk)

Constructor Summary
IndexLoader()
           
 
Method Summary
 void add_field(java.lang.String field, java.lang.String value, java.lang.String storeField, java.lang.String indexField)
          This is the real work horse of the IndexLoader.
 void add_xml_field(java.lang.String field, org.w3c.dom.traversal.NodeIterator valueIterator, java.lang.String storeField, java.lang.String indexField)
          Similar to add_field, but instead of accepting a text field as arguement it takes a XSLT node-set.
 void close_document()
          Closes the current Lucene document.
 void close_index()
          This method used to close the index and optimize it.
 void delete_documents(java.lang.String dataSourceField, java.lang.String dataSourceId)
          Deletes all Lucene documents in the index which have "dataSourceId" stored in "dataSourceField".
 java.lang.String encode_uri(java.lang.String str)
           
 void open_document()
          Creates a new Lucene document.
 void open_index(java.lang.String mode, java.lang.String directory, java.lang.String debug)
          This method tells the IndexLoader to open an index using a given mode (update or create) in the directory given as an argument either of the --update or --create in the command line.
 void setAnalyzer(Analyzer analyzer)
           
 void setIndexReader(IndexReader reader)
           
 void setIndexWriter(IndexWriter writer)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IndexLoader

public IndexLoader()
Method Detail

open_index

public void open_index(java.lang.String mode,
                       java.lang.String directory,
                       java.lang.String debug)
This method tells the IndexLoader to open an index using a given mode (update or create) in the directory given as an argument either of the --update or --create in the command line. debug is the debug level (currently 0,1,2,3). The method used to instantiates a Lucene Analyzer. This is now done in the Driver class (currently it is a SimpleAnalyzer):

Parameters:
debug -
directory -
mode -

setAnalyzer

public void setAnalyzer(Analyzer analyzer)

open_document

public void open_document()
Creates a new Lucene document. All subsequent calls to the add_field method will refer to this document. See Lucene Document javadoc


add_field

public void add_field(java.lang.String field,
                      java.lang.String value,
                      java.lang.String storeField,
                      java.lang.String indexField)

This is the real work horse of the IndexLoader. It adds "value" to "field".

Lucene stores it (for retrieval purposes) if storeField is anything but store.no (typically store.yes) for the readability of the XSL. Please refer to Field.Store in the Lucene javadoc.

The field may be indexed for searching purposes depending on the indexField parameter. It may take any of the following four values: "tokenized" (the default), "index.no", "un_tokenized" and "no_norms". "index.no" would be used for data which shouldn't be used for searching but still are useful for presentation purposes. "tokenized" splits the text in tokens (typically words) that may be searched individually or as strings. "un_tokenized" is used when the text should be searched as a string only. This is the case for a record ID. Please refer to Field.Index in the Lucene javadoc.

Parameters:
indexField -
storeField -
value -
field -

add_xml_field

public void add_xml_field(java.lang.String field,
                          org.w3c.dom.traversal.NodeIterator valueIterator,
                          java.lang.String storeField,
                          java.lang.String indexField)
Similar to add_field, but instead of accepting a text field as arguement it takes a XSLT node-set. It means that you may store XML fragments taken from the source document in the lucene index for presentation purposes.

All nodes in a node set are copied to a new XML document having the root element <fragment> ... </fragment>

Parameters:
indexField -
storeField -
valueIterator -
field -

close_document

public void close_document()
Closes the current Lucene document. I.e., the Lucene will add it to the index.


close_index

public void close_index()
This method used to close the index and optimize it. These functions have moved to the driver class, and the method will be deprecated in some future version of this software.


setIndexReader

public void setIndexReader(IndexReader reader)
Parameters:
IndexReader - reader the IndexReader is now instantiated in the Driver, and is passed to us Xalan. This gives us a tremendous performance boost.

setIndexWriter

public void setIndexWriter(IndexWriter writer)
Parameters:
IndexWriter - writer the IndexWriter is now instantiated in the Driver, and is passed to us Xalan. This gives us a tremendous performance boost.

delete_documents

public void delete_documents(java.lang.String dataSourceField,
                             java.lang.String dataSourceId)
Deletes all Lucene documents in the index which have "dataSourceId" stored in "dataSourceField".

Parameters:
dataSourceId -
dataSourceField -

encode_uri

public java.lang.String encode_uri(java.lang.String str)
Parameters:
String - str Any string you want to URI encode
Returns:
URI encoded string. The java.net.URLEncoder is much better than the one built into most exslt compatible xslt processors.