LCOV - code coverage report
Current view: top level - api - postlist.h (source / functions) Hit Total Coverage
Test: Test Coverage for xapian-core fcfb185a9dd5 Lines: 3 3 100.0 %
Date: 2019-04-18 16:33:14 Functions: 3 3 100.0 %
Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /** @file postlist.h
       2                 :            :  * @brief Abstract base class for postlists.
       3                 :            :  */
       4                 :            : /* Copyright (C) 2007,2008,2009,2011,2015,2017 Olly Betts
       5                 :            :  * Copyright (C) 2009 Lemur Consulting Ltd
       6                 :            :  *
       7                 :            :  * This program is free software; you can redistribute it and/or
       8                 :            :  * modify it under the terms of the GNU General Public License as
       9                 :            :  * published by the Free Software Foundation; either version 2 of the
      10                 :            :  * License, or (at your option) any later version.
      11                 :            :  *
      12                 :            :  * This program is distributed in the hope that it will be useful,
      13                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      14                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15                 :            :  * GNU General Public License for more details.
      16                 :            :  *
      17                 :            :  * You should have received a copy of the GNU General Public License
      18                 :            :  * along with this program; if not, write to the Free Software
      19                 :            :  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
      20                 :            :  */
      21                 :            : 
      22                 :            : #ifndef XAPIAN_INCLUDED_POSTLIST_H
      23                 :            : #define XAPIAN_INCLUDED_POSTLIST_H
      24                 :            : 
      25                 :            : #include <string>
      26                 :            : 
      27                 :            : #include "xapian/intrusive_ptr.h"
      28                 :            : #include <xapian/types.h>
      29                 :            : #include <xapian/postingiterator.h>
      30                 :            : 
      31                 :            : #include "backends/positionlist.h"
      32                 :            : #include "weight/weightinternal.h"
      33                 :            : 
      34                 :            : class OrPositionList;
      35                 :            : 
      36                 :            : namespace Xapian {
      37                 :            : namespace Internal {
      38                 :            : 
      39                 :            : /// Abstract base class for postlists.
      40                 :            : class PostList {
      41                 :            :     /// Don't allow assignment.
      42                 :            :     void operator=(const PostList &) = delete;
      43                 :            : 
      44                 :            :     /// Don't allow copying.
      45                 :            :     PostList(const PostList &) = delete;
      46                 :            : 
      47                 :            :   protected:
      48                 :            :     /// Only constructable as a base class for derived classes.
      49                 :     482187 :     PostList() { }
      50                 :            : 
      51                 :            :   public:
      52                 :            :     /** We have virtual methods and want to be able to delete derived classes
      53                 :            :      *  using a pointer to the base class, so we need a virtual destructor.
      54                 :            :      */
      55                 :            :     virtual ~PostList();
      56                 :            : 
      57                 :            :     /// Get a lower bound on the number of documents indexed by this term.
      58                 :            :     virtual Xapian::doccount get_termfreq_min() const = 0;
      59                 :            : 
      60                 :            :     /// Get an upper bound on the number of documents indexed by this term.
      61                 :            :     virtual Xapian::doccount get_termfreq_max() const = 0;
      62                 :            : 
      63                 :            :     /** Get an estimate of the number of documents indexed by this term.
      64                 :            :      *
      65                 :            :      *  It should always be true that:
      66                 :            :      *  get_termfreq_min() <= get_termfreq_est() <= get_termfreq_max()
      67                 :            :      */
      68                 :            :     virtual Xapian::doccount get_termfreq_est() const = 0;
      69                 :            : 
      70                 :            :     /** Get an estimate for the termfreq and reltermfreq, given the stats.
      71                 :            :      *
      72                 :            :      *  The frequencies may be for a combination of databases, or for just the
      73                 :            :      *  relevant documents, so the results need not lie in the bounds given by
      74                 :            :      *  get_termfreq_min() and get_termfreq_max().
      75                 :            :      */
      76                 :            :     virtual TermFreqs get_termfreq_est_using_stats(
      77                 :            :         const Xapian::Weight::Internal & stats) const;
      78                 :            : 
      79                 :            :     /// Return the current docid.
      80                 :            :     virtual Xapian::docid get_docid() const = 0;
      81                 :            : 
      82                 :            :     /** Return the wdf for the document at the current position.
      83                 :            :      *
      84                 :            :      *  The default implementation throws Xapian::UnimplementedError.
      85                 :            :      */
      86                 :            :     virtual Xapian::termcount get_wdf() const;
      87                 :            : 
      88                 :            :     /// Return the weight contribution for the current position.
      89                 :            :     virtual double get_weight(Xapian::termcount doclen,
      90                 :            :                               Xapian::termcount unique_terms) const = 0;
      91                 :            : 
      92                 :            :     /// Return true if the current position is past the last entry in this list.
      93                 :            :     virtual bool at_end() const = 0;
      94                 :            : 
      95                 :            :     /** Recalculate the upper bound on what get_weight() can return.
      96                 :            :      *
      97                 :            :      *  The maximum weight that get_weight() can return can decrease as the
      98                 :            :      *  match progresses (typically when the PostList tree prunes) - calling
      99                 :            :      *  this method calculates a current upper bound.
     100                 :            :      *
     101                 :            :      *  Note that this method may be called after the postlist has reached the
     102                 :            :      *  end.  In this situation, the method should return 0.
     103                 :            :      */
     104                 :            :     virtual double recalc_maxweight() = 0;
     105                 :            : 
     106                 :            :     /** Read the position list for the term in the current document and
     107                 :            :      *  return a pointer to it (owned by the PostList).
     108                 :            :      *
     109                 :            :      *  The default implementation throws Xapian::UnimplementedError.
     110                 :            :      */
     111                 :            :     virtual PositionList * read_position_list();
     112                 :            : 
     113                 :            :     /** Read the position list for the term in the current document and
     114                 :            :      *  return a pointer to it (not owned by the PostList).
     115                 :            :      *
     116                 :            :      *  The default implementation throws Xapian::UnimplementedError.
     117                 :            :      */
     118                 :            :     virtual PositionList * open_position_list() const;
     119                 :            : 
     120                 :            :     /** Advance the current position to the next document in the postlist.
     121                 :            :      *
     122                 :            :      *  The list starts before the first entry in the list, so next(),
     123                 :            :      *  skip_to() or check() must be called before any methods which need the
     124                 :            :      *  context of the current position.
     125                 :            :      *
     126                 :            :      *  @param w_min    The minimum weight contribution that is needed (this is
     127                 :            :      *                  just a hint which PostList subclasses may ignore).
     128                 :            :      *
     129                 :            :      *  @return If a non-NULL pointer is returned, then the caller should
     130                 :            :      *          substitute the returned pointer for its pointer to us, and then
     131                 :            :      *          delete us.  This "pruning" can only happen for a non-leaf
     132                 :            :      *          subclass of this class.
     133                 :            :      */
     134                 :            :     virtual PostList* next(double w_min) = 0;
     135                 :            : 
     136                 :            :     /** Skip forward to the specified docid.
     137                 :            :      *
     138                 :            :      *  If the specified docid isn't in the list, position ourselves on the
     139                 :            :      *  first document after it (or at_end() if no greater docids are present).
     140                 :            :      *
     141                 :            :      *  @param w_min    The minimum weight contribution that is needed (this is
     142                 :            :      *                  just a hint which PostList subclasses may ignore).
     143                 :            :      *
     144                 :            :      *  @return If a non-NULL pointer is returned, then the caller should
     145                 :            :      *          substitute the returned pointer for its pointer to us, and then
     146                 :            :      *          delete us.  This "pruning" can only happen for a non-leaf
     147                 :            :      *          subclass of this class.
     148                 :            :      */
     149                 :            :     virtual PostList* skip_to(Xapian::docid did, double w_min) = 0;
     150                 :            : 
     151                 :            :     /** Check if the specified docid occurs in this postlist.
     152                 :            :      *
     153                 :            :      *  The caller is required to ensure that the specified @a docid actually
     154                 :            :      *  exists in the database.
     155                 :            :      *
     156                 :            :      *  This method acts like skip_to() if that can be done at little extra
     157                 :            :      *  cost, in which case it then sets @a valid to true.
     158                 :            :      *
     159                 :            :      *  Otherwise it simply checks if a particular docid is present.  If it
     160                 :            :      *  is, @a valid is set to true.  If it isn't, it sets @a valid to
     161                 :            :      *  false, and leaves the position unspecified (and hence the result of
     162                 :            :      *  calling methods which depend on the current position, such as
     163                 :            :      *  get_docid() and at_end(), are also unspecified).  In this state, next()
     164                 :            :      *  will advance to the first matching position after @a docid, and
     165                 :            :      *  skip_to() will act as it would if the position was the first matching
     166                 :            :      *  position after @a docid.  If @a valid is set to false, then NULL must
     167                 :            :      *  be returned (pruning in this situation doesn't make sense).
     168                 :            :      *
     169                 :            :      *  The default implementation calls skip_to().
     170                 :            :      */
     171                 :            :     virtual PostList* check(Xapian::docid did, double w_min, bool &valid);
     172                 :            : 
     173                 :            :     /** Advance the current position to the next document in the postlist.
     174                 :            :      *
     175                 :            :      *  Any weight contribution is acceptable.
     176                 :            :      */
     177                 :     158547 :     PostList* next() { return next(0.0); }
     178                 :            : 
     179                 :            :     /** Skip forward to the specified docid.
     180                 :            :      *
     181                 :            :      *  Any weight contribution is acceptable.
     182                 :            :      */
     183                 :        108 :     PostList* skip_to(Xapian::docid did) { return skip_to(did, 0.0); }
     184                 :            : 
     185                 :            :     /// Count the number of leaf subqueries which match at the current position.
     186                 :            :     virtual Xapian::termcount count_matching_subqs() const;
     187                 :            : 
     188                 :            :     /// Gather PositionList* objects for a subtree.
     189                 :            :     virtual void gather_position_lists(OrPositionList* orposlist);
     190                 :            : 
     191                 :            :     /// Return a string description of this object.
     192                 :            :     virtual std::string get_description() const = 0;
     193                 :            : };
     194                 :            : 
     195                 :            : }
     196                 :            : }
     197                 :            : 
     198                 :            : using Xapian::Internal::PostList;
     199                 :            : 
     200                 :            : #endif // XAPIAN_INCLUDED_POSTLIST_H

Generated by: LCOV version 1.11