org.hibernate.search.backend
Class Workspace

java.lang.Object
  extended by org.hibernate.search.backend.Workspace

public class Workspace
extends Object

Lucene workspace for a DirectoryProvider.

Author:
Emmanuel Bernard, Hardy Ferentschik, Sanne Grinovero

Constructor Summary
Workspace(SearchFactoryImplementor searchFactoryImplementor, DirectoryProvider<?> provider)
           
 
Method Summary
 void closeIndexReader()
          Closes a previously opened IndexReader.
 void closeIndexWriter()
          Closes a previously opened IndexWriter.
 void commitIndexWriter()
          Commits changes to a previously opened index writer.
 org.apache.lucene.analysis.Analyzer getAnalyzer(String name)
           
<T> DocumentBuilderIndexedEntity<T>
getDocumentBuilder(Class<T> entity)
           
 Set<Class<?>> getEntitiesInDirectory()
           
 org.apache.lucene.index.IndexReader getIndexReader()
          Gets an IndexReader to alter the index, opening one if needed.
 org.apache.lucene.index.IndexWriter getIndexWriter(boolean batchmode)
          Gets the IndexWriter, opening one if needed.
 void incrementModificationCounter(int modCount)
          Increment the counter of modification operations done on the index.
 void lock()
          Acquires a lock on the DirectoryProvider backing this Workspace; this is required to use getIndexWriter(boolean), closeIndexWriter(), getIndexReader(), closeIndexReader().
 void optimize()
          Used by OptimizeLuceneWork after index optimization to flag that optimization has been forced.
 void optimizerPhase()
          If optimization has not been forced give a change to configured OptimizerStrategy to optimize the index.
 void unlock()
          Releases the lock obtained by calling lock()
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Workspace

public Workspace(SearchFactoryImplementor searchFactoryImplementor,
                 DirectoryProvider<?> provider)
Method Detail

getDocumentBuilder

public <T> DocumentBuilderIndexedEntity<T> getDocumentBuilder(Class<T> entity)

getAnalyzer

public org.apache.lucene.analysis.Analyzer getAnalyzer(String name)

optimizerPhase

public void optimizerPhase()
If optimization has not been forced give a change to configured OptimizerStrategy to optimize the index.

Throws:
org.hibernate.annotations.common.AssertionFailure - if the lock is not owned or if an IndexReader is open.

optimize

public void optimize()
Used by OptimizeLuceneWork after index optimization to flag that optimization has been forced.

See Also:
OptimizeLuceneWork, SearchFactory.optimize(), SearchFactory.optimize(Class)

getIndexReader

public org.apache.lucene.index.IndexReader getIndexReader()
Gets an IndexReader to alter the index, opening one if needed. The caller needs to own the lock relevant to this DirectoryProvider.

Returns:
a new IndexReader or one already open.
Throws:
org.hibernate.annotations.common.AssertionFailure - if an IndexWriter is open or if the lock is not owned.
See Also:
lock()

closeIndexReader

public void closeIndexReader()
Closes a previously opened IndexReader.

Throws:
SearchException - on IOException during Lucene close operation.
org.hibernate.annotations.common.AssertionFailure - if the lock is not owned or if there is no IndexReader to close.
See Also:
getIndexReader()

getIndexWriter

public org.apache.lucene.index.IndexWriter getIndexWriter(boolean batchmode)
Gets the IndexWriter, opening one if needed.

Parameters:
batchmode - when true the indexWriter settings for batch mode will be applied. Ignored if IndexWriter is open already.
Returns:
a new IndexWriter or one already open.
Throws:
org.hibernate.annotations.common.AssertionFailure - if an IndexReader is open or the lock is not owned.
SearchException - on a IOException during index opening.

commitIndexWriter

public void commitIndexWriter()
Commits changes to a previously opened index writer.

Throws:
SearchException - on IOException during Lucene close operation.
org.hibernate.annotations.common.AssertionFailure - if there is no IndexWriter to close, or if the lock is not owned.

closeIndexWriter

public void closeIndexWriter()
Closes a previously opened IndexWriter.

Throws:
SearchException - on IOException during Lucene close operation.
org.hibernate.annotations.common.AssertionFailure - if there is no IndexWriter to close, or if the lock is not owned.

incrementModificationCounter

public void incrementModificationCounter(int modCount)
Increment the counter of modification operations done on the index. Used (currently only) by the OptimizerStrategy.

Parameters:
modCount - the increment to add to the counter.

getEntitiesInDirectory

public Set<Class<?>> getEntitiesInDirectory()
Returns:
The unmodifiable set of entity types being indexed in the underlying Lucene Directory backing this Workspace.

lock

public void lock()
Acquires a lock on the DirectoryProvider backing this Workspace; this is required to use getIndexWriter(boolean), closeIndexWriter(), getIndexReader(), closeIndexReader().

See Also:
getIndexWriter(boolean), closeIndexWriter(), getIndexReader(), closeIndexReader()

unlock

public void unlock()
Releases the lock obtained by calling lock()

Throws:
org.hibernate.annotations.common.AssertionFailure - when unlocking without having closed IndexWriter or IndexReader.
See Also:
lock()


Copyright © 2011 Hibernate. All Rights Reserved.