org.openanzo.indexer.lucene
Class LuceneIndexerBase

java.lang.Object
  extended by org.openanzo.indexer.lucene.LuceneIndexerBase
All Implemented Interfaces:
IIndexer
Direct Known Subclasses:
LiteralIndexer, ModelIndexer

public abstract class LuceneIndexerBase
extends java.lang.Object
implements IIndexer

A very simple Lucene-based indexer. If this is going to be used for heavy-duty indexing, should queue up items to be indexed by another thread.

Author:
Wing Yung (wingyung@us.ibm.com)

Constructor Summary
LuceneIndexerBase()
           
 
Method Summary
 void clear()
          Clears the contents of the index.
 void close()
          Closes the resources used by the indexer.
abstract  boolean index(int id, java.lang.Object object)
          Adds the object to the index.
 void initialize(java.util.Properties properties)
          Initializes the indexer.
 void initialize(java.lang.String location, boolean indexClear, boolean removeLock)
          Initializes the indexer.
 void postIndex(int id)
          Flushes and optimizes the index.
 void postRemove(int id)
          Flushes and optimizes the index.
 int preIndex()
          A no-op.
 int preRemove()
          A no-op.
abstract  void remove(int id, java.lang.Object object)
          Removes the object from the index.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.openanzo.indexer.IIndexer
rebuild
 

Constructor Detail

LuceneIndexerBase

public LuceneIndexerBase()
Method Detail

index

public abstract boolean index(int id,
                              java.lang.Object object)
                       throws IndexerException
Description copied from interface: IIndexer
Adds the object to the index.

Specified by:
index in interface IIndexer
Parameters:
id - id of the indexer, generated by preIndex()
object - object to add to the index.
Returns:
true if indexing object was successfull
Throws:
IndexerException

remove

public abstract void remove(int id,
                            java.lang.Object object)
                     throws IndexerException
Description copied from interface: IIndexer
Removes the object from the index.

Specified by:
remove in interface IIndexer
Parameters:
id - id of the indexer, generated by preIndex()
object - object to remove from the index.
Throws:
IndexerException

initialize

public void initialize(java.util.Properties properties)
                throws IndexerException
Initializes the indexer. The properties object should contain the location of the directory containing the index (org.openanzo.indexer.lucene.indexLocation) and whether or not the index should be cleared upon initialization (org.openanzo.indexer.indexClear). Note that there are additional Lucene properties that can be set via Java system properties. For example, org.apache.lucene.writeLockTimeout (in ms)

Specified by:
initialize in interface IIndexer
Parameters:
properties - configuration for the indexer, usually comes from a .properties file
Throws:
IndexerException - if there were errors initializing the indexer

initialize

public void initialize(java.lang.String location,
                       boolean indexClear,
                       boolean removeLock)
                throws IndexerException
Initializes the indexer.

Parameters:
location - the location of the directory containing the index
indexClear - whether or not the index should be cleared upon initialization
removeLock - whether or not the index's lock should be removed upon initialization
Throws:
IndexerException

preIndex

public int preIndex()
             throws IndexerException
A no-op. IndexModifier takes care of all of the reading/writing in a threadsafe manner.

Specified by:
preIndex in interface IIndexer
Returns:
an identifier that is meant to be passed into index().
Throws:
IndexerException

postIndex

public void postIndex(int id)
               throws IndexerException
Flushes and optimizes the index.

Specified by:
postIndex in interface IIndexer
Parameters:
id - not used
Throws:
IndexerException

preRemove

public int preRemove()
              throws IndexerException
A no-op. IndexModifier takes care of all of the reading/writing in a threadsafe manner.

Specified by:
preRemove in interface IIndexer
Returns:
an identifier that is meant to be passed into remove().
Throws:
IndexerException

postRemove

public void postRemove(int id)
                throws IndexerException
Flushes and optimizes the index.

Specified by:
postRemove in interface IIndexer
Parameters:
id - not used
Throws:
IndexerException

clear

public void clear()
           throws IndexerException
Description copied from interface: IIndexer
Clears the contents of the index.

Specified by:
clear in interface IIndexer
Throws:
IndexerException

close

public void close()
           throws IndexerException
Closes the resources used by the indexer. Closes the IndexModifier.

Specified by:
close in interface IIndexer
Throws:
IndexerException


Copyright © 2007 Cambridge Semantics Inc.. All Rights Reserved.