org.terrier.matching
Class QueryResultSet

java.lang.Object
  extended by org.terrier.matching.CollectionResultSet
      extended by org.terrier.matching.QueryResultSet
All Implemented Interfaces:
java.io.Serializable, ResultSet

public class QueryResultSet
extends CollectionResultSet

A result set for a given query. This result set is created for a given number of documents, usually the number of retrieved documents for a query. Initially, it is created by cropping an instance of the CollectionResultSet, that is used in the Matching classes.
This class has support for adding metadata as well.

Author:
Vassilis Plachouras, Craig Macdonald
See Also:
Serialized Form

Field Summary
protected  java.lang.String[][] metadata
          The structure holding the metadata.
protected  gnu.trove.TObjectIntHashMap<java.lang.String> metaMap
          The structure that holds the metadata about the results.
 
Fields inherited from class org.terrier.matching.CollectionResultSet
arraysInitialised, docids, exactResultSize, lock, occurrences, resultSize, scores, statusCode
 
Constructor Summary
QueryResultSet(int numberOfDocuments)
          A default constructor for the result set with a given number of documents.
QueryResultSet(int[] docids, double[] ds, short[] occurrences)
           
 
Method Summary
 void addMetaItem(java.lang.String name, int index, java.lang.String value)
          Adds a metadata value for a given document
 void addMetaItems(java.lang.String name, java.lang.String[] values)
          Adds the metadata values for all the documents in the result set.
protected  int addMetaType(java.lang.String name)
          Get the metadata index for the given name
 java.lang.String getMetaItem(java.lang.String name, int index)
          Gets a metadata value for a given document.
 java.lang.String[] getMetaItems(java.lang.String name)
          Gets the metadata information for all documents.
 java.lang.String[] getMetaKeys()
          Returns the names of the meta keys which this resultset has
 ResultSet getResultSet(int[] positions)
          Extracts a subset of the resultset given by the list parameter, which contains a list of positions in the resultset that should be saved.
 ResultSet getResultSet(int startPosition, int length)
          Crops the existing result file and extracts a subset from the given starting point to the ending point.
 boolean hasMetaItems(java.lang.String name)
          Returns true if the resultset already has a set of metaitems with the specified name.
 void initialise()
          Initialises the arrays prior of retrieval.
protected  QueryResultSet makeNewResultSet(int length)
           
 
Methods inherited from class org.terrier.matching.CollectionResultSet
getDocids, getExactResultSize, getLock, getOccurrences, getResultSize, getScores, getStatusCode, initialise, setExactResultSize, setResultSize, setStatusCode
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

metaMap

protected gnu.trove.TObjectIntHashMap<java.lang.String> metaMap
The structure that holds the metadata about the results. It maps the metadata name, a string, to an array index of the metadata array that contains the particular metadata.


metadata

protected java.lang.String[][] metadata
The structure holding the metadata. Each column is associated with a named metavalue type, as known by metaMap. Each row is for a given document.

Constructor Detail

QueryResultSet

public QueryResultSet(int numberOfDocuments)
A default constructor for the result set with a given number of documents.

Parameters:
numberOfDocuments - the number of documents contained in the result set.

QueryResultSet

public QueryResultSet(int[] docids,
                      double[] ds,
                      short[] occurrences)
Method Detail

initialise

public void initialise()
Initialises the arrays prior of retrieval. Only the first time it is called, it will allocate memory for the arrays.

Specified by:
initialise in interface ResultSet
Overrides:
initialise in class CollectionResultSet

addMetaItem

public void addMetaItem(java.lang.String name,
                        int index,
                        java.lang.String value)
Adds a metadata value for a given document

Specified by:
addMetaItem in interface ResultSet
Overrides:
addMetaItem in class CollectionResultSet
Parameters:
name - the name of the metadata type. For example, it can be url for adding the URLs of documents.
index - the position in the resultset array of the given document
value - the metadata value.

addMetaItems

public void addMetaItems(java.lang.String name,
                         java.lang.String[] values)
Adds the metadata values for all the documents in the result set. The length of the metadata array values should be equal to the length of the docids array. The array must be sorted in the same way as the resultset (descending score)

Specified by:
addMetaItems in interface ResultSet
Overrides:
addMetaItems in class CollectionResultSet
Parameters:
name - the name of the metadata type. For example, it can be url for adding the URLs of documents.
values - the metadata values.

getMetaItem

public java.lang.String getMetaItem(java.lang.String name,
                                    int index)
Gets a metadata value for a given document. If the requested metadata information is not specified, then we return null.

Specified by:
getMetaItem in interface ResultSet
Overrides:
getMetaItem in class CollectionResultSet
Parameters:
name - the name of the metadata type.
index - the postition in the array
Returns:
a string with the metadata information, or null of the metadata is not available.

getMetaItems

public java.lang.String[] getMetaItems(java.lang.String name)
Gets the metadata information for all documents. If the requested metadata information is not specified, then we return null.

Specified by:
getMetaItems in interface ResultSet
Overrides:
getMetaItems in class CollectionResultSet
Parameters:
name - the name of the metadata type.
Returns:
an array of strings with the metadata information, or null of the metadata is not available.

hasMetaItems

public boolean hasMetaItems(java.lang.String name)
Description copied from class: CollectionResultSet
Returns true if the resultset already has a set of metaitems with the specified name.

Specified by:
hasMetaItems in interface ResultSet
Overrides:
hasMetaItems in class CollectionResultSet
Parameters:
name - of the desired metaitem set
Returns:
true if the set exists.

getMetaKeys

public java.lang.String[] getMetaKeys()
Returns the names of the meta keys which this resultset has

Specified by:
getMetaKeys in interface ResultSet
Overrides:
getMetaKeys in class CollectionResultSet

addMetaType

protected int addMetaType(java.lang.String name)
Get the metadata index for the given name

Parameters:
name - The name of the metadata type to add on
Returns:
Integer of the place in the metadata array it should be stored in

makeNewResultSet

protected QueryResultSet makeNewResultSet(int length)

getResultSet

public ResultSet getResultSet(int startPosition,
                              int length)
Crops the existing result file and extracts a subset from the given starting point to the ending point.

Specified by:
getResultSet in interface ResultSet
Overrides:
getResultSet in class CollectionResultSet
Parameters:
startPosition - the beginning of the subset.
length - the number of entries to get.
Returns:
a subset of the current result set.

getResultSet

public ResultSet getResultSet(int[] positions)
Extracts a subset of the resultset given by the list parameter, which contains a list of positions in the resultset that should be saved.

Specified by:
getResultSet in interface ResultSet
Overrides:
getResultSet in class CollectionResultSet
Parameters:
positions - int[] the list of elements in the current list that should be kept.
Returns:
a subset of the current result set specified by the list.


Terrier 3.5. Copyright © 2004-2011 University of Glasgow