org.mycore.services.fieldquery
Class MCRHit

java.lang.Object
  extended by org.mycore.services.fieldquery.MCRHit

public class MCRHit
extends Object

Represents a single result hit of a query. The hit has an ID which is the MCRObjectID of the document that matched the query. The hit may have MCRFieldValue objects set for sorting data or representing hit metadata like score or rank. If the same hit (hit with same ID) is in different result sets A and B, the data of the hit objects is merged. The hit sort data is copied from one of the hits that contains sort data. There is only on sort data set for each hit. The hit metadata of both hits is preserved and copied from both hits, so there can be multiple metadata sets from different searches for the same hit.

Author:
Arne Seifert, Frank Lützenkirchen
See Also:
MCRResults

Field Summary
static String LOCAL
          Identifies a hit that comes from the local server
(package private) static Logger LOGGER
          logger
 
Constructor Summary
MCRHit(String id)
          Creates a new result hit with the given object ID
 
Method Summary
 void addMetaData(MCRFieldValue value)
          Adds hit metadata like score or rank
 void addSortData(MCRFieldValue fieldValue)
          Adds data for sorting this hit
 Element buildXML()
          Creates a XML representation of this hit and its sort data and meta data
(package private)  int compareTo(MCRFieldDef field, MCRHit other)
          Compares this hit with another hit by comparing the value of the given search field.
 String getHost()
          Returns the alias of the host where this hit comes from
 String getID()
          Returns the ID of the object that matched the query
 String getKey()
          Returns a combination of ID and host alias to be used as key
 List<MCRFieldValue> getMetaData()
           
 List<MCRFieldValue> getSortData()
           
(package private)  boolean hasSortData()
          Returns true if this MCRHit has any sort data added
 void merge(MCRHit other)
          Merges the data of a MCRHit object with the same ID to the data of this MCRHit object.
(package private) static MCRHit parseXML(Element xml, String hostAlias)
          Parses a XML representation of a hit and its sort data and meta data
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

LOGGER

static Logger LOGGER
logger


LOCAL

public static final String LOCAL
Identifies a hit that comes from the local server

See Also:
Constant Field Values
Constructor Detail

MCRHit

public MCRHit(String id)
Creates a new result hit with the given object ID

Parameters:
id - the ID of the object that matched the query
Method Detail

getID

public String getID()
Returns the ID of the object that matched the query

Returns:
the ID of the object that matched the query

getHost

public String getHost()
Returns the alias of the host where this hit comes from

Returns:
the remote host alias, or MCRHit.LOCAL

getKey

public String getKey()
Returns a combination of ID and host alias to be used as key

Returns:
a unique key for this MCRHit

addMetaData

public void addMetaData(MCRFieldValue value)
Adds hit metadata like score or rank

Parameters:
value - the value of the metadata field

addSortData

public void addSortData(MCRFieldValue fieldValue)
Adds data for sorting this hit

Parameters:
fieldValue - the value of a sortable search field

hasSortData

boolean hasSortData()
Returns true if this MCRHit has any sort data added


getSortData

public List<MCRFieldValue> getSortData()

getMetaData

public List<MCRFieldValue> getMetaData()

compareTo

int compareTo(MCRFieldDef field,
              MCRHit other)
Compares this hit with another hit by comparing the value of the given search field. Used for sorting results.

Parameters:
field - the field to compare
other - the other hit to compare with
Returns:
0 if the two hits are equal, a positive value if this hit is "greater" than the other, a negative value if this hit is "smaller" than the other
See Also:
MCRResults.sortBy(List)

merge

public void merge(MCRHit other)
Merges the data of a MCRHit object with the same ID to the data of this MCRHit object. The sort data and meta data of the other hit is added to this object's data.

Parameters:
other - the other hit

buildXML

public Element buildXML()
Creates a XML representation of this hit and its sort data and meta data

Returns:
a 'hit' element with attribute 'id', optionally one 'sortData' child element and multiple 'metaData' child elements

parseXML

static MCRHit parseXML(Element xml,
                       String hostAlias)
Parses a XML representation of a hit and its sort data and meta data

Parameters:
xml - the XML element
hostAlias - the remote host alias
Returns:
the parsed MCRHit object

toString

public String toString()
Overrides:
toString in class Object