org.tm4j.topicmap.index.text
Class LuceneIndexBase

java.lang.Object
  extended byorg.tm4j.topicmap.index.text.LuceneIndexBase
All Implemented Interfaces:
ConfigurableIndex, FullTextIndex, Index

public abstract class LuceneIndexBase
extends java.lang.Object
implements FullTextIndex, ConfigurableIndex

INTERNAL Abstract base class for FullTextIndexes using lucene for TextIndexing Concrete Implementations have to set an analyzer and directory implementation before starting the indexing. For building the index, utility methods for common topicMapObjects are available ( addDocument(...) ) these creates fields for not locator data, and Locators from Occurrences, adds object ids as unindexed fields.

Author:
Harald Kuhn, harald_kuhn at users.sourceforge.net

Field Summary
protected  boolean createNew
           
protected  org.apache.commons.logging.Log log
           
static java.lang.String OPT_LUCENE_ANALYZER
          The configuration property key for the property that specifies the full Java class name of the Lucene Analyzer to use for the full text index.
static java.lang.String OPT_LUCENE_DIR
          The configuration property key for the property that specifies the path name of the file-system directory to use for the full text index.
protected  TopicMap topicMap
           
 
Fields inherited from interface org.tm4j.topicmap.index.text.FullTextIndex
ID, LINK, PARENT_ID, VALUE
 
Constructor Summary
protected LuceneIndexBase(TopicMap topicMap)
           
 
Method Summary
protected  void addDocument(BaseName baseName)
           
protected  void addDocument(Occurrence occurrence)
           
protected  void addDocument(Topic topic)
           
protected  void addDocument(Variant variant)
           
protected  void buildIndex()
           
 void close()
          This method may cause the index to be dropped and any memory used to be freed.
 void configure(java.util.Properties props)
          Runtime configuration method invoked by the ConfigurableIndexProvider class.
protected  org.apache.lucene.document.Document createDocument(TopicMapObject object)
           
 QueryResult findByText(java.lang.String query, boolean includeURIs)
          This causes the FullTextIndex to be queried for the given query.
 org.apache.lucene.analysis.Analyzer getAnalyzer()
          Access method for the used Lucene Analyzer
 org.apache.lucene.store.Directory getDir()
          Access method for the used Lucene Directory
 boolean isOpen()
          Determines whether or not the index is accessible.
 void open()
          This method may cause the index to be initialised.
 void reindex()
          This method may cause the index to be regenerated.
 void setAnalyzer(org.apache.lucene.analysis.Analyzer analyzer)
          Set Method for the used Lucene Analyzer
 void setDir(org.apache.lucene.store.Directory dir)
          Set Method for the used Lucene Directory
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OPT_LUCENE_ANALYZER

public static final java.lang.String OPT_LUCENE_ANALYZER
The configuration property key for the property that specifies the full Java class name of the Lucene Analyzer to use for the full text index. This property key is "org.tm4j.topicmap.index.lucene.analyzer"

See Also:
Constant Field Values

OPT_LUCENE_DIR

public static final java.lang.String OPT_LUCENE_DIR
The configuration property key for the property that specifies the path name of the file-system directory to use for the full text index. If this property is not specified, the full-text index will be created in memory. This property key is "org.tm4j.topicmap.index.lucene.dir"

See Also:
Constant Field Values

log

protected org.apache.commons.logging.Log log

topicMap

protected TopicMap topicMap

createNew

protected boolean createNew
Constructor Detail

LuceneIndexBase

protected LuceneIndexBase(TopicMap topicMap)
Method Detail

findByText

public QueryResult findByText(java.lang.String query,
                              boolean includeURIs)
                       throws IndexException
Description copied from interface: FullTextIndex
This causes the FullTextIndex to be queried for the given query. The Hits are returned in a QueryResult object. The queries have to follow the syntax of the FullTextEngine used inside the implementation If no index is available or the index is corrupted, an IndexException is thrown

Specified by:
findByText in interface FullTextIndex
Parameters:
query - the Query String following the FullTextEngine Query Syntax
includeURIs - wether to also index uri´s
Returns:
a QueryResult containing all Hits encoutered by this query
Throws:
IndexException - thrown if no index is available or it is corrupted

open

public void open()
          throws IndexException
Description copied from interface: Index
This method may cause the index to be initialised. Indexes which are automatically initialised on the loading of their IndexProvider are not required to perform any operation in this method, but should still support it as a no-op.

Specified by:
open in interface Index
Throws:
IndexException - If some internal error prevents the index from being opened.

isOpen

public boolean isOpen()
Description copied from interface: Index
Determines whether or not the index is accessible.

Specified by:
isOpen in interface Index
Returns:
True if the index is accessible, false otherwise.

reindex

public void reindex()
             throws IndexException
Description copied from interface: Index
This method may cause the index to be regenerated. Indexes which automatically update are not required to perform any operation in response to this method, but should still support it as a no-op. Indexes which do not automatically update must either regenerate themselves or throw an IndexException or an UnsupportedOperationException.

Specified by:
reindex in interface Index
Throws:
IndexException - If some internal error prevents the index from being regenerated.

close

public void close()
           throws IndexException
Description copied from interface: Index
This method may cause the index to be dropped and any memory used to be freed. After a call to this method, any subsequent call to the same interface must fail.

Specified by:
close in interface Index
Throws:
IndexException

buildIndex

protected void buildIndex()
                   throws java.io.IOException
Throws:
java.io.IOException

addDocument

protected void addDocument(Topic topic)
                    throws java.io.IOException
Throws:
java.io.IOException

addDocument

protected void addDocument(BaseName baseName)
                    throws java.io.IOException
Throws:
java.io.IOException

addDocument

protected void addDocument(Variant variant)
                    throws java.io.IOException
Throws:
java.io.IOException

addDocument

protected void addDocument(Occurrence occurrence)
                    throws java.io.IOException
Throws:
java.io.IOException

createDocument

protected org.apache.lucene.document.Document createDocument(TopicMapObject object)

getAnalyzer

public org.apache.lucene.analysis.Analyzer getAnalyzer()
Access method for the used Lucene Analyzer

Returns:
the used analyzer

setAnalyzer

public void setAnalyzer(org.apache.lucene.analysis.Analyzer analyzer)
Set Method for the used Lucene Analyzer

Parameters:
analyzer - the new analyzer

getDir

public org.apache.lucene.store.Directory getDir()
Access method for the used Lucene Directory

Returns:
the used directory

setDir

public void setDir(org.apache.lucene.store.Directory dir)
Set Method for the used Lucene Directory

Parameters:
dir - the new directory

configure

public void configure(java.util.Properties props)
               throws IndexConfigurationException
Runtime configuration method invoked by the ConfigurableIndexProvider class. This method initialises the analyzer and directory implementations to be used by the index.

Specified by:
configure in interface ConfigurableIndex
Parameters:
props - the configuration properties passed to the ConfigurableIndexProvider.
Throws:
IndexConfigurationException - if a directory name was specified but the file-system directory index could not be opened or created.