Class 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
    • 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
      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[][] allMetaItems()
      returns all metadata, indexed first by metadata type, then by rank.
      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)
      does the metaindex have a particular type of metadata?
      void initialise()
      Initialises the arrays prior of retrieval.
      protected QueryResultSet makeNewResultSet​(int length)  
      void sort()
      Sorts all documents in this resultset by descending score
      void sort​(int topDocs)
      Sorts the top topDocs document in this resultset be first.
      • 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.
      • 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:
        allMetaItems in interface ResultSet
        Overrides:
        allMetaItems in class CollectionResultSet
      • hasMetaItems

        public boolean hasMetaItems​(java.lang.String name)
        does the metaindex have a particular type of metadata?
        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
        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:
        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.
      • sort

        public void sort​(int topDocs)
        Description copied from interface: ResultSet
        Sorts the top topDocs document in this resultset be first. The order of the remaining documents is undefined.
        Specified by:
        sort in interface ResultSet
        Overrides:
        sort in class CollectionResultSet
        Parameters:
        topDocs - number of documents to top-rank