org.mycore.services.fieldquery
Class MCRSearcher

java.lang.Object
  extended by org.mycore.common.events.MCREventHandlerBase
      extended by org.mycore.services.fieldquery.MCRSearcher
All Implemented Interfaces:
MCREventHandler
Direct Known Subclasses:
MCRJDOMSearcher, MCRLuceneSearcher, MCROldLuceneSearcher

public abstract class MCRSearcher
extends MCREventHandlerBase
implements MCREventHandler

Abstract base class for searchers and indexers. Searcher implementations for a specific backend must be implemented as a subclass. This class implements MCREventHandler. Indexers can easily be implemented by overwriting the two methods addToIndex and removeFromIndex. Searchers are implemented by overwriting the method search. Searchers that do not need indexing or do this on their own can simply ignore the add/remove methods.

Author:
Frank Lützenkirchen

Field Summary
protected  String ID
          The unique searcher ID for this MCRSearcher implementation
protected  String index
          The ID of the index this searcher handles *
static Logger LOGGER
          The logger
protected  String prefix
          The prefix of all properties in mycore.properties for this searcher
protected static MCRCache RETURN_ID_CACHE
           
 
Constructor Summary
MCRSearcher()
           
 
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.
 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.
 String getID()
          Returns the unique store ID that was set for this store instance
 String getIndex()
          Returns the ID of the index this searcher is configured for.
 String getReturnID(MCRFile file)
           
protected  void handleFileCreated(MCREvent evt, MCRFile file)
          Handles file created events.
protected  void handleFileDeleted(MCREvent evt, MCRFile file)
          Handles file deleted events.
protected  void handleFileRepaired(MCREvent evt, MCRFile file)
          Handles file repair events.
protected  void handleFileUpdated(MCREvent evt, MCRFile file)
          Handles file updated events.
protected  void handleObjectCreated(MCREvent evt, MCRObject obj)
          Handles object created events.
protected  void handleObjectDeleted(MCREvent evt, MCRObject obj)
          Handles object deleted events.
protected  void handleObjectRepaired(MCREvent evt, MCRObject obj)
          Handles object repair events.
protected  void handleObjectUpdated(MCREvent evt, MCRObject obj)
          Handles object updated events.
 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.
abstract  MCRResults search(MCRCondition condition, int maxResults, List<MCRSortBy> sortBy, boolean addSortData)
          Executes a query on this searcher.
protected  void undoObjectCreated(MCREvent evt, MCRObject obj)
          Handles undo of object created events.
protected  void undoObjectDeleted(MCREvent evt, MCRObject obj)
          Handles undo of object deleted events.
 
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, toString, wait, wait, wait
 
Methods inherited from interface org.mycore.common.events.MCREventHandler
doHandleEvent, undoHandleEvent
 

Field Detail

LOGGER

public static Logger LOGGER
The logger


ID

protected String ID
The unique searcher ID for this MCRSearcher implementation


prefix

protected String prefix
The prefix of all properties in mycore.properties for this searcher


index

protected String index
The ID of the index this searcher handles *


RETURN_ID_CACHE

protected static MCRCache RETURN_ID_CACHE
Constructor Detail

MCRSearcher

public MCRSearcher()
Method Detail

init

public void init(String ID)
Initializes the searcher and sets its unique ID.

Parameters:
ID - the non-null unique ID of this searcher instance

getID

public String getID()
Returns the unique store ID that was set for this store instance

Returns:
the unique store ID that was set for this store instance

getIndex

public String getIndex()
Returns the ID of the index this searcher is configured for.


getReturnID

public String getReturnID(MCRFile file)

handleFileCreated

protected void handleFileCreated(MCREvent evt,
                                 MCRFile file)
Description copied from class: MCREventHandlerBase
Handles file created events. This implementation does nothing and should be overwritted by subclasses.

Overrides:
handleFileCreated in class MCREventHandlerBase
Parameters:
evt - the event that occured
file - the MCRFile that caused the event

handleFileUpdated

protected void handleFileUpdated(MCREvent evt,
                                 MCRFile file)
Description copied from class: MCREventHandlerBase
Handles file updated events. This implementation does nothing and should be overwritted by subclasses.

Overrides:
handleFileUpdated in class MCREventHandlerBase
Parameters:
evt - the event that occured
file - the MCRFile that caused the event

handleFileDeleted

protected void handleFileDeleted(MCREvent evt,
                                 MCRFile file)
Description copied from class: MCREventHandlerBase
Handles file deleted events. This implementation does nothing and should be overwritted by subclasses.

Overrides:
handleFileDeleted in class MCREventHandlerBase
Parameters:
evt - the event that occured
file - the MCRFile that caused the event

handleFileRepaired

protected void handleFileRepaired(MCREvent evt,
                                  MCRFile file)
Description copied from class: MCREventHandlerBase
Handles file repair events. This implementation does nothing and should be overwritted by subclasses.

Overrides:
handleFileRepaired in class MCREventHandlerBase
Parameters:
evt - the event that occured
file - the MCRFile that caused the event

handleObjectCreated

protected void handleObjectCreated(MCREvent evt,
                                   MCRObject obj)
Description copied from class: MCREventHandlerBase
Handles object created events. This implementation does nothing and should be overwritted by subclasses.

Overrides:
handleObjectCreated in class MCREventHandlerBase
Parameters:
evt - the event that occured
obj - the MCRObject that caused the event

handleObjectUpdated

protected void handleObjectUpdated(MCREvent evt,
                                   MCRObject obj)
Description copied from class: MCREventHandlerBase
Handles object updated events. This implementation does nothing and should be overwritted by subclasses.

Overrides:
handleObjectUpdated in class MCREventHandlerBase
Parameters:
evt - the event that occured
obj - the MCRObject that caused the event

handleObjectDeleted

protected void handleObjectDeleted(MCREvent evt,
                                   MCRObject obj)
Description copied from class: MCREventHandlerBase
Handles object deleted events. This implementation does nothing and should be overwritted by subclasses.

Overrides:
handleObjectDeleted in class MCREventHandlerBase
Parameters:
evt - the event that occured
obj - the MCRObject that caused the event

handleObjectRepaired

protected void handleObjectRepaired(MCREvent evt,
                                    MCRObject obj)
Description copied from class: MCREventHandlerBase
Handles object repair events. This implementation does nothing and should be overwritted by subclasses.

Overrides:
handleObjectRepaired in class MCREventHandlerBase
Parameters:
evt - the event that occured
obj - the MCRObject that caused the event

undoObjectCreated

protected void undoObjectCreated(MCREvent evt,
                                 MCRObject obj)
Description copied from class: MCREventHandlerBase
Handles undo of object created events. This implementation does nothing and should be overwritted by subclasses.

Overrides:
undoObjectCreated in class MCREventHandlerBase
Parameters:
evt - the event that occured
obj - the MCRObject that caused the event

undoObjectDeleted

protected void undoObjectDeleted(MCREvent evt,
                                 MCRObject obj)
Description copied from class: MCREventHandlerBase
Handles undo of object deleted events. This implementation does nothing and should be overwritted by subclasses.

Overrides:
undoObjectDeleted in class MCREventHandlerBase
Parameters:
evt - the event that occured
obj - the MCRObject that caused the event

addToIndex

public void addToIndex(String entryID,
                       String returnID,
                       List<MCRFieldValue> fields)
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

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

removeFromIndex

public void removeFromIndex(String entryID)
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.

Parameters:
entryID - the unique ID of this entry in the index

search

public abstract MCRResults search(MCRCondition condition,
                                  int maxResults,
                                  List<MCRSortBy> sortBy,
                                  boolean addSortData)
Executes a query on this searcher. The query MUST only refer to fields that are managed by this searcher.

Parameters:
cond - the query condition
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

addSortData

public 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. Subclasses must overwrite this method, otherwise sorting results will not always work correctly. The default implementation in this class does nothing.

Parameters:
hits - the MCRHit objects that do not have sort data set
sortBy - the MCRFieldDef fields that are sort criteria

clearIndex

public void clearIndex()
Removes all entries from index.


clearIndex

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


notifySearcher

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