org.mycore.backend.jdom
Class MCRJDOMSearcher

java.lang.Object
  extended by org.mycore.common.events.MCREventHandlerBase
      extended by org.mycore.services.fieldquery.MCRSearcher
          extended by org.mycore.backend.jdom.MCRJDOMSearcher
All Implemented Interfaces:
MCREventHandler

public class MCRJDOMSearcher
extends MCRSearcher

Implements a searcher and indexer for MCRObject metadata using only data in memory without any persistent structures. When data is indexed, the values are stored as XML document in memory. When data is searched, the query is transformed to a XSL condition and run against the XML in memory. Before first use of instances of this class, all MCRObject metadata is loaded from persistent store and indexed in memory. This class may also be useful for learning how to implement MCRSearchers and indexers.

Author:
Frank Lützenkirchen

Field Summary
 
Fields inherited from class org.mycore.services.fieldquery.MCRSearcher
ID, index, prefix, RETURN_ID_CACHE
 
Constructor Summary
MCRJDOMSearcher()
           
 
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 fields)
          Adds field values to the search index.
static boolean compare(String valueA, String valueB, String operator)
          Implements a string compare operator as Xalan function extension
static boolean contains(String value, String words)
          Implements the contains operator as Xalan function extension
 void init(String ID)
          Initializes the searcher and sets its unique ID.
static boolean like(String value, String pattern)
          Implements the like operator as Xalan function extension
 void removeFromIndex(String entryID)
          Removes the values of the given entry from the backend index.
 MCRResults search(MCRCondition condition, int maxResults, List sortBy, boolean addSortData)
          Executes a query on this searcher.
 
Methods inherited from class org.mycore.services.fieldquery.MCRSearcher
clearIndex, clearIndex, getID, getIndex, getReturnID, handleFileCreated, handleFileDeleted, handleFileRepaired, handleFileUpdated, handleObjectCreated, handleObjectDeleted, handleObjectRepaired, handleObjectUpdated, notifySearcher, 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, toString, wait, wait, wait
 
Methods inherited from interface org.mycore.common.events.MCREventHandler
doHandleEvent, undoHandleEvent
 

Constructor Detail

MCRJDOMSearcher

public MCRJDOMSearcher()
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

addToIndex

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

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

search

public MCRResults search(MCRCondition condition,
                         int maxResults,
                         List sortBy,
                         boolean addSortData)
Description copied from class: MCRSearcher
Executes a query on this searcher. The query MUST only refer to fields that are managed by this searcher.

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

contains

public static boolean contains(String value,
                               String words)
Implements the contains operator as Xalan function extension


like

public static boolean like(String value,
                           String pattern)
Implements the like operator as Xalan function extension


compare

public static boolean compare(String valueA,
                              String valueB,
                              String operator)
Implements a string compare operator as Xalan function extension


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