public class LuceneDatabase extends LuceneDataStore implements Database
For a detailed description of the database abstraction in SDX, please see the Database interface.
When creating a LuceneDatabase object, these steps should be followed :
SdxObject.ConfigurationNode| Modifier and Type | Field and Description |
|---|---|
protected java.lang.String |
DATABASE_DIR_NAME |
protected java.lang.String |
id |
ALL_FIELD, ALL_VALUE, analyzer, fsd, fsdFile, ID_FIELD, searcher, useCompoundFiles, XML_LANG_FIELD_configuration, _context, _description, _encoding, _id, _locale, _logger, _manager, _xmlizable_objects, _xmlLang, isToSaxInitializedCLASS_NAME_SUFFIX, DATABASE_DIR_PATH, PACKAGE_QUALNAME, SEARCH_MODE_AND, SEARCH_MODE_NOT, SEARCH_MODE_ORDEFAULT_ENCODINGALL_SAVE_ATTRIB, PATH_ATTRIB, SAVE_DIRECTORY_PARAM| Constructor and Description |
|---|
LuceneDatabase() |
LuceneDatabase(java.io.File dir)
Gets or creates a _database stored at a given dir.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addProperty(java.lang.String entityId,
java.lang.String propertyName,
java.lang.String propertyValue)
If the entity does not exist the method fails silently
|
void |
backup(SaveParameters save_config)
Save Lucene files
|
void |
configure(org.apache.avalon.framework.configuration.Configuration configuration) |
void |
delete(DatabaseEntity ent)
Deletes an entity from the database.
|
void |
delete(DatabaseEntity[] entities) |
void |
empty()
Empties the _database.
|
boolean |
entityExists(java.lang.String id)
Checks whether an entity with the provided id exists within this database
|
protected java.lang.String |
getClassNameSuffix()
Sub classes should element this method to return their class name suffix for SAX output
|
DatabaseConnection |
getConnection() |
java.lang.String |
getDatabaseDirectoryName()
If the database is a directory based file system implemenation like lucene
this method should return a valid name for a directory which may be created to house
the database, or in the case of hsql it will return a valid table name
|
DatabaseEntity[] |
getEntities()
Returns the list of entities within the database.
|
protected DatabaseEntity |
getEntity(org.apache.lucene.document.Document ldoc)
Builds an entity from a Lucene document.
|
DatabaseEntity |
getEntity(java.lang.String id)
Returns an entity for a given id.
|
java.lang.String |
getIndexPath()
Return's the absolute path for the
directory in which the database resides
|
Property[] |
getProperties(java.lang.String entityId)
Returns all properties from an entity in the database.
|
java.lang.String |
getProperty(java.lang.String documentId,
java.lang.String property)
Searches database for a given document id, and then returns the content of the specified field.
|
java.lang.String |
getPropertyValue(java.lang.String entityId,
java.lang.String name)
Returns a property value from an entity in the database.
|
java.lang.String[] |
getPropertyValues(java.lang.String entityId,
java.lang.String propertyName)
Returns a repeatable property from an entity in the database.
|
java.lang.String |
getWildcardSearchToken()
Returns a String representing the
appropriate wildcard search token
for the implementation
|
void |
init()
Initializes the Lucene database.
|
protected boolean |
initToSax()
Init the LinkedHashMap _xmlizable_objects with the objects in order to describ them in XML
|
void |
optimize()
Optimizeds the index for the current FSDirectory.
|
void |
releaseConnection(DatabaseConnection conn) |
void |
removeProperty(java.lang.String propertyName,
java.lang.String propertyValue)
Removes a property with the provided name and value from the
and EXISTING entity having the name/value pair
It is up to the implementation to determine proper
behavior if the entity with the provided id does not exist.
|
void |
removeProperty(java.lang.String entityId,
java.lang.String propertyName,
java.lang.String propertyValue)
If the entity does not exist the method fails silently
|
void |
restore(SaveParameters save_config)
Restore Lucene files
|
void |
save(DatabaseEntity entity)
Saves an entity within the database.
|
java.lang.String[] |
search(org.apache.avalon.framework.parameters.Parameters params)
Returns an array of database entity ids based upon the
provided search parameters
One can used Database.getEntity(id) after retrieving a
list of ids with this method.
|
java.lang.String[] |
search(org.apache.avalon.framework.parameters.Parameters params,
int mode) |
long |
size()
Returns the number of entities within this database.
|
void |
update(DatabaseEntity ent)
Updates an entity.
|
protected void |
write(org.apache.lucene.document.Document lDoc)
Writes a document to the index
|
delete, delete, delete, delete, finalize, freeResources, getFSDirectory, getFSDirectory, getReader, getSearcher, getWriter, getWriter, getWriter, getWriter, init, initVolatileObjectsToSax, isUsingCompoundFiles, recycleSearcher, search, search, verifyIndex, writeLuceneDataconfigureDescription, contextualize, enableLogging, getBaseAttributes, getConfiguration, getContext, getDescription, getEncoding, getId, getLocale, getLog, getServiceManager, getXmlLang, service, setDescription, setEncoding, setId, setLocale, setUpSdxObject, setUpSdxObject, setXmlLang, toSAX, verifyConfigurationResourcesclone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetId, setIdgetDescription, setDescriptiongetEncoding, setEncodinggetLocale, getXmlLang, setLocale, setXmlLangprotected java.lang.String DATABASE_DIR_NAME
protected java.lang.String id
public LuceneDatabase()
public LuceneDatabase(java.io.File dir)
throws SDXException
One should call the enableLogging() method before using this database, otherwise errors won't be logged.
Most of all, you should call the init() method to make sure that the database can be used.
dir - The directory where the Lucene database is stored.SDXExceptionpublic void init()
throws SDXException
It the database exists, nothing is done here. If it is doesn't exist, it will be created.
init in interface DatabaseSDXExceptionpublic java.lang.String getProperty(java.lang.String documentId,
java.lang.String property)
throws SDXException
documentId - The id of the document to search for.property - The field name, or the property to search for.SDXExceptionpublic DatabaseEntity getEntity(java.lang.String id) throws SDXException
getEntity in interface Databaseid - The entity's id.null if no entity has this id.SDXExceptionpublic DatabaseEntity[] getEntities() throws SDXException
getEntities in interface DatabaseSDXExceptionprotected DatabaseEntity getEntity(org.apache.lucene.document.Document ldoc) throws SDXException
ldoc - The Lucene document.SDXExceptionpublic void save(DatabaseEntity entity) throws SDXException
save in interface Databaseentity - The entity to save.SDXExceptionprotected void write(org.apache.lucene.document.Document lDoc)
throws SDXException
LuceneDataStorewrite in class LuceneDataStorelDoc - The lucene document to addSDXExceptionpublic java.lang.String getPropertyValue(java.lang.String entityId,
java.lang.String name)
throws SDXException
getPropertyValue in interface DatabaseentityId - The needed entity's id.name - The property's name for the desired value.null. If the property is
defined more than once, the first value is returned.SDXExceptionpublic java.lang.String[] getPropertyValues(java.lang.String entityId,
java.lang.String propertyName)
throws SDXException
Please note that this method currently doesn't work for Lucene, which still stores (?) and retrieves only the last added repeatable property.TODO:remove this note after we commit our lucene changes
getPropertyValues in interface DatabaseentityId - The needed entity's name.propertyName - The needed property's name.null if this
property is not defined for this entity.SDXExceptionpublic Property[] getProperties(java.lang.String entityId) throws SDXException
getProperties in interface DatabaseentityId - The entity's id.SDXExceptionpublic void delete(DatabaseEntity ent) throws SDXException
delete in interface Databaseent - The entity to delete (must have an id).
A new DatabaseEntity can be created with the id set to the
id of the entity desired for deletion and then this new entity
can be passed to this method and the appropriate entity corresponding
to that id will be deleted.SDXExceptionpublic void delete(DatabaseEntity[] entities) throws SDXException
SDXExceptionpublic void update(DatabaseEntity ent) throws SDXException
update in interface Databaseent - The entity to update.SDXExceptiondelete(fr.gouv.culture.sdx.utils.database.DatabaseEntity),
save(fr.gouv.culture.sdx.utils.database.DatabaseEntity)public long size()
size in interface Databasesize in class LuceneDataStorepublic void empty()
throws SDXException
empty in interface DatabaseSDXExceptionpublic java.lang.String getIndexPath()
LuceneDataStoregetIndexPath in class LuceneDataStorepublic void optimize()
throws SDXException
LuceneDataStoreoptimize in interface Databaseoptimize in class LuceneDataStoreSDXExceptionpublic boolean entityExists(java.lang.String id)
DatabaseentityExists in interface Databaseid - _identifier of the entitypublic java.lang.String[] search(org.apache.avalon.framework.parameters.Parameters params)
throws SDXException
Databasesearch in interface Databaseparams - search paramsSDXExceptionpublic java.lang.String[] search(org.apache.avalon.framework.parameters.Parameters params,
int mode)
throws SDXException
search in interface DatabaseSDXExceptionpublic void configure(org.apache.avalon.framework.configuration.Configuration configuration)
throws org.apache.avalon.framework.configuration.ConfigurationException
configure in interface org.apache.avalon.framework.configuration.Configurableconfigure in class AbstractSdxObjectorg.apache.avalon.framework.configuration.ConfigurationExceptionpublic java.lang.String getDatabaseDirectoryName()
DatabasegetDatabaseDirectoryName in interface Databasepublic DatabaseConnection getConnection() throws SDXException
getConnection in interface DatabaseSDXExceptionpublic void releaseConnection(DatabaseConnection conn) throws SDXException
releaseConnection in interface DatabaseSDXExceptionpublic void addProperty(java.lang.String entityId,
java.lang.String propertyName,
java.lang.String propertyValue)
throws SDXException
addProperty in interface DatabaseentityId - propertyName - propertyValue - SDXExceptionpublic void removeProperty(java.lang.String entityId,
java.lang.String propertyName,
java.lang.String propertyValue)
throws SDXException
removeProperty in interface DatabaseentityId - propertyName - propertyValue - SDXExceptionpublic void removeProperty(java.lang.String propertyName,
java.lang.String propertyValue)
throws SDXException
DatabaseremoveProperty in interface DatabasepropertyName - The property to removepropertyValue - The property valueSDXExceptionprotected java.lang.String getClassNameSuffix()
AbstractSdxObjectgetClassNameSuffix in class AbstractSdxObjectpublic java.lang.String getWildcardSearchToken()
DatabasegetWildcardSearchToken in interface Databaseprotected boolean initToSax()
AbstractSdxObjectinitToSax in class LuceneDataStorepublic void backup(SaveParameters save_config) throws SDXException
LuceneDataStorebackup in interface Saveablebackup in class LuceneDataStoreSDXExceptionSaveable.backup(fr.gouv.culture.sdx.utils.save.SaveParameters)public void restore(SaveParameters save_config) throws SDXException
LuceneDataStorerestore in interface Saveablerestore in class LuceneDataStoreSDXExceptionSaveable.restore(fr.gouv.culture.sdx.utils.save.SaveParameters)Copyright © 2000-2010 Ministere de la culture et de la communication / AJLSM. All Rights Reserved.