fr.gouv.culture.sdx.search.lucene.query
Class LuceneIndex

java.lang.Object
  extended byfr.gouv.culture.sdx.utils.SdxObjectImpl
      extended byfr.gouv.culture.sdx.utils.lucene.LuceneDataStore
          extended byfr.gouv.culture.sdx.search.lucene.query.LuceneIndex
All Implemented Interfaces:
org.apache.avalon.framework.configuration.Configurable, Index, Index, org.apache.avalon.framework.logger.LogEnabled, java.rmi.Remote, SdxObject

public class LuceneIndex
extends LuceneDataStore
implements org.apache.avalon.framework.configuration.Configurable, Index

Information and services related to a LuceneIndex.

From here we can get an IndexReader, a Searcher, and know a little more about defined fields.


Field Summary
static int ACTION_ADD_DOCUMENT
          int representation of indexing action for adding a document.
protected  java.util.Date creationTimestamp
           
static int DEFAULT_MAX_FIELD_LENGTH
          Defaults for IndexWriter parameters; these are based on lucene defaults
static int DEFAULT_MAX_MERGE_DOCS
          Defaults for IndexWriter parameters; these are based on lucene defaults
static int DEFAULT_MERGE_FACTOR
          Defaults for IndexWriter parameters; these are based on lucene defaults
protected  java.util.Date lastModificationTimestamp
           
 
Fields inherited from class fr.gouv.culture.sdx.utils.lucene.LuceneDataStore
ALL_FIELD, ALL_VALUE, analyzer, fsd, fsdFile, ID_FIELD, LUCENE_CHECK_FILE, searcher, XML_LANG_FIELD
 
Fields inherited from class fr.gouv.culture.sdx.utils.SdxObjectImpl
encoding, logger
 
Constructor Summary
LuceneIndex(java.io.File dir, java.lang.String host, java.lang.Integer port, java.lang.String appId, java.lang.String dbId)
          Builds an index with fields definition and a path to the index files.
 
Method Summary
 void configure(org.apache.avalon.framework.configuration.Configuration configuration)
           
 void deleteDocument(java.lang.String docId)
          Deletes a document from the index.
protected  void freeResources()
          Free's the resources associated with this index USE WITH CARE!
 java.util.Date getCreationDate()
           
 Field getDefaultField()
          Returns the default field for this index.
 Field getField(java.lang.String name)
          Returns a field given a name.
 FieldsDefinition getFieldsDefinition()
          Returns a the FieldsDefinition for this index (basically a Hashtable of all the Fields)
 int getFieldType(java.lang.String name)
          Returns the type of a field.
 java.lang.String getFieldValue(IndexableDocument doc, java.lang.String fieldName)
           
 java.util.Date getLastModificationDate()
           
 java.util.Locale getLocale(java.lang.String name)
          Returns the locale for a field.
 MetaAnalyzer getMetaAnalyzer()
          Gets the MetaAnalyzer
 QueryParser getQueryParser()
           
 org.apache.lucene.index.IndexReader getReader()
          Returns an index reader for the current FSDirectory.
 java.lang.String getRemoteIndexName()
           
 org.apache.lucene.search.Searchable getSearcher()
          Gets a searcher.
protected  org.apache.lucene.index.IndexWriter getWriter(org.apache.lucene.store.Directory directory)
          Get's an IndexWriter based upon the analyzer class field and the provided Lucene Directory
 void init()
          Initializes the Lucene database.
 void mergeBatch()
          Merge's any batch in memory, if no batch then it optimizes the lucene index
 void optimize()
          Optimizeds the index for the current FSDirectory.
 void setMetaAnalyzer(MetaAnalyzer mAnalyzer)
          Sets the MetaAnalyzer
 void setParameters(LuceneIndexParameters params)
          Set's parameters for this lucene index
protected  void writeCreationTimestampFile()
           
 void writeDocument(org.apache.lucene.document.Document ldoc, boolean batchIndex)
          Stores a Lucene document within the database.
 void writeLastModificationTimestampFile(boolean create)
           
 
Methods inherited from class fr.gouv.culture.sdx.utils.lucene.LuceneDataStore
delete, delete, delete, delete, finalize, getFSDirectory, getIndexPath, getWriter, init, recycleSearcher, search, search, size, verifyIndex, write, writeLuceneData
 
Methods inherited from class fr.gouv.culture.sdx.utils.SdxObjectImpl
enableLogging, getChildLogger, setEncoding
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

creationTimestamp

protected java.util.Date creationTimestamp

lastModificationTimestamp

protected java.util.Date lastModificationTimestamp

ACTION_ADD_DOCUMENT

public static final int ACTION_ADD_DOCUMENT
int representation of indexing action for adding a document.

See Also:
Constant Field Values

DEFAULT_MAX_FIELD_LENGTH

public static final int DEFAULT_MAX_FIELD_LENGTH
Defaults for IndexWriter parameters; these are based on lucene defaults

See Also:
Constant Field Values

DEFAULT_MAX_MERGE_DOCS

public static final int DEFAULT_MAX_MERGE_DOCS
Defaults for IndexWriter parameters; these are based on lucene defaults

See Also:
Constant Field Values

DEFAULT_MERGE_FACTOR

public static final int DEFAULT_MERGE_FACTOR
Defaults for IndexWriter parameters; these are based on lucene defaults

See Also:
Constant Field Values
Constructor Detail

LuceneIndex

public LuceneIndex(java.io.File dir,
                   java.lang.String host,
                   java.lang.Integer port,
                   java.lang.String appId,
                   java.lang.String dbId)
            throws SDXException
Builds an index with fields definition and a path to the index files.

Parameters:
dir - A directory where the index is kept. TODOJavadoc
Method Detail

configure

public void configure(org.apache.avalon.framework.configuration.Configuration configuration)
               throws org.apache.avalon.framework.configuration.ConfigurationException
Specified by:
configure in interface org.apache.avalon.framework.configuration.Configurable
Throws:
org.apache.avalon.framework.configuration.ConfigurationException

init

public void init()
          throws SDXException
Initializes the Lucene database.

It the index exists, nothing is done here. If it is doesn't exist, it will be created.

Throws:
SDXException

writeCreationTimestampFile

protected void writeCreationTimestampFile()

writeLastModificationTimestampFile

public void writeLastModificationTimestampFile(boolean create)

getFieldType

public int getFieldType(java.lang.String name)
Returns the type of a field.

Parameters:
name - The name of the field for which the type is desired.
Returns:
The int field code (see Field doc)

getLocale

public java.util.Locale getLocale(java.lang.String name)
Returns the locale for a field.

Parameters:
name - The name of the field for which the Locale is desired.

getDefaultField

public Field getDefaultField()
Returns the default field for this index.

Specified by:
getDefaultField in interface Index

getField

public Field getField(java.lang.String name)
Returns a field given a name.

Specified by:
getField in interface Index
Parameters:
name - The name of the field for which the Field is desired.

getFieldsDefinition

public FieldsDefinition getFieldsDefinition()
Returns a the FieldsDefinition for this index (basically a Hashtable of all the Fields)


getSearcher

public org.apache.lucene.search.Searchable getSearcher()
Gets a searcher.

Specified by:
getSearcher in interface Index
Overrides:
getSearcher in class LuceneDataStore
Returns:
A lucene Searcher.

getMetaAnalyzer

public MetaAnalyzer getMetaAnalyzer()
Gets the MetaAnalyzer


setMetaAnalyzer

public void setMetaAnalyzer(MetaAnalyzer mAnalyzer)
                     throws SDXException
Sets the MetaAnalyzer

Parameters:
mAnalyzer - A MetaAnalyzer object containing a FieldsDefinition object for this index.
Throws:
SDXException

writeDocument

public void writeDocument(org.apache.lucene.document.Document ldoc,
                          boolean batchIndex)
                   throws SDXException
Stores a Lucene document within the database.

Parameters:
ldoc - The Lucene document to store.
batchIndex - Indicates wheter a tempBatch index is taking place or not. Useful for efficiency of index optimizations
Throws:
SDXException

deleteDocument

public void deleteDocument(java.lang.String docId)
                    throws SDXException
Deletes a document from the index.

Parameters:
docId - The document's id.
Throws:
SDXException

getQueryParser

public QueryParser getQueryParser()
                           throws java.io.IOException,
                                  SDXException
Specified by:
getQueryParser in interface Index
Throws:
java.io.IOException
SDXException

getRemoteIndexName

public java.lang.String getRemoteIndexName()

mergeBatch

public void mergeBatch()
                throws SDXException
Merge's any batch in memory, if no batch then it optimizes the lucene index

Throws:
SDXException

freeResources

protected void freeResources()
                      throws java.io.IOException
Free's the resources associated with this index USE WITH CARE!

Overrides:
freeResources in class LuceneDataStore
Throws:
java.io.IOException - Lucene IOExceptions

getWriter

protected org.apache.lucene.index.IndexWriter getWriter(org.apache.lucene.store.Directory directory)
                                                 throws java.io.IOException
Description copied from class: LuceneDataStore
Get's an IndexWriter based upon the analyzer class field and the provided Lucene Directory

Overrides:
getWriter in class LuceneDataStore
Parameters:
directory - The lucene directory for which the writer is desired
Returns:
IndexWriter
Throws:
java.io.IOException

setParameters

public void setParameters(LuceneIndexParameters params)
Set's parameters for this lucene index

Parameters:
params - The parameters relevent to this lucene index.

optimize

public void optimize()
              throws SDXException
Description copied from class: LuceneDataStore
Optimizeds the index for the current FSDirectory.

Overrides:
optimize in class LuceneDataStore
Throws:
SDXException

getReader

public org.apache.lucene.index.IndexReader getReader()
                                              throws SDXException
Description copied from class: LuceneDataStore
Returns an index reader for the current FSDirectory.

Overrides:
getReader in class LuceneDataStore
Throws:
SDXException

getFieldValue

public java.lang.String getFieldValue(IndexableDocument doc,
                                      java.lang.String fieldName)
                               throws SDXException
Throws:
SDXException

getCreationDate

public java.util.Date getCreationDate()

getLastModificationDate

public java.util.Date getLastModificationDate()


Copyright © 2000-2004 Ministere de la culture et de la communication / AJLSM. All Rights Reserved.