org.mycore.backend.lucene
Class MCRLuceneSearcher

java.lang.Object
  extended by org.mycore.common.events.MCREventHandlerBase
      extended by org.mycore.services.fieldquery.MCRSearcher
          extended by org.mycore.backend.lucene.MCRLuceneSearcher
All Implemented Interfaces:
MCREventHandler, MCRShutdownHandler.Closeable

public class MCRLuceneSearcher
extends MCRSearcher
implements MCRShutdownHandler.Closeable

This class builds indexes from mycore meta data.

Author:
Harald Richter, Thomas Scheffler (yagee)

Field Summary
(package private) static org.apache.lucene.analysis.Analyzer analyzer
           
(package private) static int DEC_AFTER
           
(package private) static int DEC_BEFORE
           
(package private)  File IndexDir
           
(package private) static int INT_BEFORE
           
 
Fields inherited from class org.mycore.services.fieldquery.MCRSearcher
ID, index, prefix, RETURN_ID_CACHE
 
Constructor Summary
MCRLuceneSearcher()
           
 
Method Summary
 void addSortData(Iterator<MCRHit> hits, List<MCRSortBy> sortBy)
          Adds field values needed for sorting for those hits that do not have sort data set already.
 void addToIndex(String entryID, String returnID, List<MCRFieldValue> fields)
          Adds field values to the search index.
static org.apache.lucene.document.Document buildLuceneDocument(List<MCRFieldValue> fields)
          Build lucene document from transformed xml list
 void clearIndex()
          Removes all entries from index.
 void clearIndex(String fieldname, String value)
          Removes all entries of a field with a given value from index.
 void close()
          cleanly closes this object that implements Closeable.
 void deleteLuceneDocument(String fieldname, String id)
          Delete all documents in Lucene with id
static String handleNumber(String content, String type, long add)
           
 void init(String ID)
          Initializes the searcher and sets its unique ID.
 void notifySearcher(String mode)
          Inform Searcher what is going on.
 void removeFromIndex(String entryID)
          Removes the values of the given entry from the backend index.
 MCRResults search(MCRCondition condition, int maxResults, List<MCRSortBy> sortBy, boolean addSortData)
          As opposed to MCRSearcher the returned MCRResult is read only.
 String toString()
           
 
Methods inherited from class org.mycore.services.fieldquery.MCRSearcher
getID, getIndex, getReturnID, handleFileCreated, handleFileDeleted, handleFileRepaired, handleFileUpdated, handleObjectCreated, handleObjectDeleted, handleObjectRepaired, handleObjectUpdated, undoObjectCreated, undoObjectDeleted
 
Methods inherited from class org.mycore.common.events.MCREventHandlerBase
doHandleEvent, doNothing, handleClassificationCreated, handleClassificationDeleted, handleClassificationRepaired, handleClassificationUpdated, handleDerivateCreated, handleDerivateDeleted, handleDerivateRepaired, handleDerivateUpdated, undoClassificationCreated, undoClassificationDeleted, undoClassificationRepaired, undoClassificationUpdated, undoDerivateCreated, undoDerivateDeleted, undoDerivateRepaired, undoDerivateUpdated, undoFileCreated, undoFileDeleted, undoFileRepaired, undoFileUpdated, undoHandleEvent, undoObjectRepaired, undoObjectUpdated
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.mycore.common.events.MCREventHandler
doHandleEvent, undoHandleEvent
 

Field Detail

INT_BEFORE

static int INT_BEFORE

DEC_BEFORE

static int DEC_BEFORE

DEC_AFTER

static int DEC_AFTER

analyzer

static org.apache.lucene.analysis.Analyzer analyzer

IndexDir

File IndexDir
Constructor Detail

MCRLuceneSearcher

public MCRLuceneSearcher()
Method Detail

init

public void init(String ID)
Description copied from class: MCRSearcher
Initializes the searcher and sets its unique ID.

Overrides:
init in class MCRSearcher
Parameters:
ID - the non-null unique ID of this searcher instance

handleNumber

public static String handleNumber(String content,
                                  String type,
                                  long add)

removeFromIndex

public void removeFromIndex(String entryID)
Description copied from class: MCRSearcher
Removes the values of the given entry from the backend index. Searchers that need an indexer must overwrite this method to delete the values in their backend index. If this class is configured as event handler, this method is automatically called when objects are deleted or updated.

Overrides:
removeFromIndex in class MCRSearcher
Parameters:
entryID - the unique ID of this entry in the index

deleteLuceneDocument

public void deleteLuceneDocument(String fieldname,
                                 String id)
                          throws Exception
Delete all documents in Lucene with id

Parameters:
fieldname - string name of lucene field with stored id
id - string document id
indexDir - * the directory where index is stored
Throws:
Exception

search

public MCRResults search(MCRCondition condition,
                         int maxResults,
                         List<MCRSortBy> sortBy,
                         boolean addSortData)
As opposed to MCRSearcher the returned MCRResult is read only.

Specified by:
search in class MCRSearcher
maxResults - the maximum number of results to return, 0 means all results
sortBy - a not-null list of MCRSortBy sort criteria. The list is empty if the results should not be sorted
addSortData - if false, backend should sort results itself while executing the query. If this is not possible or the parameter is true, backend should not sort the results itself, but only store the data of the fields in the sortBy list which are needed to sort later
Returns:
the query results
See Also:
MCRSearcher.search(MCRCondition, int, List, boolean)

addToIndex

public void addToIndex(String entryID,
                       String returnID,
                       List<MCRFieldValue> fields)
Description copied from class: MCRSearcher
Adds field values to the search index. Searchers that need an indexer must overwrite this method to store the values in their backend index. If this class is configured as event handler, this method is automatically called when objects are created or updated. The field values have been extracted from the object's data as defined by searchfields.xml

Overrides:
addToIndex in class MCRSearcher
Parameters:
entryID - the unique ID of this entry in the index
returnID - the ID to return as result of a search (MCRHit ID)
fields - a List of MCRFieldValue objects

buildLuceneDocument

public static org.apache.lucene.document.Document buildLuceneDocument(List<MCRFieldValue> fields)
                                                               throws Exception
Build lucene document from transformed xml list

Parameters:
fields - corresponding to lucene fields
Returns:
The lucene document
Throws:
Exception

addSortData

public void addSortData(Iterator<MCRHit> hits,
                        List<MCRSortBy> sortBy)
Description copied from class: MCRSearcher
Adds field values needed for sorting for those hits that do not have sort data set already. Subclasses must overwrite this method, otherwise sorting results will not always work correctly. The default implementation in this class does nothing.

Overrides:
addSortData in class MCRSearcher
Parameters:
hits - the MCRHit objects that do not have sort data set
sortBy - the MCRFieldDef fields that are sort criteria

clearIndex

public void clearIndex()
Description copied from class: MCRSearcher
Removes all entries from index.

Overrides:
clearIndex in class MCRSearcher

clearIndex

public void clearIndex(String fieldname,
                       String value)
Description copied from class: MCRSearcher
Removes all entries of a field with a given value from index.

Overrides:
clearIndex in class MCRSearcher

notifySearcher

public void notifySearcher(String mode)
Description copied from class: MCRSearcher
Inform Searcher what is going on. Searcher can use this to speed up indexing. MCRLuceneSearcher for example uses a Ramdirectory rebuild insert ... finish

Overrides:
notifySearcher in class MCRSearcher

close

public void close()
Description copied from interface: MCRShutdownHandler.Closeable
cleanly closes this object that implements Closeable. You can provide some functionality to close open files and sockets or so.

Specified by:
close in interface MCRShutdownHandler.Closeable

toString

public String toString()
Overrides:
toString in class Object