LCOV - code coverage report
Current view: top level - api - leafpostlist.h (source / functions) Hit Total Coverage
Test: Test Coverage for xapian-core 954b5873a738 Lines: 6 13 46.2 %
Date: 2019-06-30 05:20:33 Functions: 3 4 75.0 %
Branches: 1 12 8.3 %

           Branch data     Line data    Source code
       1                 :            : /** @file leafpostlist.h
       2                 :            :  * @brief Abstract base class for leaf postlists.
       3                 :            :  */
       4                 :            : /* Copyright (C) 2007,2009,2011,2013,2015,2016,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_LEAFPOSTLIST_H
      23                 :            : #define XAPIAN_INCLUDED_LEAFPOSTLIST_H
      24                 :            : 
      25                 :            : #include "postlist.h"
      26                 :            : 
      27                 :            : #include <string>
      28                 :            : 
      29                 :            : namespace Xapian {
      30                 :            :     class Weight;
      31                 :            : }
      32                 :            : 
      33                 :            : /** Abstract base class for leaf postlists.
      34                 :            :  *
      35                 :            :  *  This class provides the following features in addition to the PostList
      36                 :            :  *  class:
      37                 :            :  */
      38                 :            : class LeafPostList : public PostList {
      39                 :            :     /// Don't allow assignment.
      40                 :            :     void operator=(const LeafPostList &) = delete;
      41                 :            : 
      42                 :            :     /// Don't allow copying.
      43                 :            :     LeafPostList(const LeafPostList &) = delete;
      44                 :            : 
      45                 :            :   protected:
      46                 :            :     const Xapian::Weight * weight;
      47                 :            : 
      48                 :            :     /// The term name for this postlist (empty for an alldocs postlist).
      49                 :            :     std::string term;
      50                 :            : 
      51                 :            :     /// Only constructable as a base class for derived classes.
      52                 :     321841 :     explicit LeafPostList(const std::string & term_)
      53         [ +  - ]:     321841 :         : weight(0), term(term_) { }
      54                 :            : 
      55                 :            :   public:
      56                 :            :     ~LeafPostList();
      57                 :            : 
      58                 :            :     /** Set the weighting scheme to use during matching.
      59                 :            :      *
      60                 :            :      *  If this isn't called, get_weight() and recalc_maxweight() will both
      61                 :            :      *  return 0.
      62                 :            :      *
      63                 :            :      *  You should not call this more than once on a particular object.
      64                 :            :      *
      65                 :            :      *  @param weight_  The weighting object to use.  Must not be NULL.
      66                 :            :      */
      67                 :     311478 :     void set_termweight(const Xapian::Weight * weight_) {
      68                 :            :         // This method shouldn't be called more than once on the same object.
      69                 :            :         Assert(!weight);
      70                 :     311478 :         weight = weight_;
      71                 :     311478 :     }
      72                 :            : 
      73                 :          0 :     double resolve_lazy_termweight(Xapian::Weight * weight_,
      74                 :            :                                    Xapian::Weight::Internal * stats,
      75                 :            :                                    Xapian::termcount qlen,
      76                 :            :                                    Xapian::termcount wqf,
      77                 :            :                                    double factor)
      78                 :            :     {
      79         [ #  # ]:          0 :         weight_->init_(*stats, qlen, term, wqf, factor);
      80                 :            :         // There should be an existing LazyWeight set already.
      81                 :            :         Assert(weight);
      82                 :          0 :         const Xapian::Weight * const_weight_ = weight_;
      83                 :          0 :         std::swap(weight, const_weight_);
      84         [ #  # ]:          0 :         delete const_weight_;
      85 [ #  # ][ #  # ]:          0 :         stats->termfreqs[term].max_part += weight->get_maxpart();
      86         [ #  # ]:          0 :         return stats->termfreqs[term].max_part;
      87                 :            :     }
      88                 :            : 
      89                 :            :     /** Return the exact term frequency.
      90                 :            :      *
      91                 :            :      *  Leaf postlists have an exact termfreq, which get_termfreq_min(),
      92                 :            :      *  get_termfreq_max(), and get_termfreq_est() all report.
      93                 :            :      */
      94                 :            :     virtual Xapian::doccount get_termfreq() const = 0;
      95                 :            : 
      96                 :            :     Xapian::doccount get_termfreq_min() const;
      97                 :            :     Xapian::doccount get_termfreq_max() const;
      98                 :            :     Xapian::doccount get_termfreq_est() const;
      99                 :            : 
     100                 :            :     double get_weight(Xapian::termcount doclen,
     101                 :            :                       Xapian::termcount unique_terms) const;
     102                 :            : 
     103                 :            :     double recalc_maxweight();
     104                 :            : 
     105                 :            :     TermFreqs get_termfreq_est_using_stats(
     106                 :            :         const Xapian::Weight::Internal & stats) const;
     107                 :            : 
     108                 :            :     Xapian::termcount count_matching_subqs() const;
     109                 :            : 
     110                 :            :     void gather_position_lists(OrPositionList* orposlist);
     111                 :            : 
     112                 :            :     /** Open another postlist from the same database.
     113                 :            :      *
     114                 :            :      *  @param term_    The term to open a postlist for (must not be an empty
     115                 :            :      *                  string).  If term_ is near to this postlist's term,
     116                 :            :      *                  then this can be a lot more efficient (and if it isn't
     117                 :            :      *                  very near, there's not much of a penalty).  Using this
     118                 :            :      *                  method can make a wildcard expansion much more memory
     119                 :            :      *                  efficient.
     120                 :            :      *
     121                 :            :      *  @param need_read_pos
     122                 :            :      *                  Does the postlist need to support read_position_list()?
     123                 :            :      *                  Note that open_position_list() may still be called even
     124                 :            :      *                  if need_read_pos is false.
     125                 :            :      *
     126                 :            :      *  @return         The new postlist object, or NULL if not supported
     127                 :            :      *                  (in which case the caller should probably open the
     128                 :            :      *                  postlist via the database instead).
     129                 :            :      */
     130                 :            :     virtual LeafPostList * open_nearby_postlist(const std::string & term_,
     131                 :            :                                                 bool need_read_pos) const;
     132                 :            : 
     133                 :            :     /** Set the term name.
     134                 :            :      *
     135                 :            :      *  This is useful when we optimise a term matching all documents to an
     136                 :            :      *  all documents postlist under OP_SYNONYM, as the term name is used by
     137                 :            :      *  LeafPostList::get_termfreq_est_using_stats() to locate the appropriate
     138                 :            :      *  TermFreqs object.
     139                 :            :      */
     140                 :        272 :     void set_term(const std::string & term_) { term = term_; }
     141                 :            : };
     142                 :            : 
     143                 :            : #endif // XAPIAN_INCLUDED_LEAFPOSTLIST_H

Generated by: LCOV version 1.11