org.apache.cocoon.components.search.components.impl
Class AbstractIndexer

java.lang.Object
  extended by org.apache.avalon.framework.logger.AbstractLogEnabled
      extended by org.apache.cocoon.components.search.components.impl.AbstractIndexer
All Implemented Interfaces:
org.apache.avalon.excalibur.pool.Poolable, org.apache.avalon.excalibur.pool.Recyclable, org.apache.avalon.framework.logger.LogEnabled, Indexer
Direct Known Subclasses:
DefaultIndexerImpl, ParallelIndexerImpl

public abstract class AbstractIndexer
extends org.apache.avalon.framework.logger.AbstractLogEnabled
implements Indexer, org.apache.avalon.excalibur.pool.Recyclable

Abstract Indexer

Author:
Nicolas Maisonneuve

Field Summary
protected  org.apache.lucene.index.IndexWriter add_writer
           
protected  org.apache.lucene.analysis.Analyzer analyzer
          the lucene Analyzer (see lucene doc)
protected  boolean clear_mode
          clear mode (if true the index will be cleared)
protected  org.apache.lucene.index.IndexReader delete_reader
           
protected  org.apache.lucene.store.Directory dir
          lucene Directory (see lucene doc)
protected  int mergeFactor
          MergeFactor (see lucene doc)
 
Fields inherited from interface org.apache.cocoon.components.search.components.Indexer
DOCUMENT_UID_FIELD, ROLE
 
Constructor Summary
AbstractIndexer()
           
 
Method Summary
protected abstract  void addDocument(org.apache.lucene.document.Document doc)
           
protected  void addDocument(org.apache.lucene.index.IndexWriter writer, org.apache.lucene.document.Document document)
          add document to the index
 void clearIndex()
          clear the index
protected  void closeReader()
          Close reader
protected  void closeWriter()
          Close writer
 int del(java.lang.String uid)
          Delete document
protected  int deleteDocument(org.apache.lucene.index.IndexReader deleter, java.lang.String uid)
          Delete document
 org.apache.lucene.analysis.Analyzer getAnalyzer()
          Get the lucene analyzer
 org.apache.lucene.store.Directory getIndex()
           
 int getMergeFactor()
           
 void index(org.apache.lucene.document.Document doc)
          Index document (update or add if Indexer.clearIndex() is called before)
protected  void openIndexReader()
          Open Index Reader
protected  void openIndexWriter(boolean create)
          Open the index Writer
 void optimize()
          Optimize the index
 void recycle()
          recylcle this object
protected  void release()
          releasing resources
 void setAnalyzer(org.apache.lucene.analysis.Analyzer analyzer)
          Set a lucene analyzer
 void setIndex(org.apache.lucene.store.Directory dir)
          Set the index directory
 void setMergeFactor(int value)
          Set a merge factor value + set minMergeDocs=2*mergeFactor (see lucene docs)
protected  void switchToADD_MODE(boolean clear)
          Switch to write mode (close read, open writer ) if it's not already done
protected  void switchToDEL_MODE()
          Switch to del mode (close writer, open reader ) if it's not already done
protected abstract  void updateDocument(org.apache.lucene.document.Document doc)
           
 
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

analyzer

protected org.apache.lucene.analysis.Analyzer analyzer
the lucene Analyzer (see lucene doc)


dir

protected org.apache.lucene.store.Directory dir
lucene Directory (see lucene doc)


mergeFactor

protected int mergeFactor
MergeFactor (see lucene doc)


clear_mode

protected boolean clear_mode
clear mode (if true the index will be cleared)


delete_reader

protected org.apache.lucene.index.IndexReader delete_reader

add_writer

protected org.apache.lucene.index.IndexWriter add_writer
Constructor Detail

AbstractIndexer

public AbstractIndexer()
Method Detail

setMergeFactor

public void setMergeFactor(int value)
Description copied from interface: Indexer
Set a merge factor value + set minMergeDocs=2*mergeFactor (see lucene docs)

Specified by:
setMergeFactor in interface Indexer
Parameters:
value - the new merge factor

getMergeFactor

public int getMergeFactor()
Specified by:
getMergeFactor in interface Indexer
Returns:
the mergeFactor

getIndex

public org.apache.lucene.store.Directory getIndex()
Specified by:
getIndex in interface Indexer

setIndex

public void setIndex(org.apache.lucene.store.Directory dir)
              throws IndexException
Description copied from interface: Indexer
Set the index directory

Specified by:
setIndex in interface Indexer
Parameters:
dir - the index directory
Throws:
IndexException

setAnalyzer

public void setAnalyzer(org.apache.lucene.analysis.Analyzer analyzer)
Description copied from interface: Indexer
Set a lucene analyzer

Specified by:
setAnalyzer in interface Indexer
Parameters:
analyzer - the analazer

getAnalyzer

public org.apache.lucene.analysis.Analyzer getAnalyzer()
Description copied from interface: Indexer
Get the lucene analyzer

Specified by:
getAnalyzer in interface Indexer

updateDocument

protected abstract void updateDocument(org.apache.lucene.document.Document doc)
                                throws IndexException
Throws:
IndexException

addDocument

protected abstract void addDocument(org.apache.lucene.document.Document doc)
                             throws IndexException
Throws:
IndexException

index

public void index(org.apache.lucene.document.Document doc)
           throws IndexException
Description copied from interface: Indexer
Index document (update or add if Indexer.clearIndex() is called before)

Specified by:
index in interface Indexer
Parameters:
doc - Document
Throws:
IndexException

del

public int del(java.lang.String uid)
        throws IndexException
Description copied from interface: Indexer
Delete document

Specified by:
del in interface Indexer
Parameters:
uid - the uid of the document
Returns:
int the number of deleted documents
Throws:
IndexException

deleteDocument

protected final int deleteDocument(org.apache.lucene.index.IndexReader deleter,
                                   java.lang.String uid)
                            throws IndexException
Delete document

Parameters:
deleter - the lucene indexreader to delete document
uid - the uid of the doucment to be deleted
Returns:
the number of deleted documents
Throws:
IndexException

addDocument

protected final void addDocument(org.apache.lucene.index.IndexWriter writer,
                                 org.apache.lucene.document.Document document)
                          throws IndexException
add document to the index

Parameters:
writer - the lucene indexwriter
document - the document to be indexed
Throws:
IndexException

optimize

public void optimize()
              throws IndexException
Description copied from interface: Indexer
Optimize the index

Specified by:
optimize in interface Indexer
Throws:
IndexException

clearIndex

public void clearIndex()
                throws IndexException
Description copied from interface: Indexer
clear the index

Specified by:
clearIndex in interface Indexer
Throws:
IndexException

release

protected void release()
                throws IndexException
releasing resources

Throws:
IndexException

recycle

public void recycle()
recylcle this object

Specified by:
recycle in interface org.apache.avalon.excalibur.pool.Recyclable

switchToADD_MODE

protected final void switchToADD_MODE(boolean clear)
                               throws IndexException
Switch to write mode (close read, open writer ) if it's not already done

Parameters:
clear - clear index
Throws:
IndexException

switchToDEL_MODE

protected final void switchToDEL_MODE()
                               throws IndexException
Switch to del mode (close writer, open reader ) if it's not already done

Throws:
IndexException

openIndexWriter

protected final void openIndexWriter(boolean create)
                              throws IndexException
Open the index Writer

Parameters:
create - clear index or not
Throws:
IndexException

openIndexReader

protected final void openIndexReader()
                              throws IndexException
Open Index Reader

Throws:
IndexException

closeWriter

protected final void closeWriter()
                          throws IndexException
Close writer

Throws:
IndexException

closeReader

protected final void closeReader()
                          throws IndexException
Close reader

Throws:
IndexException


Copyright $ Apache Software Foundation. All Rights Reserved.