Package org.terrier.matching
Class QueryResultSet
- java.lang.Object
-
- org.terrier.matching.CollectionResultSet
-
- org.terrier.matching.QueryResultSet
-
- All Implemented Interfaces:
java.io.Serializable,ResultSet
- Direct Known Subclasses:
FatQueryResultSet,FeaturedQueryResultSet
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
Fields Modifier and Type Field Description protected java.lang.String[][]metadataThe structure holding the metadata.protected gnu.trove.TObjectIntHashMap<java.lang.String>metaMapThe 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
Constructors Constructor Description 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddMetaItem(java.lang.String name, int index, java.lang.String value)Adds a metadata value for a given documentvoidaddMetaItems(java.lang.String name, java.lang.String[] values)Adds the metadata values for all the documents in the result set.protected intaddMetaType(java.lang.String name)Get the metadata index for the given namejava.lang.String[][]allMetaItems()returns all metadata, indexed first by metadata type, then by rank.java.lang.StringgetMetaItem(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 hasResultSetgetResultSet(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.ResultSetgetResultSet(int startPosition, int length)Crops the existing result file and extracts a subset from the given starting point to the ending point.booleanhasMetaItems(java.lang.String name)does the metaindex have a particular type of metadata?voidinitialise()Initialises the arrays prior of retrieval.protected QueryResultSetmakeNewResultSet(int length)voidsort()Sorts all documents in this resultset by descending scorevoidsort(int topDocs)Sorts the top topDocs document in this resultset be first.-
Methods inherited from class org.terrier.matching.CollectionResultSet
getDocids, getExactResultSize, getLock, getOccurrences, getResultSize, getScores, getStatusCode, initialise, setExactResultSize, setResultSize, setStatusCode
-
-
-
-
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:
initialisein interfaceResultSet- Overrides:
initialisein classCollectionResultSet
-
addMetaItem
public void addMetaItem(java.lang.String name, int index, java.lang.String value)Adds a metadata value for a given document- Specified by:
addMetaItemin interfaceResultSet- Overrides:
addMetaItemin classCollectionResultSet- 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 documentvalue- 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:
addMetaItemsin interfaceResultSet- Overrides:
addMetaItemsin classCollectionResultSet- 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:
getMetaItemin interfaceResultSet- Overrides:
getMetaItemin classCollectionResultSet- 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:
getMetaItemsin interfaceResultSet- Overrides:
getMetaItemsin classCollectionResultSet- 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.
-
allMetaItems
public java.lang.String[][] allMetaItems()
returns all metadata, indexed first by metadata type, then by rank. The order of keys is as in getMetaKeys()- Specified by:
allMetaItemsin interfaceResultSet- Overrides:
allMetaItemsin classCollectionResultSet
-
hasMetaItems
public boolean hasMetaItems(java.lang.String name)
does the metaindex have a particular type of metadata?- Specified by:
hasMetaItemsin interfaceResultSet- Overrides:
hasMetaItemsin classCollectionResultSet- 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:
getMetaKeysin interfaceResultSet- Overrides:
getMetaKeysin classCollectionResultSet- Returns:
- the list of key names
-
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:
getResultSetin interfaceResultSet- Overrides:
getResultSetin classCollectionResultSet- 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:
getResultSetin interfaceResultSet- Overrides:
getResultSetin classCollectionResultSet- 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.
-
sort
public void sort()
Description copied from interface:ResultSetSorts all documents in this resultset by descending score- Specified by:
sortin interfaceResultSet- Overrides:
sortin classCollectionResultSet
-
sort
public void sort(int topDocs)
Description copied from interface:ResultSetSorts the top topDocs document in this resultset be first. The order of the remaining documents is undefined.- Specified by:
sortin interfaceResultSet- Overrides:
sortin classCollectionResultSet- Parameters:
topDocs- number of documents to top-rank
-
-