org.apache.lucene.gdata.search.index
Class GDataIndexer

java.lang.Object
  extended by org.apache.lucene.gdata.search.index.GDataIndexer

public class GDataIndexer
extends Object

A GDataIndexer encapsulates every writing access to the search index.

Insert, updates and deletes to the index happens inside this class. All modification will be base on an instance of IndexDocument which contains all informations and command for the indexer.
Although this class provides methods to add, remove and update document in the index all IndexDocument instances should be added to the task queue via the addIndexableDocumentTask(Future) method. Inside this class runs an instance of IndexTask listening on this queue. The analysis of the actual documents happens inside the com.sun.corba.se.impl.orbutil.closure.Future object added to the queue. This enables the indexer to do his actual work. Documents will be build / analyzed concurrently while already finished tasks can be added to the index.

Author:
Simon Willnauer

Field Summary
protected  java.util.concurrent.atomic.AtomicInteger committed
           
protected  java.util.concurrent.atomic.AtomicInteger docsAdded
           
protected  java.util.concurrent.atomic.AtomicInteger docsDeleted
           
protected  java.util.concurrent.atomic.AtomicInteger docsUpdated
           
protected  java.util.concurrent.BlockingQueue<java.util.concurrent.Future<IndexDocument>> futurQueue
           
protected  org.apache.lucene.gdata.search.index.IndexTask indexTask
           
protected  java.util.concurrent.atomic.AtomicInteger optimized
           
protected  IndexSearcher searcher
           
protected  IndexWriter writer
           
 
Constructor Summary
protected GDataIndexer(IndexSchema schema, Directory dir, boolean create)
           
 
Method Summary
protected  void addDocument(IndexDocument indexable)
           
 void addIndexableDocumentTask(java.util.concurrent.Future<IndexDocument> task)
          Adds the given future task to the queue, and waits if the queue is full.
protected  void closeSearcher()
           
protected  void closeWriter()
           
protected  void commit(boolean optimize)
          This method commits all changes to the index and closes all open resources (e.g.
static GDataIndexer createGdataIndexer(IndexSchema config, Directory dir, boolean create)
          This factory method creates a new GDataIndexer using a instance of IndexTask
static GDataIndexer createTimedGdataIndexer(IndexSchema config, Directory dir, boolean create, long commitTimeout)
          This factory method creates a new GDataIndexer using a instance of TimedIndexTask.
protected  void deleteDocument(IndexDocument indexable)
           
protected  void destroy()
           
protected  void doDeltete()
           
protected  void doWrite(IndexDocument document)
           
protected  void init()
           
protected  void notifyCommitListeners(String serviceId)
           
protected  void openSearcher()
           
protected  void openWriter()
           
 void registerIndexEventListener(IndexEventListener listener)
          Registers a new IndexEventListener.
 void removeIndexEventListener(IndexEventListener listener)
          Removes a registered IndexEventListener
protected  void setIndexTask(org.apache.lucene.gdata.search.index.IndexTask task)
           
protected  void updateDocument(IndexDocument indexable)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

writer

protected IndexWriter writer

searcher

protected IndexSearcher searcher

committed

protected java.util.concurrent.atomic.AtomicInteger committed

optimized

protected java.util.concurrent.atomic.AtomicInteger optimized

docsAdded

protected java.util.concurrent.atomic.AtomicInteger docsAdded

docsUpdated

protected java.util.concurrent.atomic.AtomicInteger docsUpdated

docsDeleted

protected java.util.concurrent.atomic.AtomicInteger docsDeleted

futurQueue

protected final java.util.concurrent.BlockingQueue<java.util.concurrent.Future<IndexDocument>> futurQueue

indexTask

protected org.apache.lucene.gdata.search.index.IndexTask indexTask
Constructor Detail

GDataIndexer

protected GDataIndexer(IndexSchema schema,
                       Directory dir,
                       boolean create)
                throws IOException
Throws:
IOException
Method Detail

setIndexTask

protected void setIndexTask(org.apache.lucene.gdata.search.index.IndexTask task)

init

protected void init()

addIndexableDocumentTask

public void addIndexableDocumentTask(java.util.concurrent.Future<IndexDocument> task)
                              throws InterruptedException
Adds the given future task to the queue, and waits if the queue is full. The queue size is set to 100 by default.

Parameters:
task - - the task to be scheduled
Throws:
InterruptedException - - if the queue is interrupted

addDocument

protected void addDocument(IndexDocument indexable)
                    throws IOException
Throws:
IOException

updateDocument

protected void updateDocument(IndexDocument indexable)
                       throws IOException
Throws:
IOException

deleteDocument

protected void deleteDocument(IndexDocument indexable)

commit

protected void commit(boolean optimize)
               throws IOException
This method commits all changes to the index and closes all open resources (e.g. IndexWriter and IndexReader). This method notifies all registered Commit listeners if invoked.

Parameters:
optimize - - true if the index should be optimized on this commit
Throws:
IOException - - if an IOException occurs

registerIndexEventListener

public void registerIndexEventListener(IndexEventListener listener)
Registers a new IndexEventListener. All registered listeners will be notified if the index has been committed.

Parameters:
listener - - the listener to register

removeIndexEventListener

public void removeIndexEventListener(IndexEventListener listener)
Removes a registered IndexEventListener

Parameters:
listener - - the listener to remove

notifyCommitListeners

protected void notifyCommitListeners(String serviceId)

closeWriter

protected void closeWriter()
                    throws IOException
Throws:
IOException

closeSearcher

protected void closeSearcher()
                      throws IOException
Throws:
IOException

openSearcher

protected void openSearcher()
                     throws IOException
Throws:
IOException

openWriter

protected void openWriter()
                   throws IOException
Throws:
IOException

doWrite

protected void doWrite(IndexDocument document)
                throws IOException
Throws:
IOException

doDeltete

protected void doDeltete()
                  throws IOException
Throws:
IOException

destroy

protected void destroy()
                throws IOException
Throws:
IOException

createGdataIndexer

public static GDataIndexer createGdataIndexer(IndexSchema config,
                                              Directory dir,
                                              boolean create)
                                       throws IOException
This factory method creates a new GDataIndexer using a instance of IndexTask

Parameters:
config - - the config to be used to configure the indexer
dir - - the directory to index to
create - - true to create a new index, false to use the existing one.
Returns:
- a new GDataIndexer instance
Throws:
IOException - - if an IOException occurs while initializing the indexer

createTimedGdataIndexer

public static GDataIndexer createTimedGdataIndexer(IndexSchema config,
                                                   Directory dir,
                                                   boolean create,
                                                   long commitTimeout)
                                            throws IOException
This factory method creates a new GDataIndexer using a instance of TimedIndexTask. This indexer will automatically commit the index if no modification to the index occur for the given time. The used time unit is TimeUnit.SECONDS. Values less than the default value will be ignored. For the default value see TimedIndexTask.

Parameters:
config - - the config to be used to configure the indexer
dir - - the directory to index to
create - - true to create a new index, false to use the existing one.
commitTimeout - - the amount of seconds to wait until a commit should be scheduled
Returns:
- a new GDataIndexer instance
Throws:
IOException - - if an IOException occurs while initializing the indexer


Copyright © 2000-2008 Apache Software Foundation. All Rights Reserved.