LCOV - code coverage report
Current view: top level - matcher - extraweightpostlist.h (source / functions) Hit Total Coverage
Test: Test Coverage for xapian-core r Lines: 25 41 61.0 %
Date: 2011-08-21 Functions: 11 16 68.8 %
Branches: 4 24 16.7 %

           Branch data     Line data    Source code
       1                 :            : /* extraweightpostlist.h: add on extra weight contribution
       2                 :            :  *
       3                 :            :  * Copyright 1999,2000,2001 BrightStation PLC
       4                 :            :  * Copyright 2001 Ananova Ltd
       5                 :            :  * Copyright 2003,2004,2007,2009 Olly Betts
       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
      20                 :            :  * USA
      21                 :            :  */
      22                 :            : 
      23                 :            : #ifndef OM_HGUARD_EXTRAWEIGHTPOSTLIST_H
      24                 :            : #define OM_HGUARD_EXTRAWEIGHTPOSTLIST_H
      25                 :            : 
      26                 :            : #include "multimatch.h"
      27                 :            : 
      28                 :            : namespace Xapian {
      29                 :            :     class Weight;
      30                 :            : }
      31                 :            : 
      32                 :            : /// A postlist which adds on an extra weight contribution
      33                 :            : class ExtraWeightPostList : public PostList {
      34                 :            :     private:
      35                 :            :         PostList * pl;
      36                 :            :         Xapian::Weight * wt;
      37                 :            :         MultiMatch * matcher;
      38                 :            :         Xapian::weight max_weight;
      39                 :            : 
      40                 :            :     public:
      41                 :         16 :         Xapian::doccount get_termfreq_max() const {
      42                 :         16 :             return pl->get_termfreq_max();
      43                 :            :         }
      44                 :         16 :         Xapian::doccount get_termfreq_min() const {
      45                 :         16 :             return pl->get_termfreq_min();
      46                 :            :         }
      47                 :         16 :         Xapian::doccount get_termfreq_est() const {
      48                 :         16 :             return pl->get_termfreq_est();
      49                 :            :         }
      50                 :            : 
      51                 :         26 :         Xapian::docid  get_docid() const { return pl->get_docid(); }
      52                 :            : 
      53                 :         26 :         Xapian::weight get_weight() const {
      54                 :         26 :             return pl->get_weight() + wt->get_sumextra(pl->get_doclength());
      55                 :            :         }
      56                 :            : 
      57                 :          0 :         Xapian::weight get_maxweight() const {
      58                 :          0 :             return pl->get_maxweight() + max_weight;
      59                 :            :         }
      60                 :            : 
      61                 :         16 :         Xapian::weight recalc_maxweight() {
      62                 :         16 :             return pl->recalc_maxweight() + max_weight;
      63                 :            :         }
      64                 :            : 
      65                 :         42 :         PostList *next(Xapian::weight w_min) {
      66                 :         42 :             PostList *p = pl->next(w_min - max_weight);
      67         [ -  + ]:         42 :             if (p) {
      68         [ #  # ]:          0 :                 delete pl;
      69                 :          0 :                 pl = p;
      70         [ #  # ]:          0 :                 if (matcher) matcher->recalc_maxweight();
      71                 :            :             }
      72                 :         42 :             return NULL;
      73                 :            :         }
      74                 :            : 
      75                 :          0 :         PostList *skip_to(Xapian::docid did, Xapian::weight w_min) {
      76                 :          0 :             PostList *p = pl->skip_to(did, w_min - max_weight);
      77         [ #  # ]:          0 :             if (p) {
      78         [ #  # ]:          0 :                 delete pl;
      79                 :          0 :                 pl = p;
      80         [ #  # ]:          0 :                 if (matcher) matcher->recalc_maxweight();
      81                 :            :             }
      82                 :          0 :             return NULL;
      83                 :            :         }
      84                 :            : 
      85                 :         42 :         bool at_end() const { return pl->at_end(); }
      86                 :            : 
      87                 :          0 :         std::string get_description() const {
      88                 :          0 :             return "( ExtraWeight " + pl->get_description() + " )";
      89                 :            :         }
      90                 :            : 
      91                 :            :         /** Return the document length of the document the current term
      92                 :            :          *  comes from.
      93                 :            :          */
      94                 :          0 :         virtual Xapian::termcount get_doclength() const {
      95                 :          0 :             return pl->get_doclength();
      96                 :            :         }
      97                 :            : 
      98                 :         16 :         ExtraWeightPostList(PostList * pl_, Xapian::Weight *wt_,
      99                 :            :                             MultiMatch *matcher_)
     100                 :            :             : pl(pl_), wt(wt_), matcher(matcher_),
     101                 :         16 :               max_weight(wt->get_maxextra())
     102                 :         16 :         { }
     103                 :            : 
     104                 :         16 :         ~ExtraWeightPostList() {
     105 [ +  - ][ #  # ]:         16 :             delete pl;
     106 [ +  - ][ #  # ]:         16 :             delete wt;
     107 [ +  - ][ #  # ]:         16 :         }
     108                 :            : 
     109                 :         13 :         Xapian::termcount count_matching_subqs() const {
     110                 :         13 :             return pl->count_matching_subqs();
     111                 :            :         }
     112                 :            : };
     113                 :            : 
     114                 :            : #endif /* OM_HGUARD_EXTRAWEIGHTPOSTLIST_H */

Generated by: LCOV version 1.8